Skip to content

Commit 403ab7b

Browse files
authored
Fix math error affecting the linear segment -> polynomial logic (#3562)
Fix typo in the linear segment -> polynomial code
1 parent 2fa958a commit 403ab7b

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

node-graph/libraries/core-types/src/math/polynomial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<const N: usize> Mul for &Polynomial<N> {
203203
pub fn pathseg_to_parametric_polynomial(segment: PathSeg) -> (Polynomial<4>, Polynomial<4>) {
204204
match segment {
205205
PathSeg::Line(line) => {
206-
let term1 = line.p0 - line.p1;
206+
let term1 = line.p1 - line.p0;
207207
(Polynomial::new([line.p0.x, term1.x, 0., 0.]), Polynomial::new([line.p0.y, term1.y, 0., 0.]))
208208
}
209209
PathSeg::Quad(quad_bez) => {

node-graph/libraries/vector-types/src/subpath/lookup.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,17 @@ impl<PointId: Identifier> Subpath<PointId> {
112112
.map(|(centroid_part, length)| (DVec2::new(centroid_part.x, centroid_part.y), length))
113113
}
114114
}
115+
116+
#[cfg(test)]
117+
mod test_centroid {
118+
use crate::vector::PointId;
119+
120+
use super::*;
121+
#[test]
122+
fn centroid_rect() {
123+
let rect = Subpath::<PointId>::new_rect(DVec2::new(100., 100.), DVec2::new(300., 200.));
124+
let (centre, area) = rect.area_centroid_and_area(Some(1e-3), Some(1e-3)).unwrap();
125+
assert_eq!(area, 200. * 100.);
126+
assert_eq!(centre, DVec2::new(200., 150.))
127+
}
128+
}

0 commit comments

Comments
 (0)