Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace curve builder with partial curves #1131

Merged
merged 31 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d231081
Move `builder::curve` to `partial`
hannobraun Sep 22, 2022
875ee3a
Rename `GlobalCurveBuilder`
hannobraun Sep 22, 2022
77d61e6
Rename `GlobalCurve::builder`
hannobraun Sep 22, 2022
323f720
Add path to `PartialGlobalCurve`
hannobraun Sep 22, 2022
444cb09
Replace `PartialGlobalCurve::x_axis`
hannobraun Sep 22, 2022
ba60279
Replace `PartialGlobalCurve::y_axis`
hannobraun Sep 22, 2022
e294945
Replace `PartialGlobalCurve::z_axis`
hannobraun Sep 22, 2022
5a3a015
Replace `PartialGlobalCurve::circle_from_radius`
hannobraun Sep 22, 2022
40d432b
Replace `PartialGlobalCurve::line_from_points`
hannobraun Sep 22, 2022
f3a7d8c
Expect `&Stores` in `PartialGlobalCurve::build`
hannobraun Sep 22, 2022
236ee6b
Derive `Default` for `PartialGlobalCurve`
hannobraun Sep 22, 2022
f327aba
Update documentation of `PartialGlobalCurve`
hannobraun Sep 22, 2022
aaad1d9
Rename `CurveBuilder` to `PartialCurve`
hannobraun Sep 22, 2022
5ba7d97
Rename `Curve::builder` to `Curve::partial`
hannobraun Sep 22, 2022
ef1544d
Split `PartialCurve::build_line_from_points`
hannobraun Sep 22, 2022
b9edbd1
Refactor
hannobraun Sep 22, 2022
f19f7ac
Refactor
hannobraun Sep 22, 2022
9cd00c5
Replace `PartialCurve::build_circle_from_radius`
hannobraun Sep 22, 2022
5c03961
Replace `PartialCurve::build_v_axis`
hannobraun Sep 22, 2022
ec7e01f
Replace `PartialCurve::build_u_axis`
hannobraun Sep 22, 2022
038b32a
Refactor
hannobraun Sep 22, 2022
e24dd24
Rename variable to be more specific
hannobraun Sep 22, 2022
680d74c
Refactor
hannobraun Sep 22, 2022
d534af5
Add `PartialCurve::with_global_form`
hannobraun Sep 22, 2022
2d7f0fd
Add `PartialCurve::with_path`
hannobraun Sep 22, 2022
9bc4e21
Expect `&Stores` in `PartialCurve::build`
hannobraun Sep 22, 2022
8fa6bac
Make `surface` in `PartialCurve` optional
hannobraun Sep 22, 2022
659fa9a
Derive `Default` for `PartialCurve`
hannobraun Sep 22, 2022
fe2ac53
Update documentation of `PartialCurve`
hannobraun Sep 22, 2022
da6ff4f
Compute global form in `PartialCurve::build`
hannobraun Sep 22, 2022
cf9c326
Refactor
hannobraun Sep 22, 2022
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
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
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