From 6d499efd3c3a182a50216c3134066fd15f9ca4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Wed, 10 Dec 2025 23:53:10 +0100 Subject: [PATCH] Add Point3::from_line() --- src/common/geometry.rs | 5 +++++ src/solvers/playground.rs | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/common/geometry.rs b/src/common/geometry.rs index 46a3c92..386d772 100644 --- a/src/common/geometry.rs +++ b/src/common/geometry.rs @@ -16,6 +16,11 @@ impl Point2 { pub struct Point3(pub u64, pub u64, pub u64); impl Point3 { + pub fn from_line(line: &str, separator: char) -> Self { + let p: Vec = line.split(separator).map(|s| s.parse().unwrap()).collect(); + Self(p[0], p[1], p[2]) + } + pub fn distance_sqr(&self, other: &Self) -> u64 { self.0.abs_diff(other.0).pow(2) + self.1.abs_diff(other.1).pow(2) diff --git a/src/solvers/playground.rs b/src/solvers/playground.rs index e2cc7fd..82bc775 100644 --- a/src/solvers/playground.rs +++ b/src/solvers/playground.rs @@ -21,8 +21,7 @@ impl Playground { fn junction_boxes(reader: R) -> Vec { let mut junction_boxes = Vec::new(); for line in reader.lines().map_while(Result::ok) { - let j: Vec = line.split(Self::POINT_SPLIT_CHAR).map(|s| s.parse().unwrap()).collect(); - junction_boxes.push(Point3(j[0], j[1], j[2])); + junction_boxes.push(Point3::from_line(&line, Self::POINT_SPLIT_CHAR)); } junction_boxes }