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

Define curve geometry in curve approximation tests #2324

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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