Skip to content

Commit

Permalink
Merge pull request #2324 from hannobraun/geometry
Browse files Browse the repository at this point in the history
Define curve geometry in curve approximation tests
  • Loading branch information
hannobraun authored Apr 26, 2024
2 parents 3c3d53b + be5028b commit 788345c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
14 changes: 9 additions & 5 deletions crates/fj-core/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ mod tests {
use crate::{
algorithms::approx::{Approx, ApproxPoint},
geometry::{CurveBoundary, GlobalPath, HalfEdgeGeom, SurfacePath},
operations::{build::BuildSurface, insert::Insert},
operations::build::{BuildCurve, BuildSurface},
topology::{Curve, Surface},
Core,
};
Expand All @@ -195,7 +195,8 @@ mod tests {
let surface = core.layers.topology.surfaces.xz_plane();
let (path, boundary) =
SurfacePath::line_from_points([[1., 1.], [2., 1.]]);
let curve = Curve::new().insert(&mut core);
let curve =
Curve::from_path_and_surface(path, surface.clone(), &mut core);
let boundary = CurveBoundary::from(boundary);
let half_edge = HalfEdgeGeom { path, boundary };

Expand All @@ -217,7 +218,8 @@ mod tests {
);
let (path, boundary) =
SurfacePath::line_from_points([[1., 1.], [2., 1.]]);
let curve = Curve::new().insert(&mut core);
let curve =
Curve::from_path_and_surface(path, surface.clone(), &mut core);
let boundary = CurveBoundary::from(boundary);
let half_edge = HalfEdgeGeom { path, boundary };

Expand All @@ -238,7 +240,8 @@ mod tests {
([0.], [0., 1.]),
([TAU], [TAU, 1.]),
]);
let curve = Curve::new().insert(&mut core);
let curve =
Curve::from_path_and_surface(path, surface.clone(), &mut core);
let boundary = CurveBoundary::from([[0.], [TAU]]);
let half_edge = HalfEdgeGeom { path, boundary };

Expand Down Expand Up @@ -268,7 +271,8 @@ mod tests {

let surface = core.layers.topology.surfaces.xz_plane();
let path = SurfacePath::circle_from_center_and_radius([0., 0.], 1.);
let curve = Curve::new().insert(&mut core);
let curve =
Curve::from_path_and_surface(path, surface.clone(), &mut core);
let boundary = CurveBoundary::from([[0.], [TAU]]);
let half_edge = HalfEdgeGeom { path, boundary };

Expand Down
12 changes: 12 additions & 0 deletions crates/fj-core/src/geometry/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ pub struct CurveGeom {
pub definitions: Vec<LocalCurveGeom>,
}

impl CurveGeom {
/// Create a new instance of `CurveGeom` from a path and a surface
pub fn from_path_and_surface(
path: SurfacePath,
surface: Handle<Surface>,
) -> Self {
Self {
definitions: vec![LocalCurveGeom { path, surface }],
}
}
}

/// The geometric definition of a curve in 2D surface coordinates
#[derive(Clone)]
pub struct LocalCurveGeom {
Expand Down
32 changes: 32 additions & 0 deletions crates/fj-core/src/operations/build/curve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::{
geometry::{CurveGeom, SurfacePath},
operations::insert::Insert,
storage::Handle,
topology::{Curve, Surface},
Core,
};

/// Build a [`Curve`]
///
/// See [module-level documentation] for context.
///
/// [module-level documentation]: super
pub trait BuildCurve {
/// Build a curve from the provided path and surface
fn from_path_and_surface(
path: SurfacePath,
surface: Handle<Surface>,
core: &mut Core,
) -> Handle<Curve> {
let curve = Curve::new().insert(core);

core.layers.geometry.define_curve(
curve.clone(),
CurveGeom::from_path_and_surface(path, surface),
);

curve
}
}

impl BuildCurve for Curve {}
2 changes: 2 additions & 0 deletions crates/fj-core/src/operations/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! the top-level object itself, but also to the other objects that make up its
//! components.

mod curve;
mod cycle;
mod face;
mod half_edge;
Expand All @@ -27,6 +28,7 @@ mod solid;
mod surface;

pub use self::{
curve::BuildCurve,
cycle::BuildCycle,
face::{BuildFace, Polygon},
half_edge::BuildHalfEdge,
Expand Down

0 comments on commit 788345c

Please sign in to comment.