Skip to content

Commit

Permalink
Merge pull request #2059 from hannobraun/edge
Browse files Browse the repository at this point in the history
Rename `Edge` to `HalfEdge`
  • Loading branch information
hannobraun authored Oct 18, 2023
2 parents 30e67a5 + 0c39e20 commit 2491b35
Show file tree
Hide file tree
Showing 40 changed files with 314 additions and 261 deletions.
2 changes: 1 addition & 1 deletion crates/fj-core/src/algorithms/approx/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Approx for (&Cycle, &Surface) {
let tolerance = tolerance.into();

let edges = cycle
.edges()
.half_edges()
.iter()
.map(|edge| {
(edge.deref(), surface).approx_with_cache(tolerance, cache)
Expand Down
18 changes: 9 additions & 9 deletions crates/fj-core/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use fj_math::Point;

use crate::{
geometry::{CurveBoundary, GlobalPath, SurfacePath},
objects::{Curve, Edge, Surface, Vertex},
objects::{Curve, HalfEdge, Surface, Vertex},
storage::{Handle, HandleWrapper},
};

Expand All @@ -22,7 +22,7 @@ use super::{
Approx, ApproxPoint, Tolerance,
};

impl Approx for (&Edge, &Surface) {
impl Approx for (&HalfEdge, &Surface) {
type Approximation = EdgeApprox;
type Cache = EdgeApproxCache;

Expand Down Expand Up @@ -109,7 +109,7 @@ impl Approx for (&Edge, &Surface) {
}
}

/// An approximation of an [`Edge`]
/// An approximation of a [`HalfEdge`]
#[derive(Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct EdgeApprox {
/// The point that approximates the first vertex of the edge
Expand Down Expand Up @@ -263,8 +263,8 @@ mod tests {
use crate::{
algorithms::approx::{Approx, ApproxPoint},
geometry::{CurveBoundary, GlobalPath, SurfaceGeometry},
objects::{Edge, Surface},
operations::BuildEdge,
objects::{HalfEdge, Surface},
operations::BuildHalfEdge,
services::Services,
};

Expand All @@ -274,7 +274,7 @@ mod tests {

let surface = services.objects.surfaces.xz_plane();
let edge =
Edge::line_segment([[1., 1.], [2., 1.]], None, &mut services);
HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services);

let tolerance = 1.;
let approx = (&edge, surface.deref()).approx(tolerance);
Expand All @@ -291,7 +291,7 @@ mod tests {
v: [0., 0., 1.].into(),
});
let edge =
Edge::line_segment([[1., 1.], [2., 1.]], None, &mut services);
HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services);

let tolerance = 1.;
let approx = (&edge, &surface).approx(tolerance);
Expand All @@ -310,7 +310,7 @@ mod tests {
u: path,
v: [0., 0., 1.].into(),
});
let edge = Edge::line_segment(
let edge = HalfEdge::line_segment(
[[0., 1.], [TAU, 1.]],
Some(boundary.inner),
&mut services,
Expand Down Expand Up @@ -338,7 +338,7 @@ mod tests {
let mut services = Services::new();

let surface = services.objects.surfaces.xz_plane();
let edge = Edge::circle([0., 0.], 1., &mut services);
let edge = HalfEdge::circle([0., 0.], 1., &mut services);

let tolerance = 1.;
let approx = (&edge, surface.deref()).approx(tolerance);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/algorithms/bounding_volume/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ impl super::BoundingVolume<2> for Cycle {
fn aabb(&self) -> Option<Aabb<2>> {
let mut aabb: Option<Aabb<2>> = None;

for edge in self.edges() {
for edge in self.half_edges() {
let new_aabb = edge.aabb().expect("`Edge` can always compute AABB");
aabb = Some(aabb.map_or(new_aabb, |aabb| aabb.merged(&new_aabb)));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/algorithms/bounding_volume/edge.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use fj_math::{Aabb, Vector};

use crate::{geometry::SurfacePath, objects::Edge};
use crate::{geometry::SurfacePath, objects::HalfEdge};

impl super::BoundingVolume<2> for Edge {
impl super::BoundingVolume<2> for HalfEdge {
fn aabb(&self) -> Option<Aabb<2>> {
match self.path() {
SurfacePath::Circle(circle) => {
Expand Down
28 changes: 17 additions & 11 deletions crates/fj-core/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use fj_math::{Point, Segment};

use crate::{geometry::SurfacePath, objects::Edge};
use crate::{geometry::SurfacePath, objects::HalfEdge};

use super::LineSegmentIntersection;

/// The intersection between a curve and an [`Edge`]
/// The intersection between a curve and a [`HalfEdge`]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum CurveEdgeIntersection {
/// The curve and edge intersect at a point
Expand All @@ -26,8 +26,8 @@ impl CurveEdgeIntersection {
/// # Panics
///
/// Currently, only intersections between lines and line segments can be
/// computed. Panics, if a different type of curve or [`Edge`] is passed.
pub fn compute(path: &SurfacePath, edge: &Edge) -> Option<Self> {
/// computed. Panics, if a different type of curve or [`HalfEdge`] is passed.
pub fn compute(path: &SurfacePath, edge: &HalfEdge) -> Option<Self> {
let path_as_line = match path {
SurfacePath::Line(line) => line,
_ => todo!("Curve-edge intersection only supports lines"),
Expand Down Expand Up @@ -72,7 +72,7 @@ mod tests {
use fj_math::Point;

use crate::{
geometry::SurfacePath, objects::Edge, operations::BuildEdge,
geometry::SurfacePath, objects::HalfEdge, operations::BuildHalfEdge,
services::Services,
};

Expand All @@ -84,7 +84,7 @@ mod tests {

let path = SurfacePath::u_axis();
let edge =
Edge::line_segment([[1., -1.], [1., 1.]], None, &mut services);
HalfEdge::line_segment([[1., -1.], [1., 1.]], None, &mut services);

let intersection = CurveEdgeIntersection::compute(&path, &edge);

Expand All @@ -101,8 +101,11 @@ mod tests {
let mut services = Services::new();

let path = SurfacePath::u_axis();
let edge =
Edge::line_segment([[-1., -1.], [-1., 1.]], None, &mut services);
let edge = HalfEdge::line_segment(
[[-1., -1.], [-1., 1.]],
None,
&mut services,
);

let intersection = CurveEdgeIntersection::compute(&path, &edge);

Expand All @@ -119,8 +122,11 @@ mod tests {
let mut services = Services::new();

let path = SurfacePath::u_axis();
let edge =
Edge::line_segment([[-1., -1.], [1., -1.]], None, &mut services);
let edge = HalfEdge::line_segment(
[[-1., -1.], [1., -1.]],
None,
&mut services,
);

let intersection = CurveEdgeIntersection::compute(&path, &edge);

Expand All @@ -133,7 +139,7 @@ mod tests {

let path = SurfacePath::u_axis();
let edge =
Edge::line_segment([[-1., 0.], [1., 0.]], None, &mut services);
HalfEdge::line_segment([[-1., 0.], [1., 0.]], None, &mut services);

let intersection = CurveEdgeIntersection::compute(&path, &edge);

Expand Down
5 changes: 4 additions & 1 deletion crates/fj-core/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ impl CurveFaceIntersection {

/// Compute the intersection
pub fn compute(path: &SurfacePath, face: &Face) -> Self {
let edges = face.region().all_cycles().flat_map(|cycle| cycle.edges());
let edges = face
.region()
.all_cycles()
.flat_map(|cycle| cycle.half_edges());

let mut intersections = Vec::new();

Expand Down
12 changes: 6 additions & 6 deletions crates/fj-core/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use fj_math::Point;

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

Expand All @@ -28,12 +28,12 @@ impl Intersect for (&Face, &Point<2>) {
// as long as we initialize the `previous_hit` variable with the
// result of the last segment.
let mut previous_hit = cycle
.edges()
.half_edges()
.iter()
.last()
.and_then(|edge| (&ray, edge).intersect());

for (edge, next_edge) in cycle.edges().pairs() {
for (edge, next_edge) in cycle.half_edges().pairs() {
let hit = (&ray, edge).intersect();

let count_hit = match (hit, previous_hit) {
Expand Down Expand Up @@ -122,7 +122,7 @@ pub enum FacePointIntersection {
PointIsInsideFace,

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

/// The point is coincident with a vertex
PointIsOnVertex(Point<2>),
Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {
let edge = face
.region()
.exterior()
.edges()
.half_edges()
.iter()
.find(|edge| edge.start_position() == Point::from([0., 0.]))
.unwrap();
Expand Down Expand Up @@ -371,7 +371,7 @@ mod tests {
let vertex = face
.region()
.exterior()
.edges()
.half_edges()
.iter()
.find(|edge| edge.start_position() == Point::from([1., 0.]))
.map(|edge| edge.start_position())
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/algorithms/intersect/ray_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use fj_math::Segment;
use crate::{
algorithms::intersect::{HorizontalRayToTheRight, Intersect},
geometry::SurfacePath,
objects::Edge,
objects::HalfEdge,
storage::Handle,
};

use super::ray_segment::RaySegmentIntersection;

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

fn intersect(self) -> Option<Self::Intersection> {
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/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::GlobalPath,
objects::{Edge, Face},
objects::{Face, HalfEdge},
storage::Handle,
};

Expand Down Expand Up @@ -134,7 +134,7 @@ pub enum RayFaceIntersection {
RayHitsFaceAndAreParallel,

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

/// The ray hits a vertex
RayHitsVertex(Point<2>),
Expand Down Expand Up @@ -262,7 +262,7 @@ mod tests {
let edge = face
.region()
.exterior()
.edges()
.half_edges()
.iter()
.find(|edge| edge.start_position() == Point::from([-1., 1.]))
.unwrap();
Expand Down Expand Up @@ -298,7 +298,7 @@ mod tests {
let vertex = face
.region()
.exterior()
.edges()
.half_edges()
.iter()
.find(|edge| edge.start_position() == Point::from([-1., -1.]))
.map(|edge| edge.start_position())
Expand Down
15 changes: 8 additions & 7 deletions crates/fj-core/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use fj_interop::{ext::ArrayExt, mesh::Color};
use fj_math::{Point, Scalar, Vector};

use crate::{
objects::{Cycle, Edge, Face, Region, Surface, Vertex},
operations::{BuildEdge, Insert, UpdateCycle, UpdateEdge},
objects::{Cycle, Face, HalfEdge, Region, Surface, Vertex},
operations::{BuildHalfEdge, Insert, UpdateCycle, UpdateHalfEdge},
services::Services,
storage::Handle,
};

use super::{Sweep, SweepCache};

impl Sweep for (&Edge, &Handle<Vertex>, &Surface, Option<Color>) {
type Swept = (Handle<Face>, Handle<Edge>);
impl Sweep for (&HalfEdge, &Handle<Vertex>, &Surface, Option<Color>) {
type Swept = (Handle<Face>, Handle<HalfEdge>);

fn sweep_with_cache(
self,
Expand Down Expand Up @@ -81,7 +81,7 @@ impl Sweep for (&Edge, &Handle<Vertex>, &Surface, Option<Color>) {
.zip_ext(curves)
.map(|((((boundary, start), end), start_vertex), curve)| {
let edge = {
let edge = Edge::line_segment(
let edge = HalfEdge::line_segment(
[start, end],
Some(boundary),
services,
Expand All @@ -97,8 +97,9 @@ impl Sweep for (&Edge, &Handle<Vertex>, &Surface, Option<Color>) {
edge.insert(services)
};

exterior =
Some(exterior.take().unwrap().add_edges([edge.clone()]));
exterior = Some(
exterior.take().unwrap().add_half_edges([edge.clone()]),
);

edge
});
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Sweep for Handle<Face> {
let cycle = cycle.reverse(services);

let mut top_edges = Vec::new();
for (edge, next) in cycle.edges().pairs() {
for (edge, next) in cycle.half_edges().pairs() {
let (face, top_edge) = (
edge.deref(),
next.start_vertex(),
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/algorithms/transform/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl TransformObject for Cycle {
services: &mut Services,
cache: &mut TransformCache,
) -> Self {
let edges = self.edges().iter().map(|edge| {
let edges = self.half_edges().iter().map(|edge| {
edge.clone()
.transform_with_cache(transform, services, cache)
});
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use fj_math::Transform;

use crate::{objects::Edge, services::Services};
use crate::{objects::HalfEdge, services::Services};

use super::{TransformCache, TransformObject};

impl TransformObject for Edge {
impl TransformObject for HalfEdge {
fn transform_with_cache(
self,
transform: &Transform,
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/src/objects/kinds/curve.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// A curve
///
/// `Curve` represents a curve in space, but holds no data to define that curve.
/// It is referenced by [`Edge`], which defines the curve in the coordinates of
/// its surface.
/// It is referenced by [`HalfEdge`], which defines the curve in the coordinates
/// of its surface.
///
/// `Curve` exists to allow identifying which [`Edge`]s are supposed to be
/// `Curve` exists to allow identifying which [`HalfEdge`]s are supposed to be
/// coincident in global space.
///
/// # Equality
Expand All @@ -20,7 +20,7 @@
/// `Eq`/`Ord`/..., you can use `HandleWrapper<Curve>` to do that. It will use
/// `Handle::id` to provide those `Eq`/`Ord`/... implementations.
///
/// [`Edge`]: crate::objects::Edge
/// [`HalfEdge`]: crate::objects::HalfEdge
#[derive(Clone, Debug, Default, Hash)]
pub struct Curve {}

Expand Down
Loading

0 comments on commit 2491b35

Please sign in to comment.