Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node-graph/libraries/core-types/src/math/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
14 changes: 14 additions & 0 deletions node-graph/libraries/vector-types/src/subpath/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.))
}
}
Loading