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

Fix API for defining curve geometry #2329

Merged
merged 3 commits into from
Apr 29, 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
15 changes: 1 addition & 14 deletions crates/fj-core/src/geometry/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{storage::Handle, topology::Surface};
use super::SurfacePath;

/// The geometric definition of a curve
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct CurveGeom {
/// # The redundant local definitions of the curve geometry
///
Expand All @@ -27,19 +27,6 @@ pub struct CurveGeom {
pub definitions: BTreeMap<Handle<Surface>, 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 {
let mut definitions = BTreeMap::new();
definitions.insert(surface, LocalCurveGeom { path });

Self { definitions }
}
}

/// The geometric definition of a curve in 2D surface coordinates
#[derive(Clone)]
pub struct LocalCurveGeom {
Expand Down
11 changes: 8 additions & 3 deletions crates/fj-core/src/geometry/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
topology::{Curve, HalfEdge, Surface, Topology},
};

use super::{CurveGeom, GlobalPath, HalfEdgeGeom, SurfaceGeom};
use super::{CurveGeom, GlobalPath, HalfEdgeGeom, LocalCurveGeom, SurfaceGeom};

/// Geometric data that is associated with topological objects
pub struct Geometry {
Expand Down Expand Up @@ -65,9 +65,14 @@ impl Geometry {
pub(crate) fn define_curve_inner(
&mut self,
curve: Handle<Curve>,
geometry: CurveGeom,
surface: Handle<Surface>,
geometry: LocalCurveGeom,
) {
self.curve.insert(curve, geometry);
self.curve
.entry(curve)
.or_default()
.definitions
.insert(surface, geometry);
}

pub(crate) fn define_half_edge_inner(
Expand Down
27 changes: 22 additions & 5 deletions crates/fj-core/src/layers/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Layer infrastructure for [`Geometry`]

use crate::{
geometry::{CurveGeom, Geometry, HalfEdgeGeom, SurfaceGeom},
geometry::{Geometry, HalfEdgeGeom, LocalCurveGeom, SurfaceGeom},
storage::Handle,
topology::{Curve, HalfEdge, Surface},
};
Expand All @@ -10,9 +10,21 @@ use super::{Command, Event, Layer};

impl Layer<Geometry> {
/// Define the geometry of the provided curve
pub fn define_curve(&mut self, curve: Handle<Curve>, geometry: CurveGeom) {
pub fn define_curve(
&mut self,
curve: Handle<Curve>,
surface: Handle<Surface>,
geometry: LocalCurveGeom,
) {
let mut events = Vec::new();
self.process(DefineCurve { curve, geometry }, &mut events);
self.process(
DefineCurve {
curve,
surface,
geometry,
},
&mut events,
);
}

/// Define the geometry of the provided half-edge
Expand Down Expand Up @@ -50,7 +62,8 @@ impl Layer<Geometry> {
/// Define the geometry of a curve
pub struct DefineCurve {
curve: Handle<Curve>,
geometry: CurveGeom,
surface: Handle<Surface>,
geometry: LocalCurveGeom,
}

impl Command<Geometry> for DefineCurve {
Expand All @@ -68,7 +81,11 @@ impl Command<Geometry> for DefineCurve {

impl Event<Geometry> for DefineCurve {
fn evolve(&self, state: &mut Geometry) {
state.define_curve_inner(self.curve.clone(), self.geometry.clone());
state.define_curve_inner(
self.curve.clone(),
self.surface.clone(),
self.geometry.clone(),
);
}
}

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

use crate::{
geometry::{CurveGeom, HalfEdgeGeom, SurfacePath},
geometry::{HalfEdgeGeom, LocalCurveGeom, SurfacePath},
operations::{geometry::UpdateHalfEdgeGeometry, insert::Insert},
storage::Handle,
topology::{Curve, HalfEdge, Surface, Vertex},
Expand Down Expand Up @@ -65,7 +65,8 @@ pub trait BuildHalfEdge {

core.layers.geometry.define_curve(
half_edge.curve().clone(),
CurveGeom::from_path_and_surface(path, surface),
surface,
LocalCurveGeom { path },
);
core.layers.geometry.define_half_edge(
half_edge.clone(),
Expand Down Expand Up @@ -93,7 +94,8 @@ pub trait BuildHalfEdge {

core.layers.geometry.define_curve(
half_edge.curve().clone(),
CurveGeom::from_path_and_surface(path, surface),
surface,
LocalCurveGeom { path },
);
core.layers.geometry.define_half_edge(
half_edge.clone(),
Expand Down Expand Up @@ -123,7 +125,8 @@ pub trait BuildHalfEdge {

core.layers.geometry.define_curve(
half_edge.curve().clone(),
CurveGeom::from_path_and_surface(path, surface),
surface,
LocalCurveGeom { path },
);
core.layers.geometry.define_half_edge(
half_edge.clone(),
Expand Down
7 changes: 2 additions & 5 deletions crates/fj-core/src/operations/geometry/curve.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
geometry::{CurveGeom, Geometry, SurfacePath},
geometry::{Geometry, LocalCurveGeom, SurfacePath},
layers::Layer,
storage::Handle,
topology::{Curve, Surface},
Expand All @@ -23,10 +23,7 @@ impl UpdateCurveGeometry for Handle<Curve> {
surface: Handle<Surface>,
geometry: &mut Layer<Geometry>,
) -> Self {
geometry.define_curve(
self.clone(),
CurveGeom::from_path_and_surface(path, surface),
);
geometry.define_curve(self.clone(), surface, LocalCurveGeom { path });

self
}
Expand Down