Skip to content

Commit

Permalink
Merge pull request #1176 from hannobraun/curve
Browse files Browse the repository at this point in the history
Integrate `Curve` into centralized object storage
  • Loading branch information
hannobraun authored Oct 6, 2022
2 parents 7b269b5 + a222aff commit 48c2258
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 65 deletions.
12 changes: 6 additions & 6 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{

use super::{path::RangeOnPath, Approx, ApproxPoint, Tolerance};

impl Approx for (&Curve, RangeOnPath) {
impl Approx for (&Handle<Curve>, RangeOnPath) {
type Approximation = CurveApprox;
type Cache = CurveCache;

Expand Down Expand Up @@ -200,7 +200,7 @@ mod tests {
objects::{Curve, Surface},
partial::HasPartial,
path::GlobalPath,
stores::Stores,
stores::{Handle, Stores},
};

use super::CurveApprox;
Expand All @@ -212,7 +212,7 @@ mod tests {
let surface = stores
.surfaces
.insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]));
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface))
.as_line_from_points([[1., 1.], [2., 1.]])
.build(&stores);
Expand All @@ -231,7 +231,7 @@ mod tests {
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
));
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface))
.as_line_from_points([[1., 1.], [1., 2.]])
.build(&stores);
Expand All @@ -248,7 +248,7 @@ mod tests {

let path = GlobalPath::circle_from_radius(1.);
let surface = stores.surfaces.insert(Surface::new(path, [0., 0., 1.]));
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_line_from_points([[0., 1.], [1., 1.]])
.build(&stores);
Expand Down Expand Up @@ -279,7 +279,7 @@ mod tests {
let surface = stores
.surfaces
.insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]));
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface))
.as_circle_from_radius(1.)
.build(&stores);
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/approx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::{

use fj_math::Point;

use crate::objects::Curve;
use crate::{objects::Curve, stores::Handle};

pub use self::tolerance::{InvalidTolerance, Tolerance};

Expand Down Expand Up @@ -119,4 +119,4 @@ impl<const D: usize> PartialOrd for ApproxPoint<D> {
/// The source of an [`ApproxPoint`]
pub trait Source: Any + Debug {}

impl Source for (Curve, Point<1>) {}
impl Source for (Handle<Curve>, Point<1>) {}
10 changes: 5 additions & 5 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mod tests {
use crate::{
objects::{Curve, HalfEdge, Surface},
partial::HasPartial,
stores::Stores,
stores::{Handle, Stores},
};

use super::CurveEdgeIntersection;
Expand All @@ -87,7 +87,7 @@ mod tests {
let stores = Stores::new();

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
Expand All @@ -111,7 +111,7 @@ mod tests {
let stores = Stores::new();

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
Expand All @@ -135,7 +135,7 @@ mod tests {
let stores = Stores::new();

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
Expand All @@ -154,7 +154,7 @@ mod tests {
let stores = Stores::new();

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ mod tests {
use crate::{
objects::{Curve, Face, Surface},
partial::HasPartial,
stores::Stores,
stores::{Handle, Stores},
};

use super::CurveFaceIntersection;
Expand All @@ -169,7 +169,7 @@ mod tests {

let surface = stores.surfaces.insert(Surface::xy_plane());

let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_line_from_points([[-3., 0.], [-2., 0.]])
.build(&stores);
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
objects::{Curve, Face},
stores::Stores,
stores::{Handle, Stores},
};

use super::{CurveFaceIntersection, SurfaceSurfaceIntersection};
Expand All @@ -14,7 +14,7 @@ pub struct FaceFaceIntersection {
/// representation of the intersection on the respective face's surface.
///
/// They both represent the same global curve.
pub intersection_curves: [Curve; 2],
pub intersection_curves: [Handle<Curve>; 2],

/// The interval of this intersection, in curve coordinates
///
Expand Down Expand Up @@ -66,7 +66,7 @@ mod tests {
algorithms::intersect::CurveFaceIntersection,
objects::{Curve, Face, Surface},
partial::HasPartial,
stores::Stores,
stores::{Handle, Stores},
};

use super::FaceFaceIntersection;
Expand Down Expand Up @@ -117,7 +117,7 @@ mod tests {
let intersection = FaceFaceIntersection::compute([&a, &b], &stores);

let expected_curves = surfaces.map(|surface| {
Curve::partial()
Handle::<Curve>::partial()
.with_surface(Some(surface))
.as_line_from_points([[0., 0.], [1., 0.]])
.build(&stores)
Expand Down
11 changes: 6 additions & 5 deletions crates/fj-kernel/src/algorithms/intersect/surface_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct SurfaceSurfaceIntersection {
/// The intersection curves
pub intersection_curves: [Curve; 2],
pub intersection_curves: [Handle<Curve>; 2],
}

impl SurfaceSurfaceIntersection {
Expand Down Expand Up @@ -58,8 +58,9 @@ impl SurfaceSurfaceIntersection {
let curves = surfaces_and_planes.map(|(surface, plane)| {
let path = SurfacePath::Line(plane.project_line(&line));
let global_form = GlobalCurve::new(stores);
let curve = Curve::new(surface, path, global_form);

Curve::new(surface, path, global_form)
stores.curves.insert(curve)
});

Some(Self {
Expand Down Expand Up @@ -90,7 +91,7 @@ mod tests {
algorithms::transform::TransformObject,
objects::{Curve, Surface},
partial::HasPartial,
stores::Stores,
stores::{Handle, Stores},
};

use super::SurfaceSurfaceIntersection;
Expand All @@ -117,11 +118,11 @@ mod tests {
None,
);

let expected_xy = Curve::partial()
let expected_xy = Handle::<Curve>::partial()
.with_surface(Some(xy.clone()))
.as_u_axis()
.build(&stores);
let expected_xz = Curve::partial()
let expected_xz = Handle::<Curve>::partial()
.with_surface(Some(xz.clone()))
.as_u_axis()
.build(&stores);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{

use super::Sweep;

impl Sweep for Curve {
impl Sweep for Handle<Curve> {
type Swept = Handle<Surface>;

fn sweep(self, path: impl Into<Vector<3>>, stores: &Stores) -> Self::Swept {
Expand Down
10 changes: 7 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ impl Sweep for (HalfEdge, Color) {
points_curve_and_surface,
));

Curve::new(
let curve = Curve::new(
surface.clone(),
path,
edge.curve().global_form().clone(),
)
);

stores.curves.insert(curve)
};

let vertices = {
Expand Down Expand Up @@ -110,7 +112,9 @@ impl Sweep for (HalfEdge, Color) {
points_curve_and_surface,
));

Curve::new(surface.clone(), path, global)
let curve = Curve::new(surface.clone(), path, global);

stores.curves.insert(curve)
};

let global =
Expand Down
9 changes: 5 additions & 4 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ impl Sweep for (Vertex, Handle<Surface>) {
// `Edge` is straight-forward.
let curve = {
let line = Line::from_points(points_surface);
Curve::new(
let curve = Curve::new(
surface.clone(),
SurfacePath::Line(line),
edge_global.curve().clone(),
)
);
stores.curves.insert(curve)
};

// And now the vertices. Again, nothing wild here.
Expand Down Expand Up @@ -152,15 +153,15 @@ mod tests {
algorithms::sweep::Sweep,
objects::{Curve, HalfEdge, Surface, Vertex},
partial::HasPartial,
stores::Stores,
stores::{Handle, Stores},
};

#[test]
fn vertex_surface() {
let stores = Stores::new();

let surface = stores.surfaces.insert(Surface::xz_plane());
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use fj_math::Transform;
use crate::{
objects::Curve,
partial::{MaybePartial, PartialGlobalEdge, PartialHalfEdge},
stores::Stores,
stores::{Handle, Stores},
};

use super::TransformObject;
Expand Down Expand Up @@ -34,7 +34,7 @@ impl TransformObject for PartialHalfEdge {
.into_partial()
.transform(transform, stores)
.with_curve(curve.as_ref().and_then(
|curve: &MaybePartial<Curve>| curve.global_form(),
|curve: &MaybePartial<Handle<Curve>>| curve.global_form(),
))
.into()
});
Expand Down
5 changes: 3 additions & 2 deletions crates/fj-kernel/src/algorithms/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ mod tests {

let curve = {
let path = SurfacePath::line_from_points(points_surface);
let curve_global = GlobalCurve::new(&stores);
Curve::new(surface.clone(), path, curve_global)
let global_form = GlobalCurve::new(&stores);
let curve = Curve::new(surface.clone(), path, global_form);
stores.curves.insert(curve)
};

let [a_global, b_global] =
Expand Down
9 changes: 5 additions & 4 deletions crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
Curve, Cycle, Face, HalfEdge, Shell, Surface, SurfaceVertex, Vertex,
},
partial::HasPartial,
stores::Stores,
stores::{Handle, Stores},
};

/// API for building a [`Shell`]
Expand Down Expand Up @@ -119,9 +119,10 @@ impl<'a> ShellBuilder<'a> {
.with_surface(Some(surface.clone()))
.with_global_form(Some(*from.global_form()));

let curve = Curve::partial().with_global_form(Some(
side_up_prev.curve().global_form().clone(),
));
let curve = Handle::<Curve>::partial()
.with_global_form(Some(
side_up_prev.curve().global_form().clone(),
));

HalfEdge::partial()
.with_curve(Some(curve))
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub trait ObjectIters<'r> {
}
}

impl<'r> ObjectIters<'r> for Curve {
impl<'r> ObjectIters<'r> for Handle<Curve> {
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> {
vec![self.global_form() as &dyn ObjectIters]
}
Expand Down Expand Up @@ -365,7 +365,7 @@ mod tests {
Sketch, Solid, Surface, SurfaceVertex, Vertex,
},
partial::HasPartial,
stores::Stores,
stores::{Handle, Stores},
};

use super::ObjectIters as _;
Expand All @@ -375,7 +375,7 @@ mod tests {
let stores = Stores::new();

let surface = stores.surfaces.insert(Surface::xy_plane());
let object = Curve::partial()
let object = Handle::<Curve>::partial()
.with_surface(Some(surface))
.as_u_axis()
.build(&stores);
Expand Down Expand Up @@ -582,7 +582,7 @@ mod tests {
let stores = Stores::new();

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl HalfEdge {
pub fn new([a, b]: [Vertex; 2], global_form: GlobalEdge) -> Self {
// Make sure `curve` and `vertices` match.
assert_eq!(
a.curve(),
b.curve(),
a.curve().id(),
b.curve().id(),
"An edge's vertices must be defined in the same curve",
);

Expand Down Expand Up @@ -69,7 +69,7 @@ impl HalfEdge {
}

/// Access the curve that defines the half-edge's geometry
pub fn curve(&self) -> &Curve {
pub fn curve(&self) -> &Handle<Curve> {
let [vertex, _] = self.vertices();
vertex.curve()
}
Expand Down
Loading

0 comments on commit 48c2258

Please sign in to comment.