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

Remove Vertex #1526

Merged
merged 28 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1d13d07
Simplify method return value
hannobraun Jan 20, 2023
65a921a
Don't store `Vertex` in `HalfEdge`
hannobraun Jan 20, 2023
4daa74d
Update struct field name
hannobraun Jan 20, 2023
772b449
Inline `Vertex` transform implementation
hannobraun Jan 20, 2023
8260c47
Don't implement partial object traits for vertices
hannobraun Jan 20, 2023
b017466
Refactor
hannobraun Jan 20, 2023
c8dff52
Refactor
hannobraun Jan 20, 2023
ba7d886
Avoid use of `PartialVertex::build`
hannobraun Jan 20, 2023
b2b6353
Inline `PartialVertex::build` into last call site
hannobraun Jan 20, 2023
5e76fbb
Refactor
hannobraun Jan 20, 2023
23bdcb3
Update variable names
hannobraun Jan 20, 2023
e39d2b5
Avoid use of `HalfEdge::vertices`
hannobraun Jan 20, 2023
d3f5657
Don't expect `Vertex` in `HalfEdge::new`
hannobraun Jan 20, 2023
f20867f
Update variable names
hannobraun Jan 20, 2023
a60d005
Update variable names
hannobraun Jan 20, 2023
2777f56
Refactor
hannobraun Jan 20, 2023
97e4a56
Avoid use of `Vertex`
hannobraun Jan 20, 2023
14b4e6c
Avoid use of `Vertex`
hannobraun Jan 20, 2023
c5f88dd
Avoid using `HalfEdge::vertices`
hannobraun Jan 20, 2023
36cef4e
Avoid using `Vertex` in sweep code
hannobraun Jan 20, 2023
8de89cd
Avoid using `Vertex` in validation code
hannobraun Jan 20, 2023
28f5f27
Inline `PartialVertex::from_full` into call site
hannobraun Jan 20, 2023
861b27c
Remove `HalfEdge::vertices`
hannobraun Jan 20, 2023
aae5645
Update variable name
hannobraun Jan 20, 2023
77e7901
Remove unused code
hannobraun Jan 20, 2023
b6be89c
Remove last use of `Vertex`
hannobraun Jan 20, 2023
f2ace07
Remove reference to `Vertex` from doc comment
hannobraun Jan 20, 2023
138ab9a
Remove `Vertex`
hannobraun Jan 20, 2023
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
27 changes: 18 additions & 9 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Intersection between faces and points in 2D

use fj_interop::ext::ArrayExt;
use fj_math::Point;

use crate::{
objects::{Face, HalfEdge, Vertex},
objects::{Face, HalfEdge, SurfaceVertex},
storage::Handle,
};

Expand Down Expand Up @@ -48,13 +49,17 @@ impl Intersect for (&Handle<Face>, &Point<2>) {
));
}
(Some(RaySegmentIntersection::RayStartsOnOnFirstVertex), _) => {
let vertex = half_edge.vertices()[0].clone();
let [vertex, _] = half_edge.boundary().zip_ext(
half_edge.surface_vertices().map(Clone::clone)
);
return Some(
FacePointIntersection::PointIsOnVertex(vertex)
);
}
(Some(RaySegmentIntersection::RayStartsOnSecondVertex), _) => {
let vertex = half_edge.vertices()[1].clone();
let [_, vertex] = half_edge.boundary().zip_ext(
half_edge.surface_vertices().map(Clone::clone)
);
return Some(
FacePointIntersection::PointIsOnVertex(vertex)
);
Expand Down Expand Up @@ -125,11 +130,12 @@ pub enum FacePointIntersection {
PointIsOnEdge(Handle<HalfEdge>),

/// The point is coincident with a vertex
PointIsOnVertex(Vertex),
PointIsOnVertex((Point<1>, Handle<SurfaceVertex>)),
}

#[cfg(test)]
mod tests {
use fj_interop::ext::ArrayExt;
use fj_math::Point;
use pretty_assertions::assert_eq;

Expand Down Expand Up @@ -342,12 +348,15 @@ mod tests {
let vertex = face
.exterior()
.half_edges()
.flat_map(|half_edge| half_edge.vertices())
.find(|vertex| {
vertex.surface_form().position() == Point::from([1., 0.])
.flat_map(|half_edge| {
half_edge
.boundary()
.zip_ext(half_edge.surface_vertices().map(Clone::clone))
})
.unwrap()
.clone();
.find(|(_, surface_vertex)| {
surface_vertex.position() == Point::from([1., 0.])
})
.unwrap();
assert_eq!(
intersection,
Some(FacePointIntersection::PointIsOnVertex(vertex))
Expand Down
18 changes: 11 additions & 7 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fj_math::{Plane, Point, Scalar};
use crate::{
algorithms::intersect::face_point::FacePointIntersection,
geometry::path::GlobalPath,
objects::{Face, HalfEdge, Vertex},
objects::{Face, HalfEdge, SurfaceVertex},
storage::Handle,
};

Expand Down Expand Up @@ -136,11 +136,12 @@ pub enum RayFaceIntersection {
RayHitsEdge(Handle<HalfEdge>),

/// The ray hits a vertex
RayHitsVertex(Vertex),
RayHitsVertex((Point<1>, Handle<SurfaceVertex>)),
}

#[cfg(test)]
mod tests {
use fj_interop::ext::ArrayExt;
use fj_math::Point;

use crate::{
Expand Down Expand Up @@ -287,12 +288,15 @@ mod tests {
let vertex = face
.exterior()
.half_edges()
.flat_map(|half_edge| half_edge.vertices())
.find(|vertex| {
vertex.surface_form().position() == Point::from([-1., -1.])
.flat_map(|half_edge| {
half_edge
.boundary()
.zip_ext(half_edge.surface_vertices().map(Clone::clone))
})
.unwrap()
.clone();
.find(|(_, surface_vertex)| {
surface_vertex.position() == Point::from([-1., -1.])
})
.unwrap();
assert_eq!(
(&ray, &face).intersect(),
Some(RayFaceIntersection::RayHitsVertex(vertex))
Expand Down
6 changes: 5 additions & 1 deletion crates/fj-kernel/src/algorithms/reverse/edge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use fj_interop::ext::ArrayExt;

use crate::{
insert::Insert,
objects::{HalfEdge, Objects},
Expand All @@ -10,7 +12,9 @@ use super::Reverse;
impl Reverse for Handle<HalfEdge> {
fn reverse(self, objects: &mut Service<Objects>) -> Self {
let vertices = {
let [a, b] = self.vertices().clone();
let [a, b] = self
.boundary()
.zip_ext(self.surface_vertices().map(Clone::clone));
[b, a]
};

Expand Down
44 changes: 22 additions & 22 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
insert::Insert,
objects::{
Curve, Cycle, Face, GlobalEdge, HalfEdge, Objects, SurfaceVertex,
Vertex,
},
partial::{Partial, PartialFace, PartialObject},
services::Service,
Expand Down Expand Up @@ -57,39 +56,43 @@ impl Sweep for (Handle<HalfEdge>, Color) {
.insert(objects)
};

let vertices = {
let boundary = {
let points_surface = points_curve_and_surface
.map(|(_, point_surface)| point_surface);

edge.vertices()
.each_ref_ext()
edge.boundary()
.zip_ext(edge.surface_vertices())
.into_iter_fixed()
.zip(points_surface)
.collect::<[_; 2]>()
.map(|(vertex, point_surface)| {
.map(|((point, surface_vertex), point_surface)| {
let surface_vertex = SurfaceVertex::new(
point_surface,
surface.clone(),
vertex.surface_form().global_form().clone(),
surface_vertex.global_form().clone(),
)
.insert(objects);

Vertex::new(vertex.position(), surface_vertex)
(point, surface_vertex)
})
};

HalfEdge::new(curve, vertices, edge.global_form().clone())
HalfEdge::new(curve, boundary, edge.global_form().clone())
.insert(objects)
};

let side_edges = bottom_edge.vertices().clone().map(|vertex| {
(vertex, surface.clone()).sweep_with_cache(path, cache, objects)
});
let side_edges = bottom_edge
.boundary()
.zip_ext(bottom_edge.surface_vertices())
.map(|(point, surface_vertex)| {
(point, surface_vertex.clone(), surface.clone())
.sweep_with_cache(path, cache, objects)
});

let top_edge = {
let surface_vertices = side_edges.clone().map(|edge| {
let [_, vertex] = edge.vertices();
vertex.surface_form().clone()
let [_, surface_vertex] = edge.surface_vertices();
surface_vertex.clone()
});

let points_curve_and_surface = bottom_edge
Expand Down Expand Up @@ -122,14 +125,13 @@ impl Sweep for (Handle<HalfEdge>, Color) {
)
.insert(objects);

let vertices = bottom_edge
let boundary = bottom_edge
.boundary()
.into_iter_fixed()
.zip(surface_vertices)
.collect::<[_; 2]>()
.map(|(point, surface_form)| Vertex::new(point, surface_form));
.collect::<[_; 2]>();

HalfEdge::new(curve, vertices, global).insert(objects)
HalfEdge::new(curve, boundary, global).insert(objects)
};

let cycle = {
Expand All @@ -144,15 +146,13 @@ impl Sweep for (Handle<HalfEdge>, Color) {
while i < edges.len() {
let j = (i + 1) % edges.len();

let [_, prev_last] = edges[i].vertices();
let [next_first, _] = edges[j].vertices();
let [_, prev_last] = edges[i].surface_vertices();
let [next_first, _] = edges[j].surface_vertices();

// Need to compare surface forms here, as the global forms might
// be coincident when sweeping circles, despite the vertices
// being different!
if prev_last.surface_form().id()
!= next_first.surface_form().id()
{
if prev_last.id() != next_first.id() {
edges[j] = edges[j].clone().reverse(objects);
}

Expand Down
49 changes: 25 additions & 24 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use crate::{
insert::Insert,
objects::{
Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects,
Surface, SurfaceVertex, Vertex,
Surface, SurfaceVertex,
},
services::Service,
storage::Handle,
};

use super::{Sweep, SweepCache};

impl Sweep for (Vertex, Handle<Surface>) {
impl Sweep for (Point<1>, Handle<SurfaceVertex>, Handle<Surface>) {
type Swept = Handle<HalfEdge>;

fn sweep_with_cache(
Expand All @@ -22,7 +22,7 @@ impl Sweep for (Vertex, Handle<Surface>) {
cache: &mut SweepCache,
objects: &mut Service<Objects>,
) -> Self::Swept {
let (vertex, surface) = self;
let (point, surface_vertex, surface) = self;
let path = path.into();

// The result of sweeping a `Vertex` is an `Edge`. Seems
Expand Down Expand Up @@ -60,8 +60,7 @@ impl Sweep for (Vertex, Handle<Surface>) {
// With that out of the way, let's start by creating the `GlobalEdge`,
// as that is the most straight-forward part of this operations, and
// we're going to need it soon anyway.
let (edge_global, vertices_global) = vertex
.surface_form()
let (edge_global, vertices_global) = surface_vertex
.global_form()
.clone()
.sweep_with_cache(path, cache, objects);
Expand All @@ -81,8 +80,8 @@ impl Sweep for (Vertex, Handle<Surface>) {
// straight-forward: The start of the edge is at zero, the end is at
// one.
let points_surface = [
Point::from([vertex.position().t, Scalar::ZERO]),
Point::from([vertex.position().t, Scalar::ONE]),
Point::from([point.t, Scalar::ZERO]),
Point::from([point.t, Scalar::ONE]),
];

// Armed with those coordinates, creating the `Curve` of the output
Expand All @@ -99,20 +98,20 @@ impl Sweep for (Vertex, Handle<Surface>) {
let [_, global_form] = vertices_global;

[
vertex.surface_form().clone(),
surface_vertex,
SurfaceVertex::new(position, surface, global_form)
.insert(objects),
]
};

// And now the vertices. Again, nothing wild here.
let vertices = vertices_surface.map(|surface_form| {
Vertex::new([surface_form.position().v], surface_form)
let boundary = vertices_surface.map(|surface_vertex| {
(Point::from([surface_vertex.position().v]), surface_vertex)
});

// And finally, creating the output `Edge` is just a matter of
// assembling the pieces we've already created.
HalfEdge::new(curve, vertices, edge_global).insert(objects)
HalfEdge::new(curve, boundary, edge_global).insert(objects)
}
}

Expand Down Expand Up @@ -158,7 +157,7 @@ mod tests {
insert::Insert,
partial::{
Partial, PartialCurve, PartialGlobalVertex, PartialHalfEdge,
PartialObject, PartialSurfaceVertex, PartialVertex,
PartialObject, PartialSurfaceVertex,
},
services::Services,
};
Expand All @@ -168,24 +167,26 @@ mod tests {
let mut services = Services::new();

let surface = services.objects.surfaces.xz_plane();
let mut curve = PartialCurve {
surface: Partial::from(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();
let vertex = PartialVertex {
position: Some([0.].into()),
surface_form: Partial::from_partial(PartialSurfaceVertex {
let (position, surface_vertex) = {
let mut curve = PartialCurve {
surface: Partial::from(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();

let surface_form = Partial::from_partial(PartialSurfaceVertex {
position: Some(Point::from([0., 0.])),
surface: Partial::from(surface.clone()),
global_form: Partial::from_partial(PartialGlobalVertex {
position: Some(Point::from([0., 0., 0.])),
}),
}),
}
.build(&mut services.objects);
})
.build(&mut services.objects);

(Point::from([0.]), surface_form)
};

let half_edge = (vertex, surface.clone())
let half_edge = (position, surface_vertex, surface.clone())
.sweep([0., 0., 1.], &mut services.objects);

let expected_half_edge = {
Expand Down
14 changes: 10 additions & 4 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use fj_interop::ext::ArrayExt;
use fj_math::Transform;

use crate::{
Expand All @@ -18,15 +19,20 @@ impl TransformObject for HalfEdge {
.curve()
.clone()
.transform_with_cache(transform, objects, cache);
let vertices = self.vertices().clone().map(|vertex| {
vertex.transform_with_cache(transform, objects, cache)
});
let boundary = self.boundary().zip_ext(self.surface_vertices()).map(
|(point, surface_vertex)| {
let surface_vertex = surface_vertex
.clone()
.transform_with_cache(transform, objects, cache);
(point, surface_vertex)
},
);
let global_form = self
.global_form()
.clone()
.transform_with_cache(transform, objects, cache);

Self::new(curve, vertices, global_form)
Self::new(curve, boundary, global_form)
}
}

Expand Down
Loading