Skip to content

Commit

Permalink
Merge pull request #1597 from hannobraun/surface
Browse files Browse the repository at this point in the history
Remove reference to `Surface` from `SurfaceVertex`
  • Loading branch information
hannobraun authored Feb 17, 2023
2 parents abef26e + c55abb0 commit e80875a
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 239 deletions.
18 changes: 12 additions & 6 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ mod tests {
half_edge
};
let side_up = {
let mut side_up = PartialHalfEdge::default();
side_up.replace_surface(surface.clone());
let mut side_up = PartialHalfEdge {
surface: surface.clone(),
..Default::default()
};

{
let [back, front] = side_up
Expand All @@ -217,8 +219,10 @@ mod tests {
side_up
};
let top = {
let mut top = PartialHalfEdge::default();
top.replace_surface(surface.clone());
let mut top = PartialHalfEdge {
surface: surface.clone(),
..Default::default()
};

{
let [(back, back_surface), (front, front_surface)] =
Expand All @@ -243,8 +247,10 @@ mod tests {
.clone()
};
let side_down = {
let mut side_down = PartialHalfEdge::default();
side_down.replace_surface(surface);
let mut side_down = PartialHalfEdge {
surface,
..Default::default()
};

let [(back, back_surface), (front, front_surface)] =
side_down.vertices.each_mut_ext();
Expand Down
6 changes: 1 addition & 5 deletions crates/fj-kernel/src/algorithms/transform/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ impl TransformObject for SurfaceVertex {
// coordinates and thus transforming the surface takes care of it.
let position = self.position();

let surface = self
.surface()
.clone()
.transform_with_cache(transform, objects, cache);
let global_form = self
.global_form()
.clone()
.transform_with_cache(transform, objects, cache);

Self::new(position, surface, global_form)
Self::new(position, global_form)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl CycleBuilder for PartialCycle {

let [_, vertex] = &mut new_half_edge.vertices;
vertex.1 = shared_surface_vertex;
new_half_edge.replace_surface(self.surface.clone());
new_half_edge.surface = self.surface.clone();
new_half_edge.infer_global_form();
}

Expand Down
22 changes: 1 addition & 21 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ use super::CurveBuilder;

/// Builder API for [`PartialHalfEdge`]
pub trait HalfEdgeBuilder {
/// Completely replace the surface in this half-edge's object graph
///
/// Please note that this operation will write to both vertices that the
/// half-edge references. If any of them were created from full objects,
/// this will break the connection to those, meaning that building the
/// partial objects won't result in those full objects again. This will be
/// the case, even if those full objects already referenced the provided
/// surface.
fn replace_surface(&mut self, surface: impl Into<Partial<Surface>>);

/// Update partial half-edge to be a circle, from the given radius
fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>);

Expand Down Expand Up @@ -61,16 +51,6 @@ pub trait HalfEdgeBuilder {
}

impl HalfEdgeBuilder for PartialHalfEdge {
fn replace_surface(&mut self, surface: impl Into<Partial<Surface>>) {
let surface = surface.into();

self.surface = surface.clone();

for vertex in &mut self.vertices {
vertex.1.write().surface = surface.clone();
}
}

fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>) {
let path = self.curve.write().update_as_circle_from_radius(radius);

Expand Down Expand Up @@ -134,7 +114,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
surface: impl Into<Partial<Surface>>,
points: [impl Into<Point<2>>; 2],
) {
self.replace_surface(surface.into());
self.surface = surface.into();

for (vertex, point) in self.vertices.each_mut_ext().zip_ext(points) {
let mut surface_form = vertex.1.write();
Expand Down
28 changes: 3 additions & 25 deletions crates/fj-kernel/src/builder/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
use fj_math::Point;

use crate::partial::{PartialGlobalVertex, PartialSurfaceVertex};

/// Builder API for [`PartialSurfaceVertex`]
pub trait SurfaceVertexBuilder {
/// Infer the position of the surface vertex' global form
///
/// Updates the global vertex referenced by this surface vertex with the
/// inferred position, and also returns the position.
fn infer_global_position(&mut self) -> Point<3>;
}
pub trait SurfaceVertexBuilder {}

impl SurfaceVertexBuilder for PartialSurfaceVertex {
fn infer_global_position(&mut self) -> Point<3> {
let position_surface = self
.position
.expect("Can't infer global position without surface position");
let surface = self
.surface
.read()
.geometry
.expect("Can't infer global position without surface geometry");

let position_global =
surface.point_from_surface_coords(position_surface);
self.global_form.write().position = Some(position_global);

position_global
}
// No methods are currently defined. This trait serves as a placeholder, to
// make it clear where to add such methods, once necessary.
}

/// Builder API for [`PartialGlobalVertex`]
Expand Down
10 changes: 1 addition & 9 deletions crates/fj-kernel/src/objects/full/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
use fj_math::Point;

use crate::{objects::Surface, storage::Handle};
use crate::storage::Handle;

/// A vertex, defined in surface (2D) coordinates
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct SurfaceVertex {
position: Point<2>,
surface: Handle<Surface>,
global_form: Handle<GlobalVertex>,
}

impl SurfaceVertex {
/// Construct a new instance of `SurfaceVertex`
pub fn new(
position: impl Into<Point<2>>,
surface: Handle<Surface>,
global_form: Handle<GlobalVertex>,
) -> Self {
let position = position.into();
Self {
position,
surface,
global_form,
}
}
Expand All @@ -30,11 +27,6 @@ impl SurfaceVertex {
self.position
}

/// Access the surface that the vertex is defined in
pub fn surface(&self) -> &Handle<Surface> {
&self.surface
}

/// Access the global form of the vertex
pub fn global_form(&self) -> &Handle<GlobalVertex> {
&self.global_form
Expand Down
10 changes: 2 additions & 8 deletions crates/fj-kernel/src/partial/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crate::{
Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects,
Surface, SurfaceVertex,
},
partial::{
FullToPartialCache, Partial, PartialObject, PartialSurfaceVertex,
},
partial::{FullToPartialCache, Partial, PartialObject},
services::Service,
};

Expand Down Expand Up @@ -106,11 +104,7 @@ impl Default for PartialHalfEdge {

let curve = Partial::<Curve>::new();
let vertices = array::from_fn(|_| {
let surface_form = Partial::from_partial(PartialSurfaceVertex {
surface: surface.clone(),
..Default::default()
});

let surface_form = Partial::default();
(None, surface_form)
});

Expand Down
12 changes: 2 additions & 10 deletions crates/fj-kernel/src/partial/objects/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fj_math::Point;

use crate::{
objects::{GlobalVertex, Objects, Surface, SurfaceVertex},
objects::{GlobalVertex, Objects, SurfaceVertex},
partial::{FullToPartialCache, Partial, PartialObject},
services::Service,
};
Expand All @@ -12,9 +12,6 @@ pub struct PartialSurfaceVertex {
/// The position of the vertex on the surface
pub position: Option<Point<2>>,

/// The surface that the vertex is defined in
pub surface: Partial<Surface>,

/// The global form of the vertex
pub global_form: Partial<GlobalVertex>,
}
Expand All @@ -28,10 +25,6 @@ impl PartialObject for PartialSurfaceVertex {
) -> Self {
Self {
position: Some(surface_vertex.position()),
surface: Partial::from_full(
surface_vertex.surface().clone(),
cache,
),
global_form: Partial::from_full(
surface_vertex.global_form().clone(),
cache,
Expand All @@ -43,10 +36,9 @@ impl PartialObject for PartialSurfaceVertex {
let position = self
.position
.expect("Can't build `SurfaceVertex` without position");
let surface = self.surface.build(objects);
let global_form = self.global_form.build(objects);

SurfaceVertex::new(position, surface, global_form)
SurfaceVertex::new(position, global_form)
}
}

Expand Down
Loading

0 comments on commit e80875a

Please sign in to comment.