Avoid instantiating translated sets

This commit is contained in:
2022-01-09 15:44:24 +01:00
parent 33111615be
commit dba146b299

View File

@@ -199,19 +199,18 @@ fn try_overlap(matched: &Scanner, candidate: &Scanner) -> Option<(Point3, Scanne
let correct: HashSet<_> = matched.iter().map(|&base| base - matched_pivot).collect(); let correct: HashSet<_> = matched.iter().map(|&base| base - matched_pivot).collect();
let mut relative = HashSet::new(); for rot in Rotations::new(candidate) {
for rot in Rotations::new(&candidate.visible) {
for &start in &rot { for &start in &rot {
relative.clear(); let translated_iter = rot.iter().map(|&other| other - start);
relative.extend(rot.iter().map(|&other| other - start)); if translated_iter
.clone()
if correct.intersection(&relative).count() >= 12 { .filter(|p| correct.contains(p))
.count()
>= 12
{
// Found a solution, build the correct output // Found a solution, build the correct output
let translated = relative let translated = translated_iter.map(|point| point + matched_pivot).collect();
.drain()
.map(|point| point + matched_pivot)
.collect();
return Some((start - matched_pivot, Scanner::new(translated))); return Some((start - matched_pivot, Scanner::new(translated)));
} }
@@ -248,6 +247,8 @@ fn parts_common(input: &mut dyn Read) -> (HashSet<Point3>, Vec<Point3>) {
} }
} }
assert!(scanners.is_empty());
(points, scanners_found) (points, scanners_found)
} }