From bf6dadf04ca943258f9fde6df0f5a7172f4ba018 Mon Sep 17 00:00:00 2001 From: hypercube <0hypercube@gmail.com> Date: Thu, 1 Jan 2026 18:04:27 +0000 Subject: [PATCH] Fix typo in the linear segment -> polynomial code --- .../libraries/core-types/src/math/polynomial.rs | 2 +- .../libraries/vector-types/src/subpath/lookup.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/node-graph/libraries/core-types/src/math/polynomial.rs b/node-graph/libraries/core-types/src/math/polynomial.rs index 8af2f0907e..392fee51e4 100644 --- a/node-graph/libraries/core-types/src/math/polynomial.rs +++ b/node-graph/libraries/core-types/src/math/polynomial.rs @@ -203,7 +203,7 @@ impl Mul for &Polynomial { pub fn pathseg_to_parametric_polynomial(segment: PathSeg) -> (Polynomial<4>, Polynomial<4>) { match segment { PathSeg::Line(line) => { - let term1 = line.p0 - line.p1; + let term1 = line.p1 - line.p0; (Polynomial::new([line.p0.x, term1.x, 0., 0.]), Polynomial::new([line.p0.y, term1.y, 0., 0.])) } PathSeg::Quad(quad_bez) => { diff --git a/node-graph/libraries/vector-types/src/subpath/lookup.rs b/node-graph/libraries/vector-types/src/subpath/lookup.rs index 7f37e88a6c..1c66ceaafb 100644 --- a/node-graph/libraries/vector-types/src/subpath/lookup.rs +++ b/node-graph/libraries/vector-types/src/subpath/lookup.rs @@ -112,3 +112,17 @@ impl Subpath { .map(|(centroid_part, length)| (DVec2::new(centroid_part.x, centroid_part.y), length)) } } + +#[cfg(test)] +mod test_centroid { + use crate::vector::PointId; + + use super::*; + #[test] + fn centroid_rect() { + let rect = Subpath::::new_rect(DVec2::new(100., 100.), DVec2::new(300., 200.)); + let (centre, area) = rect.area_centroid_and_area(Some(1e-3), Some(1e-3)).unwrap(); + assert_eq!(area, 200. * 100.); + assert_eq!(centre, DVec2::new(200., 150.)) + } +}