Fix math error affecting the linear segment -> polynomial logic (#3562)
Fix typo in the linear segment -> polynomial code
This commit is contained in:
parent
2fa958aa79
commit
403ab7ba31
|
|
@ -203,7 +203,7 @@ impl<const N: usize> Mul for &Polynomial<N> {
|
||||||
pub fn pathseg_to_parametric_polynomial(segment: PathSeg) -> (Polynomial<4>, Polynomial<4>) {
|
pub fn pathseg_to_parametric_polynomial(segment: PathSeg) -> (Polynomial<4>, Polynomial<4>) {
|
||||||
match segment {
|
match segment {
|
||||||
PathSeg::Line(line) => {
|
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.]))
|
(Polynomial::new([line.p0.x, term1.x, 0., 0.]), Polynomial::new([line.p0.y, term1.y, 0., 0.]))
|
||||||
}
|
}
|
||||||
PathSeg::Quad(quad_bez) => {
|
PathSeg::Quad(quad_bez) => {
|
||||||
|
|
|
||||||
|
|
@ -112,3 +112,17 @@ impl<PointId: Identifier> Subpath<PointId> {
|
||||||
.map(|(centroid_part, length)| (DVec2::new(centroid_part.x, centroid_part.y), length))
|
.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.))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue