Skip to content

Commit

Permalink
Merge pull request #1950 from hannobraun/curve
Browse files Browse the repository at this point in the history
Add `Curve` object
  • Loading branch information
hannobraun authored Jul 19, 2023
2 parents 5d1d399 + a849efa commit a648c57
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 9 deletions.
19 changes: 19 additions & 0 deletions crates/fj-core/src/algorithms/transform/curve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use fj_math::Transform;

use crate::{objects::Curve, services::Services};

use super::{TransformCache, TransformObject};

impl TransformObject for Curve {
fn transform_with_cache(
self,
_: &Transform,
_: &mut Services,
_: &mut TransformCache,
) -> Self {
// There's nothing to actually transform here, as `Curve` holds no data.
// We still need this implementation though, as a new `Curve` object
// must be created to represent the new and transformed curve.
Self::new()
}
}
6 changes: 5 additions & 1 deletion crates/fj-core/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ impl TransformObject for HalfEdge {
// coordinates.
let path = self.path();
let boundary = self.boundary();
let curve = self
.curve()
.clone()
.transform_with_cache(transform, services, cache);
let start_vertex = self
.start_vertex()
.clone()
Expand All @@ -27,7 +31,7 @@ impl TransformObject for HalfEdge {
.clone()
.transform_with_cache(transform, services, cache);

Self::new(path, boundary, start_vertex, global_form)
Self::new(path, boundary, curve, start_vertex, global_form)
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/algorithms/transform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! API for transforming objects
mod curve;
mod cycle;
mod edge;
mod face;
Expand Down
32 changes: 32 additions & 0 deletions crates/fj-core/src/objects/kinds/curve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// A curve
///
/// `Curve` represents a curve in space, but holds no data to define that curve.
/// It is referenced by [`HalfEdge`], which defines the curve in the coordinates
/// of its surface.
///
/// `Curve` exists to allow identifying which [`HalfEdge`]s are supposed to be
/// coincident in global space.
///
/// # Equality
///
/// `Curve` contains no data and exists purely to be used within a `Handle`,
/// where `Handle::id` can be used to compare different instances of `Curve`.
///
/// If `Curve` had `Eq`/`PartialEq` implementations, it containing no data would
/// mean that all instances of `Curve` would be considered equal. This would be
/// very error-prone.
///
/// If you need to reference a `Curve` from a struct that needs to derive
/// `Eq`/`Ord`/..., you can use `HandleWrapper<Curve>` to do that. It will use
/// `Handle::id` to provide those `Eq`/`Ord`/... implementations.
///
/// [`HalfEdge`]: crate::objects::HalfEdge
#[derive(Clone, Debug, Default, Hash)]
pub struct Curve {}

impl Curve {
/// Create a new instance
pub fn new() -> Self {
Self::default()
}
}
10 changes: 9 additions & 1 deletion crates/fj-core/src/objects/kinds/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use fj_math::Point;

use crate::{
geometry::{BoundaryOnCurve, SurfacePath},
objects::Vertex,
objects::{Curve, Vertex},
storage::{Handle, HandleWrapper},
};

Expand Down Expand Up @@ -42,6 +42,7 @@ use crate::{
pub struct HalfEdge {
path: SurfacePath,
boundary: BoundaryOnCurve,
curve: HandleWrapper<Curve>,
start_vertex: HandleWrapper<Vertex>,
global_form: HandleWrapper<GlobalEdge>,
}
Expand All @@ -51,12 +52,14 @@ impl HalfEdge {
pub fn new(
path: SurfacePath,
boundary: impl Into<BoundaryOnCurve>,
curve: Handle<Curve>,
start_vertex: Handle<Vertex>,
global_form: Handle<GlobalEdge>,
) -> Self {
Self {
path,
boundary: boundary.into(),
curve: curve.into(),
start_vertex: start_vertex.into(),
global_form: global_form.into(),
}
Expand All @@ -82,6 +85,11 @@ impl HalfEdge {
self.path.point_from_path_coords(start)
}

/// Access the curve of the half-edge
pub fn curve(&self) -> &Handle<Curve> {
&self.curve
}

/// Access the vertex from where this half-edge starts
pub fn start_vertex(&self) -> &Handle<Vertex> {
&self.start_vertex
Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/objects/kinds/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod curve;
pub mod cycle;
pub mod edge;
pub mod face;
Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ mod stores;

pub use self::{
kinds::{
curve::Curve,
cycle::{Cycle, HalfEdgesOfCycle},
edge::{GlobalEdge, HalfEdge},
face::{Face, FaceSet, Handedness},
Expand Down
5 changes: 3 additions & 2 deletions crates/fj-core/src/objects/object.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
objects::{
Cycle, Face, GlobalEdge, HalfEdge, Objects, Region, Shell, Sketch,
Solid, Surface, Vertex,
Curve, Cycle, Face, GlobalEdge, HalfEdge, Objects, Region, Shell,
Sketch, Solid, Surface, Vertex,
},
storage::{Handle, HandleWrapper, ObjectId},
validate::{Validate, ValidationError},
Expand Down Expand Up @@ -91,6 +91,7 @@ macro_rules! object {
}

object!(
Curve, "curve", curves;
Cycle, "cycle", cycles;
Face, "face", faces;
GlobalEdge, "global edge", global_edges;
Expand Down
7 changes: 5 additions & 2 deletions crates/fj-core/src/objects/stores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ use crate::{
};

use super::{
Cycle, Face, GlobalEdge, HalfEdge, Region, Shell, Sketch, Solid, Surface,
Vertex,
Curve, Cycle, Face, GlobalEdge, HalfEdge, Region, Shell, Sketch, Solid,
Surface, Vertex,
};

/// The available object stores
#[derive(Debug, Default)]
pub struct Objects {
/// Store for [`Curve`]s
pub curves: Store<Curve>,

/// Store for [`Cycle`]s
pub cycles: Store<Cycle>,

Expand Down
5 changes: 3 additions & 2 deletions crates/fj-core/src/operations/build/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use fj_math::{Arc, Point, Scalar};

use crate::{
geometry::{BoundaryOnCurve, SurfacePath},
objects::{GlobalEdge, HalfEdge, Vertex},
objects::{Curve, GlobalEdge, HalfEdge, Vertex},
operations::Insert,
services::Services,
};
Expand All @@ -16,10 +16,11 @@ pub trait BuildHalfEdge {
boundary: impl Into<BoundaryOnCurve>,
services: &mut Services,
) -> HalfEdge {
let curve = Curve::new().insert(services);
let start_vertex = Vertex::new().insert(services);
let global_form = GlobalEdge::new().insert(services);

HalfEdge::new(path, boundary, start_vertex, global_form)
HalfEdge::new(path, boundary, curve, start_vertex, global_form)
}

/// Create an arc
Expand Down
3 changes: 2 additions & 1 deletion crates/fj-core/src/operations/insert.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
objects::{
Cycle, Face, GlobalEdge, HalfEdge, Region, Shell, Sketch, Solid,
Curve, Cycle, Face, GlobalEdge, HalfEdge, Region, Shell, Sketch, Solid,
Surface, Vertex,
},
services::Services,
Expand Down Expand Up @@ -43,6 +43,7 @@ macro_rules! impl_insert {
}

impl_insert!(
Curve, curves;
Cycle, cycles;
Face, faces;
GlobalEdge, global_edges;
Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/operations/reverse/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl Reverse for Cycle {
HalfEdge::new(
current.path(),
current.boundary().reverse(),
current.curve().clone(),
next.start_vertex().clone(),
current.global_form().clone(),
)
Expand Down
2 changes: 2 additions & 0 deletions crates/fj-core/src/operations/update/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl UpdateHalfEdge for HalfEdge {
HalfEdge::new(
self.path(),
self.boundary(),
self.curve().clone(),
start_vertex,
self.global_form().clone(),
)
Expand All @@ -28,6 +29,7 @@ impl UpdateHalfEdge for HalfEdge {
HalfEdge::new(
self.path(),
self.boundary(),
self.curve().clone(),
self.start_vertex().clone(),
global_form,
)
Expand Down
12 changes: 12 additions & 0 deletions crates/fj-core/src/validate/curve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::objects::Curve;

use super::{Validate, ValidationConfig, ValidationError};

impl Validate for Curve {
fn validate_with_config(
&self,
_: &ValidationConfig,
_: &mut Vec<ValidationError>,
) {
}
}
1 change: 1 addition & 0 deletions crates/fj-core/src/validate/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ mod tests {
HalfEdge::new(
valid.path(),
boundary,
valid.curve().clone(),
valid.start_vertex().clone(),
valid.global_form().clone(),
)
Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/validate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Infrastructure for validating objects
mod curve;
mod cycle;
mod edge;
mod face;
Expand Down

0 comments on commit a648c57

Please sign in to comment.