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

Integrate HalfEdge into centralized object storage #1248

Merged
merged 3 commits into from
Oct 20, 2022
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
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mod tests {
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
let half_edge = HalfEdge::partial()
let half_edge = Handle::<HalfEdge>::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[1., -1.], [1., 1.]])
.build(&objects);
Expand All @@ -115,7 +115,7 @@ mod tests {
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
let half_edge = HalfEdge::partial()
let half_edge = Handle::<HalfEdge>::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[-1., -1.], [-1., 1.]])
.build(&objects);
Expand All @@ -139,7 +139,7 @@ mod tests {
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
let half_edge = HalfEdge::partial()
let half_edge = Handle::<HalfEdge>::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[-1., -1.], [1., -1.]])
.build(&objects);
Expand All @@ -158,7 +158,7 @@ mod tests {
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
let half_edge = HalfEdge::partial()
let half_edge = Handle::<HalfEdge>::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[-1., 0.], [1., 0.]])
.build(&objects);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub enum FacePointIntersection {
PointIsInsideFace,

/// The point is coincident with an edge
PointIsOnEdge(HalfEdge),
PointIsOnEdge(Handle<HalfEdge>),

/// The point is coincident with a vertex
PointIsOnVertex(Handle<Vertex>),
Expand Down
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/algorithms/intersect/ray_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use crate::{
algorithms::intersect::{HorizontalRayToTheRight, Intersect},
objects::HalfEdge,
path::SurfacePath,
storage::Handle,
};

use super::ray_segment::RaySegmentIntersection;

impl Intersect for (&HorizontalRayToTheRight<2>, &HalfEdge) {
impl Intersect for (&HorizontalRayToTheRight<2>, &Handle<HalfEdge>) {
type Intersection = RaySegmentIntersection;

fn intersect(self) -> Option<Self::Intersection> {
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub enum RayFaceIntersection {
RayHitsFaceAndAreParallel,

/// The ray hits an edge
RayHitsEdge(HalfEdge),
RayHitsEdge(Handle<HalfEdge>),

/// The ray hits a vertex
RayHitsVertex(Handle<Vertex>),
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/reverse/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::objects::Cycle;
use crate::objects::{Cycle, Objects};

use super::Reverse;

impl Reverse for Cycle {
fn reverse(self) -> Self {
fn reverse(self, objects: &Objects) -> Self {
let surface = self.surface().clone();

let mut edges = self
.into_half_edges()
.map(|edge| edge.reverse())
.map(|edge| edge.reverse(objects))
.collect::<Vec<_>>();

edges.reverse();
Expand Down
11 changes: 7 additions & 4 deletions crates/fj-kernel/src/algorithms/reverse/edge.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use crate::objects::HalfEdge;
use crate::{
objects::{HalfEdge, Objects},
storage::Handle,
};

use super::Reverse;

impl Reverse for HalfEdge {
fn reverse(self) -> Self {
impl Reverse for Handle<HalfEdge> {
fn reverse(self, objects: &Objects) -> Self {
let vertices = {
let [a, b] = self.vertices().clone();
[b, a]
};

HalfEdge::new(vertices, self.global_form().clone())
HalfEdge::new(vertices, self.global_form().clone(), objects)
}
}
9 changes: 5 additions & 4 deletions crates/fj-kernel/src/algorithms/reverse/face.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::objects::Face;
use crate::objects::{Face, Objects};

use super::Reverse;

impl Reverse for Face {
fn reverse(self) -> Self {
let exterior = self.exterior().clone().reverse();
let interiors = self.interiors().map(|cycle| cycle.clone().reverse());
fn reverse(self, objects: &Objects) -> Self {
let exterior = self.exterior().clone().reverse(objects);
let interiors =
self.interiors().map(|cycle| cycle.clone().reverse(objects));

Face::from_exterior(exterior)
.with_interiors(interiors)
Expand Down
4 changes: 3 additions & 1 deletion crates/fj-kernel/src/algorithms/reverse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Reverse the direction/orientation of objects

use crate::objects::Objects;

mod cycle;
mod edge;
mod face;
Expand All @@ -8,5 +10,5 @@ mod face;
pub trait Reverse {
/// Reverse the direction/orientation of the object
#[must_use]
fn reverse(self) -> Self;
fn reverse(self, objects: &Objects) -> Self;
}
23 changes: 12 additions & 11 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ use crate::{
Vertex,
},
path::SurfacePath,
storage::Handle,
};

use super::{Sweep, SweepCache};

impl Sweep for (HalfEdge, Color) {
impl Sweep for (Handle<HalfEdge>, Color) {
type Swept = Face;

fn sweep_with_cache(
Expand Down Expand Up @@ -82,7 +83,7 @@ impl Sweep for (HalfEdge, Color) {
})
};

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

let side_edges = bottom_edge.vertices().clone().map(|vertex| {
Expand Down Expand Up @@ -145,7 +146,7 @@ impl Sweep for (HalfEdge, Color) {
})
};

HalfEdge::new(vertices, global)
HalfEdge::new(vertices, global, objects)
};

let cycle = {
Expand All @@ -169,7 +170,7 @@ impl Sweep for (HalfEdge, Color) {
if prev_last.surface_form().id()
!= next_first.surface_form().id()
{
edges[j] = edges[j].clone().reverse();
edges[j] = edges[j].clone().reverse(objects);
}

i += 1;
Expand Down Expand Up @@ -198,7 +199,7 @@ mod tests {
fn sweep() {
let objects = Objects::new();

let half_edge = HalfEdge::partial()
let half_edge = Handle::<HalfEdge>::partial()
.with_surface(Some(objects.surfaces.xy_plane()))
.as_line_segment_from_points([[0., 0.], [1., 0.]])
.build(&objects);
Expand All @@ -208,11 +209,11 @@ mod tests {
let expected_face = {
let surface = objects.surfaces.xz_plane();

let bottom = HalfEdge::partial()
let bottom = Handle::<HalfEdge>::partial()
.with_surface(Some(surface.clone()))
.as_line_segment_from_points([[0., 0.], [1., 0.]])
.build(&objects);
let side_up = HalfEdge::partial()
let side_up = Handle::<HalfEdge>::partial()
.with_surface(Some(surface.clone()))
.with_back_vertex(Some(
Handle::<Vertex>::partial().with_surface_form(Some(
Expand All @@ -227,7 +228,7 @@ mod tests {
))
.as_line_segment()
.build(&objects);
let top = HalfEdge::partial()
let top = Handle::<HalfEdge>::partial()
.with_surface(Some(surface.clone()))
.with_back_vertex(Some(
Handle::<Vertex>::partial().with_surface_form(Some(
Expand All @@ -242,8 +243,8 @@ mod tests {
))
.as_line_segment()
.build(&objects)
.reverse();
let side_down = HalfEdge::partial()
.reverse(&objects);
let side_down = Handle::<HalfEdge>::partial()
.with_surface(Some(surface.clone()))
.with_back_vertex(Some(
Handle::<Vertex>::partial().with_surface_form(Some(
Expand All @@ -257,7 +258,7 @@ mod tests {
))
.as_line_segment()
.build(&objects)
.reverse();
.reverse(&objects);

let cycle = Cycle::new(surface, [bottom, side_up, top, side_down]);

Expand Down
17 changes: 9 additions & 8 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Sweep for Face {
if is_negative_sweep {
self.clone()
} else {
self.clone().reverse()
self.clone().reverse(objects)
}
};
faces.push(bottom_face);
Expand All @@ -49,7 +49,7 @@ impl Sweep for Face {
let mut face = self.clone().translate(path, objects);

if is_negative_sweep {
face = face.reverse();
face = face.reverse(objects);
};

face
Expand All @@ -60,7 +60,7 @@ impl Sweep for Face {
for cycle in self.all_cycles() {
for half_edge in cycle.half_edges() {
let half_edge = if is_negative_sweep {
half_edge.clone().reverse()
half_edge.clone().reverse(objects)
} else {
half_edge.clone()
};
Expand All @@ -84,6 +84,7 @@ mod tests {
algorithms::{reverse::Reverse, transform::TransformObject},
objects::{Face, HalfEdge, Objects, Sketch},
partial::HasPartial,
storage::Handle,
};

use super::Sweep;
Expand All @@ -105,7 +106,7 @@ mod tests {
let bottom = Face::builder(&objects, surface.clone())
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.reverse();
.reverse(&objects);
let top = Face::builder(&objects, surface.translate(UP, &objects))
.with_exterior_polygon_from_points(TRIANGLE)
.build();
Expand All @@ -120,7 +121,7 @@ mod tests {
// https://doc.rust-lang.org/std/primitive.slice.html#method.array_windows
let [a, b] = [window[0], window[1]];

let half_edge = HalfEdge::partial()
let half_edge = Handle::<HalfEdge>::partial()
.with_surface(Some(objects.surfaces.xy_plane()))
.as_line_segment_from_points([a, b])
.build(&objects);
Expand All @@ -143,7 +144,7 @@ mod tests {
Face::builder(&objects, surface.clone().translate(DOWN, &objects))
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.reverse();
.reverse(&objects);
let top = Face::builder(&objects, surface)
.with_exterior_polygon_from_points(TRIANGLE)
.build();
Expand All @@ -158,11 +159,11 @@ mod tests {
// https://doc.rust-lang.org/std/primitive.slice.html#method.array_windows
let [a, b] = [window[0], window[1]];

let half_edge = HalfEdge::partial()
let half_edge = Handle::<HalfEdge>::partial()
.with_surface(Some(objects.surfaces.xy_plane()))
.as_line_segment_from_points([a, b])
.build(&objects)
.reverse();
.reverse(&objects);
(half_edge, Color::default()).sweep(DOWN, &objects)
});

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
use super::{Sweep, SweepCache};

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

fn sweep_with_cache(
self,
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Sweep for (Handle<Vertex>, Handle<Surface>) {

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

Expand Down Expand Up @@ -181,7 +181,7 @@ mod tests {

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

let expected_half_edge = HalfEdge::partial()
let expected_half_edge = Handle::<HalfEdge>::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[0., 0.], [0., 1.]])
.build(&objects);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ mod tests {
let global_edge = Handle::<GlobalEdge>::partial()
.from_curve_and_vertices(&curve, &vertices)
.build(&objects);
let half_edge = HalfEdge::new(vertices, global_edge);
let half_edge = HalfEdge::new(vertices, global_edge, &objects);

let result =
half_edge.clone().validate_with_config(&ValidationConfig {
Expand Down
10 changes: 5 additions & 5 deletions crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a> ShellBuilder<'a> {
.half_edges()
.zip(&surfaces)
.map(|(half_edge, surface)| {
HalfEdge::partial()
Handle::<HalfEdge>::partial()
.with_surface(Some(surface.clone()))
.with_global_form(Some(half_edge.global_form().clone()))
.as_line_segment_from_points([[Z, Z], [edge_length, Z]])
Expand All @@ -89,7 +89,7 @@ impl<'a> ShellBuilder<'a> {
.with_position(Some(from.position() + [Z, edge_length]))
.with_surface(Some(surface.clone()));

HalfEdge::partial()
Handle::<HalfEdge>::partial()
.with_vertices(Some([
Handle::<Vertex>::partial()
.with_surface_form(Some(from)),
Expand Down Expand Up @@ -127,7 +127,7 @@ impl<'a> ShellBuilder<'a> {
side_up_prev.curve().global_form().clone(),
));

HalfEdge::partial()
Handle::<HalfEdge>::partial()
.with_curve(Some(curve))
.with_vertices(Some([
Handle::<Vertex>::partial()
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<'a> ShellBuilder<'a> {
let to =
Handle::<Vertex>::partial().with_surface_form(Some(to));

HalfEdge::partial()
Handle::<HalfEdge>::partial()
.with_vertices(Some([from, to]))
.as_line_segment()
.build(self.objects)
Expand Down Expand Up @@ -243,7 +243,7 @@ impl<'a> ShellBuilder<'a> {
});

edges.push(
HalfEdge::partial()
Handle::<HalfEdge>::partial()
.with_vertices(Some(vertices))
.with_global_form(Some(edge.global_form().clone()))
.as_line_segment()
Expand Down
Loading