Skip to content

Commit

Permalink
Merge pull request #1131 from hannobraun/ready/partial-curve
Browse files Browse the repository at this point in the history
Replace curve builder with partial curves
  • Loading branch information
hannobraun authored Sep 22, 2022
2 parents 8d2fc79 + cf9c326 commit 6bca7ed
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 157 deletions.
24 changes: 16 additions & 8 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ mod tests {
let stores = Stores::new();

let surface = Surface::new(GlobalPath::x_axis(), [0., 0., 1.]);
let curve = Curve::builder(&stores, surface)
.build_line_from_points([[1., 1.], [2., 1.]]);
let curve = Curve::partial()
.with_surface(surface)
.as_line_from_points([[1., 1.], [2., 1.]])
.build(&stores);
let range = RangeOnPath::from([[0.], [1.]]);

let approx = (&curve, range).approx(1.);
Expand All @@ -224,8 +226,10 @@ mod tests {

let surface =
Surface::new(GlobalPath::circle_from_radius(1.), [0., 0., 1.]);
let curve = Curve::builder(&stores, surface)
.build_line_from_points([[1., 1.], [1., 2.]]);
let curve = Curve::partial()
.with_surface(surface)
.as_line_from_points([[1., 1.], [1., 2.]])
.build(&stores);
let range = RangeOnPath::from([[0.], [1.]]);

let approx = (&curve, range).approx(1.);
Expand All @@ -239,8 +243,10 @@ mod tests {

let path = GlobalPath::circle_from_radius(1.);
let surface = Surface::new(path, [0., 0., 1.]);
let curve = Curve::builder(&stores, surface)
.build_line_from_points([[0., 1.], [1., 1.]]);
let curve = Curve::partial()
.with_surface(surface)
.as_line_from_points([[0., 1.], [1., 1.]])
.build(&stores);

let range = RangeOnPath::from([[0.], [TAU]]);
let tolerance = 1.;
Expand All @@ -266,8 +272,10 @@ mod tests {
let stores = Stores::new();

let surface = Surface::new(GlobalPath::x_axis(), [0., 0., 1.]);
let curve =
Curve::builder(&stores, surface).build_circle_from_radius(1.);
let curve = Curve::partial()
.with_surface(surface)
.as_circle_from_radius(1.)
.build(&stores);

let range = RangeOnPath::from([[0.], [TAU]]);
let tolerance = 1.;
Expand Down
20 changes: 16 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ mod tests {
let stores = Stores::new();

let surface = Surface::xy_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let curve = Curve::partial()
.with_surface(surface)
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[1., -1.], [1., 1.]])
.build();
Expand All @@ -106,7 +109,10 @@ mod tests {
let stores = Stores::new();

let surface = Surface::xy_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let curve = Curve::partial()
.with_surface(surface)
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[-1., -1.], [-1., 1.]])
.build();
Expand All @@ -126,7 +132,10 @@ mod tests {
let stores = Stores::new();

let surface = Surface::xy_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let curve = Curve::partial()
.with_surface(surface)
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[-1., -1.], [1., -1.]])
.build();
Expand All @@ -141,7 +150,10 @@ mod tests {
let stores = Stores::new();

let surface = Surface::xy_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let curve = Curve::partial()
.with_surface(surface)
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[-1., 0.], [1., 0.]])
.build();
Expand Down
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ mod tests {

let surface = Surface::xy_plane();

let curve = Curve::builder(&stores, surface)
.build_line_from_points([[-3., 0.], [-2., 0.]]);
let curve = Curve::partial()
.with_surface(surface)
.as_line_from_points([[-3., 0.], [-2., 0.]])
.build(&stores);

#[rustfmt::skip]
let exterior = [
Expand Down
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ mod tests {
let intersection = FaceFaceIntersection::compute([&a, &b], &stores);

let expected_curves = surfaces.map(|surface| {
Curve::builder(&stores, surface)
.build_line_from_points([[0., 0.], [1., 0.]])
Curve::partial()
.with_surface(surface)
.as_line_from_points([[0., 0.], [1., 0.]])
.build(&stores)
});
let expected_intervals =
CurveFaceIntersection::from_intervals([[[-1.], [1.]]]);
Expand Down
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/surface_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ mod tests {
None,
);

let expected_xy = Curve::builder(&stores, xy).build_u_axis();
let expected_xz = Curve::builder(&stores, xz).build_u_axis();
let expected_xy =
Curve::partial().with_surface(xy).as_u_axis().build(&stores);
let expected_xz =
Curve::partial().with_surface(xz).as_u_axis().build(&stores);

assert_eq!(
SurfaceSurfaceIntersection::compute([&xy, &xz], &stores),
Expand Down
12 changes: 8 additions & 4 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ impl Sweep for GlobalVertex {
let a = self;
let b = GlobalVertex::from_position(self.position() + path.into());

let curve = GlobalCurve::builder(stores)
.line_from_points([a.position(), b.position()]);
let curve = GlobalCurve::partial()
.as_line_from_points([a.position(), b.position()])
.build(stores);

GlobalEdge::new(curve, [a, b])
}
Expand All @@ -160,7 +161,10 @@ mod tests {
let stores = Stores::new();

let surface = Surface::xz_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let curve = Curve::partial()
.with_surface(surface)
.as_u_axis()
.build(&stores);
let vertex = Vertex::partial()
.with_position([0.])
.with_curve(curve)
Expand All @@ -182,7 +186,7 @@ mod tests {
.sweep([0., 0., 1.], &stores);

let expected_edge = GlobalEdge::new(
GlobalCurve::builder(&stores).z_axis(),
GlobalCurve::partial().as_z_axis().build(&stores),
[[0., 0., 0.], [0., 0., 1.]].map(GlobalVertex::from_position),
);
assert_eq!(edge, expected_edge);
Expand Down
118 changes: 0 additions & 118 deletions crates/fj-kernel/src/builder/curve.rs

This file was deleted.

6 changes: 4 additions & 2 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ impl<'a> HalfEdgeBuilder<'a> {

/// Build the [`HalfEdge`] as a circle from the given radius
pub fn as_circle_from_radius(mut self, radius: impl Into<Scalar>) -> Self {
let curve = Curve::builder(self.stores, self.surface)
.build_circle_from_radius(radius);
let curve = Curve::partial()
.with_surface(self.surface)
.as_circle_from_radius(radius)
.build(self.stores);

let vertices = {
let [a_curve, b_curve] =
Expand Down
2 changes: 0 additions & 2 deletions crates/fj-kernel/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! API for building objects
mod curve;
mod cycle;
mod edge;
mod face;
Expand All @@ -9,7 +8,6 @@ mod sketch;
mod solid;

pub use self::{
curve::{CurveBuilder, GlobalCurveBuilder},
cycle::CycleBuilder,
edge::{GlobalEdgeBuilder, HalfEdgeBuilder},
face::FaceBuilder,
Expand Down
12 changes: 9 additions & 3 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ mod tests {
let stores = Stores::new();

let surface = Surface::xy_plane();
let object = Curve::builder(&stores, surface).build_u_axis();
let object = Curve::partial()
.with_surface(surface)
.as_u_axis()
.build(&stores);

assert_eq!(1, object.curve_iter().count());
assert_eq!(0, object.cycle_iter().count());
Expand Down Expand Up @@ -425,7 +428,7 @@ mod tests {
fn global_curve() {
let stores = Stores::new();

let object = GlobalCurve::builder(&stores).x_axis();
let object = GlobalCurve::partial().as_x_axis().build(&stores);

assert_eq!(0, object.curve_iter().count());
assert_eq!(0, object.cycle_iter().count());
Expand Down Expand Up @@ -561,7 +564,10 @@ mod tests {
let stores = Stores::new();

let surface = Surface::xy_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let curve = Curve::partial()
.with_surface(surface)
.as_u_axis()
.build(&stores);
let global_vertex = GlobalVertex::from_position([0., 0., 0.]);
let surface_vertex =
SurfaceVertex::new([0., 0.], surface, global_vertex);
Expand Down
22 changes: 14 additions & 8 deletions crates/fj-kernel/src/objects/curve.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
builder::{CurveBuilder, GlobalCurveBuilder},
partial::{PartialCurve, PartialGlobalCurve},
path::{GlobalPath, SurfacePath},
stores::{Handle, Stores},
stores::Handle,
};

use super::Surface;
Expand All @@ -15,9 +15,12 @@ pub struct Curve {
}

impl Curve {
/// Build a `Curve` using [`CurveBuilder`]
pub fn builder(stores: &Stores, surface: Surface) -> CurveBuilder {
CurveBuilder { stores, surface }
/// Create a [`PartialCurve`]
///
/// This function exists just for convenience, and will just return a
/// default [`PartialCurve`].
pub fn partial() -> PartialCurve {
PartialCurve::default()
}

/// Construct a new instance of `Curve`
Expand Down Expand Up @@ -56,9 +59,12 @@ pub struct GlobalCurve {
}

impl GlobalCurve {
/// Build a `Curve` using [`GlobalCurveBuilder`]
pub fn builder(stores: &Stores) -> GlobalCurveBuilder {
GlobalCurveBuilder { stores }
/// Create a [`PartialGlobalCurve`]
///
/// This function exists just for convenience, and will just return a
/// default [`PartialGlobalCurve`].
pub fn partial() -> PartialGlobalCurve {
PartialGlobalCurve::default()
}

/// Construct a `GlobalCurve` from the path that defines it
Expand Down
Loading

0 comments on commit 6bca7ed

Please sign in to comment.