Skip to content

Commit e80875a

Browse files
authored
Merge pull request #1597 from hannobraun/surface
Remove reference to `Surface` from `SurfaceVertex`
2 parents abef26e + c55abb0 commit e80875a

File tree

12 files changed

+110
-239
lines changed

12 files changed

+110
-239
lines changed

crates/fj-kernel/src/algorithms/sweep/edge.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ mod tests {
196196
half_edge
197197
};
198198
let side_up = {
199-
let mut side_up = PartialHalfEdge::default();
200-
side_up.replace_surface(surface.clone());
199+
let mut side_up = PartialHalfEdge {
200+
surface: surface.clone(),
201+
..Default::default()
202+
};
201203

202204
{
203205
let [back, front] = side_up
@@ -217,8 +219,10 @@ mod tests {
217219
side_up
218220
};
219221
let top = {
220-
let mut top = PartialHalfEdge::default();
221-
top.replace_surface(surface.clone());
222+
let mut top = PartialHalfEdge {
223+
surface: surface.clone(),
224+
..Default::default()
225+
};
222226

223227
{
224228
let [(back, back_surface), (front, front_surface)] =
@@ -243,8 +247,10 @@ mod tests {
243247
.clone()
244248
};
245249
let side_down = {
246-
let mut side_down = PartialHalfEdge::default();
247-
side_down.replace_surface(surface);
250+
let mut side_down = PartialHalfEdge {
251+
surface,
252+
..Default::default()
253+
};
248254

249255
let [(back, back_surface), (front, front_surface)] =
250256
side_down.vertices.each_mut_ext();

crates/fj-kernel/src/algorithms/transform/vertex.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ impl TransformObject for SurfaceVertex {
1818
// coordinates and thus transforming the surface takes care of it.
1919
let position = self.position();
2020

21-
let surface = self
22-
.surface()
23-
.clone()
24-
.transform_with_cache(transform, objects, cache);
2521
let global_form = self
2622
.global_form()
2723
.clone()
2824
.transform_with_cache(transform, objects, cache);
2925

30-
Self::new(position, surface, global_form)
26+
Self::new(position, global_form)
3127
}
3228
}
3329

crates/fj-kernel/src/builder/cycle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl CycleBuilder for PartialCycle {
149149

150150
let [_, vertex] = &mut new_half_edge.vertices;
151151
vertex.1 = shared_surface_vertex;
152-
new_half_edge.replace_surface(self.surface.clone());
152+
new_half_edge.surface = self.surface.clone();
153153
new_half_edge.infer_global_form();
154154
}
155155

crates/fj-kernel/src/builder/edge.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ use super::CurveBuilder;
1111

1212
/// Builder API for [`PartialHalfEdge`]
1313
pub trait HalfEdgeBuilder {
14-
/// Completely replace the surface in this half-edge's object graph
15-
///
16-
/// Please note that this operation will write to both vertices that the
17-
/// half-edge references. If any of them were created from full objects,
18-
/// this will break the connection to those, meaning that building the
19-
/// partial objects won't result in those full objects again. This will be
20-
/// the case, even if those full objects already referenced the provided
21-
/// surface.
22-
fn replace_surface(&mut self, surface: impl Into<Partial<Surface>>);
23-
2414
/// Update partial half-edge to be a circle, from the given radius
2515
fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>);
2616

@@ -61,16 +51,6 @@ pub trait HalfEdgeBuilder {
6151
}
6252

6353
impl HalfEdgeBuilder for PartialHalfEdge {
64-
fn replace_surface(&mut self, surface: impl Into<Partial<Surface>>) {
65-
let surface = surface.into();
66-
67-
self.surface = surface.clone();
68-
69-
for vertex in &mut self.vertices {
70-
vertex.1.write().surface = surface.clone();
71-
}
72-
}
73-
7454
fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>) {
7555
let path = self.curve.write().update_as_circle_from_radius(radius);
7656

@@ -134,7 +114,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
134114
surface: impl Into<Partial<Surface>>,
135115
points: [impl Into<Point<2>>; 2],
136116
) {
137-
self.replace_surface(surface.into());
117+
self.surface = surface.into();
138118

139119
for (vertex, point) in self.vertices.each_mut_ext().zip_ext(points) {
140120
let mut surface_form = vertex.1.write();

crates/fj-kernel/src/builder/vertex.rs

+3-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
1-
use fj_math::Point;
2-
31
use crate::partial::{PartialGlobalVertex, PartialSurfaceVertex};
42

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

146
impl SurfaceVertexBuilder for PartialSurfaceVertex {
15-
fn infer_global_position(&mut self) -> Point<3> {
16-
let position_surface = self
17-
.position
18-
.expect("Can't infer global position without surface position");
19-
let surface = self
20-
.surface
21-
.read()
22-
.geometry
23-
.expect("Can't infer global position without surface geometry");
24-
25-
let position_global =
26-
surface.point_from_surface_coords(position_surface);
27-
self.global_form.write().position = Some(position_global);
28-
29-
position_global
30-
}
7+
// No methods are currently defined. This trait serves as a placeholder, to
8+
// make it clear where to add such methods, once necessary.
319
}
3210

3311
/// Builder API for [`PartialGlobalVertex`]

crates/fj-kernel/src/objects/full/vertex.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
use fj_math::Point;
22

3-
use crate::{objects::Surface, storage::Handle};
3+
use crate::storage::Handle;
44

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

1312
impl SurfaceVertex {
1413
/// Construct a new instance of `SurfaceVertex`
1514
pub fn new(
1615
position: impl Into<Point<2>>,
17-
surface: Handle<Surface>,
1816
global_form: Handle<GlobalVertex>,
1917
) -> Self {
2018
let position = position.into();
2119
Self {
2220
position,
23-
surface,
2421
global_form,
2522
}
2623
}
@@ -30,11 +27,6 @@ impl SurfaceVertex {
3027
self.position
3128
}
3229

33-
/// Access the surface that the vertex is defined in
34-
pub fn surface(&self) -> &Handle<Surface> {
35-
&self.surface
36-
}
37-
3830
/// Access the global form of the vertex
3931
pub fn global_form(&self) -> &Handle<GlobalVertex> {
4032
&self.global_form

crates/fj-kernel/src/partial/objects/edge.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use crate::{
88
Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects,
99
Surface, SurfaceVertex,
1010
},
11-
partial::{
12-
FullToPartialCache, Partial, PartialObject, PartialSurfaceVertex,
13-
},
11+
partial::{FullToPartialCache, Partial, PartialObject},
1412
services::Service,
1513
};
1614

@@ -106,11 +104,7 @@ impl Default for PartialHalfEdge {
106104

107105
let curve = Partial::<Curve>::new();
108106
let vertices = array::from_fn(|_| {
109-
let surface_form = Partial::from_partial(PartialSurfaceVertex {
110-
surface: surface.clone(),
111-
..Default::default()
112-
});
113-
107+
let surface_form = Partial::default();
114108
(None, surface_form)
115109
});
116110

crates/fj-kernel/src/partial/objects/vertex.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use fj_math::Point;
22

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

15-
/// The surface that the vertex is defined in
16-
pub surface: Partial<Surface>,
17-
1815
/// The global form of the vertex
1916
pub global_form: Partial<GlobalVertex>,
2017
}
@@ -28,10 +25,6 @@ impl PartialObject for PartialSurfaceVertex {
2825
) -> Self {
2926
Self {
3027
position: Some(surface_vertex.position()),
31-
surface: Partial::from_full(
32-
surface_vertex.surface().clone(),
33-
cache,
34-
),
3528
global_form: Partial::from_full(
3629
surface_vertex.global_form().clone(),
3730
cache,
@@ -43,10 +36,9 @@ impl PartialObject for PartialSurfaceVertex {
4336
let position = self
4437
.position
4538
.expect("Can't build `SurfaceVertex` without position");
46-
let surface = self.surface.build(objects);
4739
let global_form = self.global_form.build(objects);
4840

49-
SurfaceVertex::new(position, surface, global_form)
41+
SurfaceVertex::new(position, global_form)
5042
}
5143
}
5244

0 commit comments

Comments
 (0)