Fix math error affecting the linear segment -> polynomial logic (#3562)

Fix typo in the linear segment -> polynomial code
This commit is contained in:
James Lindsay 2026-01-02 10:00:02 +00:00 committed by GitHub
parent 2fa958aa79
commit 403ab7ba31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -203,7 +203,7 @@ impl<const N: usize> Mul for &Polynomial<N> {
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) => {

View File

@ -112,3 +112,17 @@ impl<PointId: Identifier> Subpath<PointId> {
.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::<PointId>::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.))
}
}