Skip to content

Commit

Permalink
Merge pull request #33 from mattatz/develop
Browse files Browse the repository at this point in the history
0.1.36
  • Loading branch information
mattatz authored Nov 1, 2024
2 parents 8cf8b85 + 0f43e0f commit 7fdcbc1
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 107 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "curvo"
version = "0.1.35"
version = "0.1.36"
authors = ["Masatatsu Nakamura <masatatsu.nakamura@gmail.com"]
edition = "2021"
keywords = ["nurbs", "modeling", "graphics", "3d"]
Expand All @@ -12,8 +12,8 @@ license = "MIT"
readme = "README.md"

[dependencies]
anyhow = "1.0.91"
nalgebra = { version = "0.33.1", features = [
anyhow = "1.0.92"
nalgebra = { version = "0.33.2", features = [
"serde-serialize"
] }
num-traits = "0.2.19"
Expand All @@ -34,7 +34,7 @@ bevy_points = { version = "0.6.0", optional = true }
argmin = "0.10.0"
itertools = "0.13.0"
log = { version = "0.4.22", optional = true }
serde = { version = "1.0.213", optional = true }
serde = { version = "1.0.214", optional = true }

[target.wasm32-unknown-unknown.dependencies]
argmin = { version = "0.10.0", features = ["wasm-bindgen"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/polyline_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn setup(
})
.insert(Name::new("points"));

let polyline_curve = NurbsCurve2D::polyline(&points);
let polyline_curve = NurbsCurve2D::polyline(&points, true);

let samples = polyline_curve.tessellate(Some(1e-8));
let line_vertices = samples
Expand Down
51 changes: 30 additions & 21 deletions src/boolean/degeneracies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,30 @@ mod tests {
let circle =
NurbsCurve2D::<f64>::try_circle(&Point2::origin(), &Vector2::x(), &Vector2::y(), 1.)
.unwrap();
let rectangle = NurbsCurve2D::<f64>::polyline(&[
Point2::new(0., 2.),
Point2::new(1., 2.),
Point2::new(1., -2.),
Point2::new(0., -2.),
Point2::new(0., 2.),
]);
let rectangle = NurbsCurve2D::<f64>::polyline(
&[
Point2::new(0., 2.),
Point2::new(1., 2.),
Point2::new(1., -2.),
Point2::new(0., -2.),
Point2::new(0., 2.),
],
true,
);
let intersections =
find_intersections_without_degeneracies(&circle, &rectangle, Some(OPTIONS)).unwrap();
assert_eq!(intersections.len(), 2);

let rectangle_2 = NurbsCurve2D::<f64>::polyline(&[
Point2::new(-0.5, 2.),
Point2::new(0.5, 2.),
Point2::new(0.5, -1.),
Point2::new(-0.5, -1.),
Point2::new(-0.5, 2.),
]);
let rectangle_2 = NurbsCurve2D::<f64>::polyline(
&[
Point2::new(-0.5, 2.),
Point2::new(0.5, 2.),
Point2::new(0.5, -1.),
Point2::new(-0.5, -1.),
Point2::new(-0.5, 2.),
],
true,
);
let intersections_2 =
find_intersections_without_degeneracies(&circle, &rectangle_2, Some(OPTIONS)).unwrap();
assert_eq!(intersections_2.len(), 4);
Expand Down Expand Up @@ -154,13 +160,16 @@ mod tests {
let subject =
NurbsCurve2D::<f64>::try_circle(&Point2::origin(), &Vector2::x(), &Vector2::y(), 1.)
.unwrap();
let clip = NurbsCurve2D::<f64>::polyline(&[
Point2::new(-dx, -dy),
Point2::new(dx, -dy),
Point2::new(dx, dy),
Point2::new(-dx, dy),
Point2::new(-dx, -dy),
]);
let clip = NurbsCurve2D::<f64>::polyline(
&[
Point2::new(-dx, -dy),
Point2::new(dx, -dy),
Point2::new(dx, dy),
Point2::new(-dx, dy),
Point2::new(-dx, -dy),
],
true,
);
let delta: f64 = 0.8204758902600001;
let trans = Translation2::new(delta.cos(), 0.) * Rotation2::new(delta);
let intersections = find_intersections_without_degeneracies(
Expand Down
51 changes: 30 additions & 21 deletions src/boolean/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ const OPTIONS: CurveIntersectionSolverOptions<f64> = CurveIntersectionSolverOpti
fn rectangle(width: f64, height: f64) -> NurbsCurve2D<f64> {
let dx = width * 0.5;
let dy = height * 0.5;
NurbsCurve2D::polyline(&[
Point2::new(-dx, -dy),
Point2::new(dx, -dy),
Point2::new(dx, dy),
Point2::new(-dx, dy),
Point2::new(-dx, -dy),
])
NurbsCurve2D::polyline(
&[
Point2::new(-dx, -dy),
Point2::new(dx, -dy),
Point2::new(dx, dy),
Point2::new(-dx, dy),
Point2::new(-dx, -dy),
],
true,
)
}

fn compound_circle(radius: f64) -> CompoundCurve<f64, U3> {
Expand All @@ -45,21 +48,27 @@ fn rectangular_annulus(width: f64, height: f64, square_size: f64) -> Region<f64>
let dy = height * 0.5;
let size = (square_size * 0.5).min(dx).min(dy);
Region::new(
NurbsCurve2D::polyline(&[
Point2::new(-dx, -dy),
Point2::new(dx, -dy),
Point2::new(dx, dy),
Point2::new(-dx, dy),
Point2::new(-dx, -dy),
])
NurbsCurve2D::polyline(
&[
Point2::new(-dx, -dy),
Point2::new(dx, -dy),
Point2::new(dx, dy),
Point2::new(-dx, dy),
Point2::new(-dx, -dy),
],
true,
)
.into(),
vec![NurbsCurve2D::polyline(&[
Point2::new(-size, -size),
Point2::new(size, -size),
Point2::new(size, size),
Point2::new(-size, size),
Point2::new(-size, -size),
])
vec![NurbsCurve2D::polyline(
&[
Point2::new(-size, -size),
Point2::new(size, -size),
Point2::new(size, size),
Point2::new(-size, size),
Point2::new(-size, -size),
],
true,
)
.into()],
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/contains/contains_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn x_ray_intersection<T: FloatingPoint + ArgminFloat>(
option: Option<CurveIntersectionSolverOptions<T>>,
) -> anyhow::Result<Vec<Point2<T>>> {
let option = option.unwrap_or_default();
let ray = NurbsCurve::polyline(&[*point, point + Vector2::x() * ray_length]);
let ray = NurbsCurve::polyline(&[*point, point + Vector2::x() * ray_length], true);
let traversed = BoundingBoxTraversal::try_traverse(
curve,
&ray,
Expand Down
17 changes: 10 additions & 7 deletions src/contains/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ fn test_circle_boundary_case() {
fn test_rectangle_boundary_case() {
let dx = 2.;
let dy = 1.;
let rectangle = NurbsCurve2D::<f64>::polyline(&[
Point2::new(0., 0.),
Point2::new(dx, 0.),
Point2::new(dx, dy),
Point2::new(0., dy),
Point2::new(0., 0.),
]);
let rectangle = NurbsCurve2D::<f64>::polyline(
&[
Point2::new(0., 0.),
Point2::new(dx, 0.),
Point2::new(dx, dy),
Point2::new(0., dy),
Point2::new(0., 0.),
],
true,
);
assert!(rectangle
.contains(&Point2::new(0., 0.), Some(OPTIONS))
.unwrap());
Expand Down
24 changes: 19 additions & 5 deletions src/curve/nurbs_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where
/// Point2::new(-1.0, 1.0),
/// Point2::new(1.0, 1.0),
/// ];
/// let polyline_curve = NurbsCurve2D::polyline(&points);
/// let polyline_curve = NurbsCurve2D::polyline(&points, true);
/// let (start, end) = polyline_curve.knots_domain();
/// let start = polyline_curve.point_at(start);
/// let end = polyline_curve.point_at(end);
Expand All @@ -125,7 +125,7 @@ where
/// let goal = points.iter().tuple_windows().map(|(a, b)| (a - b).norm()).sum();
/// assert_eq!(length, goal);
/// ```
pub fn polyline(points: &[OPoint<T, DimNameDiff<D, U1>>]) -> Self
pub fn polyline(points: &[OPoint<T, DimNameDiff<D, U1>>], normalize_knots: bool) -> Self
where
D: DimNameSub<U1>,
<D as DimNameSub<U1>>::Output: DimNameAdd<U1>,
Expand All @@ -142,7 +142,11 @@ where
}
knots.push(acc);

let knots = knots.into_iter().map(|k| k / acc).collect();
let knots = if normalize_knots {
knots.into_iter().map(|k| k / acc).collect()
} else {
knots
};

Self {
degree: 1,
Expand Down Expand Up @@ -266,6 +270,16 @@ where
deriv[1].clone()
}

/// Compute second order derivative at a given parameter.
pub fn second_derivative_at(&self, u: T) -> OVector<T, DimNameDiff<D, U1>>
where
D: DimNameSub<U1>,
DefaultAllocator: Allocator<DimNameDiff<D, U1>>,
{
let deriv = self.rational_derivatives(u, 2);
deriv[2].clone()
}

/// Evaluate the curve at a given parameter to get a point & tangent vector at the same time
#[allow(clippy::type_complexity)]
pub fn point_tangent_at(
Expand Down Expand Up @@ -1291,7 +1305,7 @@ where
/// Point3::new(1., 1., 0.),
/// Point3::new(-1., 1., 0.),
/// Point3::new(-1., -1., 0.),
/// ],
/// ], true,
/// );
/// assert!(polyline.is_closed());
///
Expand All @@ -1301,7 +1315,7 @@ where
/// Point3::new(1., -1., 0.),
/// Point3::new(1., 1., 0.),
/// Point3::new(-1., 1., 0.),
/// ],
/// ], true,
/// );
/// assert!(!unclosed.is_closed());
/// ```
Expand Down
34 changes: 20 additions & 14 deletions src/curve/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ fn problem_case() {
KnotStyle::Centripetal,
)
.unwrap();
let clip = NurbsCurve2D::<f64>::polyline(&[
Point2::new(-1., -1.),
Point2::new(1., -1.),
Point2::new(1., 1.),
Point2::new(-1., 1.),
Point2::new(-1., -1.),
]);
let clip = NurbsCurve2D::<f64>::polyline(
&[
Point2::new(-1., -1.),
Point2::new(1., -1.),
Point2::new(1., 1.),
Point2::new(-1., 1.),
Point2::new(-1., -1.),
],
true,
);
let delta: f64 = 17.58454421724;
let trans = Translation2::new(delta.cos(), 0.) * Rotation2::new(delta);
let clip = clip.transformed(&trans.into());
Expand All @@ -64,13 +67,16 @@ fn problem_case2() {
KnotStyle::Centripetal,
)
.unwrap();
let clip = NurbsCurve2D::<f64>::polyline(&[
Point2::new(-1., -1.),
Point2::new(1., -1.),
Point2::new(1., 1.),
Point2::new(-1., 1.),
Point2::new(-1., -1.),
]);
let clip = NurbsCurve2D::<f64>::polyline(
&[
Point2::new(-1., -1.),
Point2::new(1., -1.),
Point2::new(1., 1.),
Point2::new(-1., 1.),
Point2::new(-1., -1.),
],
true,
);

let delta: f64 = 1.2782841177;
let trans = Translation2::new(delta.cos(), 0.) * Rotation2::new(delta);
Expand Down
Loading

0 comments on commit 7fdcbc1

Please sign in to comment.