Skip to content

Commit

Permalink
Merge pull request #2337 from hannobraun/geometry
Browse files Browse the repository at this point in the history
Add `UpdateCurveGeometry::make_line_on_surface`
  • Loading branch information
hannobraun authored Apr 29, 2024
2 parents 17180dc + 8590772 commit 9be74da
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
13 changes: 13 additions & 0 deletions crates/fj-core/src/geometry/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ pub struct CurveGeom {
pub definitions: BTreeMap<Handle<Surface>, LocalCurveGeom>,
}

impl CurveGeom {
/// # Return the local definition on the provided surface
///
/// ## Panics
///
/// Panics, if the curve has not been defined on that surface.
pub fn local_on(&self, surface: &Handle<Surface>) -> &LocalCurveGeom {
self.definitions
.get(surface)
.expect("Curve not defined on provided surface")
}
}

/// The geometric definition of a curve in 2D surface coordinates
#[derive(Clone)]
pub struct LocalCurveGeom {
Expand Down
31 changes: 19 additions & 12 deletions crates/fj-core/src/operations/build/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use fj_interop::ext::ArrayExt;
use fj_math::{Arc, Point, Scalar};

use crate::{
geometry::{CurveBoundary, HalfEdgeGeom, LocalCurveGeom, SurfacePath},
operations::{geometry::UpdateHalfEdgeGeometry, insert::Insert},
operations::{
geometry::{UpdateCurveGeometry, UpdateHalfEdgeGeometry},
insert::Insert,
},
storage::Handle,
topology::{Curve, HalfEdge, Surface, Vertex},
Core,
Expand Down Expand Up @@ -115,21 +117,26 @@ pub trait BuildHalfEdge {
surface: Handle<Surface>,
core: &mut Core,
) -> Handle<HalfEdge> {
let boundary = boundary.unwrap_or_default();
let path = SurfacePath::line_from_points_with_coords(
boundary.inner.zip_ext(points_surface),
);

let half_edge = HalfEdge::unjoined(core).insert(core);

core.layers.geometry.define_curve(
half_edge.curve().clone(),
surface,
LocalCurveGeom { path },
half_edge.curve().clone().make_line_on_surface(
points_surface,
boundary,
surface.clone(),
&mut core.layers.geometry,
);

core.layers.geometry.define_half_edge(
half_edge.clone(),
HalfEdgeGeom { path, boundary },
HalfEdgeGeom {
path: core
.layers
.geometry
.of_curve(half_edge.curve())
.local_on(&surface)
.path,
boundary: boundary.unwrap_or_default(),
},
);

half_edge
Expand Down
35 changes: 34 additions & 1 deletion crates/fj-core/src/operations/geometry/curve.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use fj_interop::ext::ArrayExt;
use fj_math::Point;

use crate::{
geometry::{Geometry, LocalCurveGeom, SurfacePath},
geometry::{CurveBoundary, Geometry, LocalCurveGeom, SurfacePath},
layers::Layer,
storage::Handle,
topology::{Curve, Surface},
Expand All @@ -14,6 +17,21 @@ pub trait UpdateCurveGeometry {
surface: Handle<Surface>,
geometry: &mut Layer<Geometry>,
) -> Self;

/// Define the geometry as a line
///
/// The line is constructed from two points on the provided surface.
///
/// Optionally the coordinates of those points on the curve can be supplied.
/// If those are not provided, it is assumed that the provided surface
/// points have the curve coordinates `0` and `1`.
fn make_line_on_surface(
self,
points_surface: [impl Into<Point<2>>; 2],
points_curve: Option<CurveBoundary<Point<1>>>,
surface: Handle<Surface>,
geometry: &mut Layer<Geometry>,
) -> Self;
}

impl UpdateCurveGeometry for Handle<Curve> {
Expand All @@ -27,4 +45,19 @@ impl UpdateCurveGeometry for Handle<Curve> {

self
}

fn make_line_on_surface(
self,
points_surface: [impl Into<Point<2>>; 2],
points_curve: Option<CurveBoundary<Point<1>>>,
surface: Handle<Surface>,
geometry: &mut Layer<Geometry>,
) -> Self {
let points_curve = points_curve.unwrap_or_default();
let path = SurfacePath::line_from_points_with_coords(
points_curve.inner.zip_ext(points_surface),
);

self.make_path_on_surface(path, surface, geometry)
}
}

0 comments on commit 9be74da

Please sign in to comment.