You are given a vector of points in 2D space, represented as Vec<(i32, i32)>.
Write a function that returns the number of distinct squares that can be formed using these points as vertices.
A square is defined as a quadrilateral with four equal sides and four right angles.
fn count_squares(points: &Vec<(i32, i32)>) -> usizelet points = vec![(0, 0), (1, 0), (0, 1), (1, 1)];
assert_eq!(count_squares(&points), 1);Explanation: These four points form a unit square.
let points = vec![
(0, 0), (1, 0), (2, 0),
(0, 1), (1, 1), (2, 1),
(0, 2), (1, 2), (2, 2)
];
assert_eq!(count_squares(&points), 6);Explanation:
- Four 1×1 squares
- One 2×2 square
- One √2×√2 rotated square (diamond)
let points = vec![(0, 0), (1, 1), (2, 0)];
assert_eq!(count_squares(&points), 0);Explanation: No four points form a square.