use std::collections::HashMap;
use std::collections::HashSet;
pub fn find_mtps(
dataset: &Vec<(u32, u32)>,
restrict_dpitch_zero: bool
) -> HashMap<(i32, i32), Vec<(u32, u32)>> {
let points = dataset;
let n = points.len();
let mut groups: HashMap<(i32, i32), HashSet<(u32, u32)>> = HashMap::new();
for i in 0..n {
let (ti, pi) = points[i];
for j in 0..i {
let (tj, pj) = points[j];
let dx = ti as i32 - tj as i32;
let dy = pi as i32 - pj as i32;
if restrict_dpitch_zero && dy != 0 {
continue;
}
groups
.entry((dx, dy))
.or_insert_with(HashSet::new)
.insert((tj, pj));
groups
.entry((-dx, -dy))
.or_insert_with(HashSet::new)
.insert((ti, pi));
}
}
let mut result = HashMap::new();
for (vec, start_set) in groups {
if vec == (0, 0) {
continue;
}
if start_set.len() < 2 {
continue;
}
let mut start_points: Vec<_> = start_set.into_iter().collect();
start_points.sort(); result.insert(vec, start_points);
}
result
}