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

Rename Edge to HalfEdge #1064

Merged
merged 38 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2f0a051
Remove redundant information from doc comment
hannobraun Sep 8, 2022
9111748
Remove obsolete implementation note
hannobraun Sep 8, 2022
92de5aa
Rename `Edge` to `HalfEdge`
hannobraun Sep 8, 2022
864d178
Update argument name
hannobraun Sep 8, 2022
d5d7021
Update variable names
hannobraun Sep 8, 2022
433e7c3
Restore alphabetic order of trait implementations
hannobraun Sep 8, 2022
40af85b
Update variable name
hannobraun Sep 8, 2022
4bc4041
Update variable name
hannobraun Sep 8, 2022
57a82ad
Update struct name
hannobraun Sep 8, 2022
16ab99f
Update trait method name
hannobraun Sep 8, 2022
b68e2cc
Update doc comment
hannobraun Sep 8, 2022
c92b4ca
Restore alphabetic ordering of trait methods
hannobraun Sep 8, 2022
258fc0e
Restore alphabetic ordering of trait impls
hannobraun Sep 8, 2022
4db8443
Update test name
hannobraun Sep 8, 2022
c9a481f
Restore alphabetic ordering of tests
hannobraun Sep 8, 2022
14bb370
Restore alphabetic ordering of test assertions
hannobraun Sep 8, 2022
21aa19e
Update struct field name
hannobraun Sep 8, 2022
13e1217
Update variable name
hannobraun Sep 8, 2022
3d8c999
Update argument name
hannobraun Sep 8, 2022
e740f13
Update variable name
hannobraun Sep 8, 2022
419b40b
Update method name
hannobraun Sep 8, 2022
2a71754
Update variable name
hannobraun Sep 8, 2022
226e830
Update variable name
hannobraun Sep 8, 2022
e636eea
Update struct field name
hannobraun Sep 8, 2022
b3c7019
Simplify variable name
hannobraun Sep 8, 2022
6a47847
Update struct name
hannobraun Sep 8, 2022
4784e46
Update method name
hannobraun Sep 8, 2022
1e520a0
Update doc comments
hannobraun Sep 8, 2022
4119331
Update variable name
hannobraun Sep 8, 2022
82ff01c
Simplify code
hannobraun Sep 8, 2022
e8d6519
Update variable name
hannobraun Sep 8, 2022
54ea129
Update variable name
hannobraun Sep 8, 2022
44fa9dc
Update variable name
hannobraun Sep 8, 2022
00b9907
Update argument name
hannobraun Sep 8, 2022
ce22d23
Update variable name
hannobraun Sep 8, 2022
546c508
Update variable name
hannobraun Sep 8, 2022
15cb961
Update doc comments
hannobraun Sep 8, 2022
9941078
Update variable name
hannobraun Sep 8, 2022
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
15 changes: 9 additions & 6 deletions crates/fj-kernel/src/algorithms/approx/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,34 @@ use fj_math::Segment;

use crate::objects::Cycle;

use super::{edge::EdgeApprox, Approx, ApproxPoint, Tolerance};
use super::{edge::HalfEdgeApprox, Approx, ApproxPoint, Tolerance};

impl Approx for &Cycle {
type Approximation = CycleApprox;

fn approx(self, tolerance: Tolerance) -> Self::Approximation {
let edges = self.edges().map(|edge| edge.approx(tolerance)).collect();
CycleApprox { edges }
let half_edges = self
.half_edges()
.map(|half_edge| half_edge.approx(tolerance))
.collect();
CycleApprox { half_edges }
}
}

/// An approximation of a [`Cycle`]
#[derive(Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct CycleApprox {
/// The approximated edges that make up the approximated cycle
pub edges: Vec<EdgeApprox>,
pub half_edges: Vec<HalfEdgeApprox>,
}

impl CycleApprox {
/// Compute the points that approximate the cycle
pub fn points(&self) -> Vec<ApproxPoint<2>> {
let mut points = Vec::new();

for edge_approx in &self.edges {
points.extend(edge_approx.points());
for approx in &self.half_edges {
points.extend(approx.points());
}

if let Some(point) = points.first() {
Expand Down
14 changes: 7 additions & 7 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
//! approximations are usually used to build cycle approximations, and this way,
//! the caller doesn't have to call with duplicate vertices.

use crate::objects::Edge;
use crate::objects::HalfEdge;

use super::{
curve::{CurveApprox, RangeOnCurve},
Approx, ApproxPoint,
};

impl Approx for &Edge {
type Approximation = EdgeApprox;
impl Approx for &HalfEdge {
type Approximation = HalfEdgeApprox;

fn approx(self, tolerance: super::Tolerance) -> Self::Approximation {
let &[a, b] = self.vertices();
Expand All @@ -25,24 +25,24 @@ impl Approx for &Edge {
);
let curve_approx = (self.curve(), range).approx(tolerance);

EdgeApprox {
HalfEdgeApprox {
first,
curve_approx,
}
}
}

/// An approximation of an [`Edge`]
/// An approximation of an [`HalfEdge`]
#[derive(Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct EdgeApprox {
pub struct HalfEdgeApprox {
/// The point that approximates the first vertex of the curve
pub first: ApproxPoint<2>,

/// The approximation of the edge's curve
pub curve_approx: CurveApprox,
}

impl EdgeApprox {
impl HalfEdgeApprox {
/// Compute the points that approximate the edge
pub fn points(&self) -> Vec<ApproxPoint<2>> {
let mut points = Vec::new();
Expand Down
30 changes: 15 additions & 15 deletions crates/fj-kernel/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::objects::{Curve, CurveKind, Edge};
use crate::objects::{Curve, CurveKind, HalfEdge};

use super::LineSegmentIntersection;

/// The intersection between a [`Curve`] and an [`Edge`], in curve coordinates
/// 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,23 +26,23 @@ impl CurveEdgeIntersection {
/// # Panics
///
/// Currently, only intersections between lines and line segments can be
/// computed. Panics, if a different type of [`Curve`] or [`Edge`] is
/// computed. Panics, if a different type of [`Curve`] or [`HalfEdge`] is
/// passed.
pub fn compute(curve: &Curve, edge: &Edge) -> Option<Self> {
pub fn compute(curve: &Curve, half_edge: &HalfEdge) -> Option<Self> {
let curve_as_line = match curve.kind() {
CurveKind::Line(line) => line,
_ => todo!("Curve-edge intersection only supports lines"),
};

let edge_as_segment = {
let edge_curve_as_line = match edge.curve().kind() {
let edge_curve_as_line = match half_edge.curve().kind() {
CurveKind::Line(line) => line,
_ => {
todo!("Curve-edge intersection only supports line segments")
}
};

let edge_vertices = edge.vertices().map(|vertex| {
let edge_vertices = half_edge.vertices().map(|vertex| {
edge_curve_as_line.point_from_line_coords(vertex.position())
});

Expand Down Expand Up @@ -71,18 +71,18 @@ impl CurveEdgeIntersection {
mod tests {
use fj_math::Point;

use crate::objects::{Curve, Edge, Surface};
use crate::objects::{Curve, HalfEdge, Surface};

use super::CurveEdgeIntersection;

#[test]
fn compute_edge_in_front_of_curve_origin() {
let surface = Surface::xy_plane();
let curve = Curve::build(surface).u_axis();
let edge = Edge::build(surface)
let half_edge = HalfEdge::build(surface)
.line_segment_from_points([[1., -1.], [1., 1.]]);

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

assert_eq!(
intersection,
Expand All @@ -96,10 +96,10 @@ mod tests {
fn compute_edge_behind_curve_origin() {
let surface = Surface::xy_plane();
let curve = Curve::build(surface).u_axis();
let edge = Edge::build(surface)
let half_edge = HalfEdge::build(surface)
.line_segment_from_points([[-1., -1.], [-1., 1.]]);

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

assert_eq!(
intersection,
Expand All @@ -113,10 +113,10 @@ mod tests {
fn compute_edge_parallel_to_curve() {
let surface = Surface::xy_plane();
let curve = Curve::build(surface).u_axis();
let edge = Edge::build(surface)
let half_edge = HalfEdge::build(surface)
.line_segment_from_points([[-1., -1.], [1., -1.]]);

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

assert!(intersection.is_none());
}
Expand All @@ -125,10 +125,10 @@ mod tests {
fn compute_edge_on_curve() {
let surface = Surface::xy_plane();
let curve = Curve::build(surface).u_axis();
let edge = Edge::build(surface)
let half_edge = HalfEdge::build(surface)
.line_segment_from_points([[-1., 0.], [1., 0.]]);

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

assert_eq!(
intersection,
Expand Down
9 changes: 3 additions & 6 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ impl CurveFaceIntersection {

/// Compute the intersections between a [`Curve`] and a [`Face`]
pub fn compute(curve: &Curve, face: &Face) -> Self {
let edges = face.all_cycles().flat_map(|cycle| {
let edges: Vec<_> = cycle.edges().cloned().collect();
edges
});
let half_edges = face.all_cycles().flat_map(|cycle| cycle.half_edges());

let mut intersections = Vec::new();

for edge in edges {
let intersection = CurveEdgeIntersection::compute(curve, &edge);
for half_edge in half_edges {
let intersection = CurveEdgeIntersection::compute(curve, half_edge);

if let Some(intersection) = intersection {
match intersection {
Expand Down
18 changes: 9 additions & 9 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use fj_math::Point;

use crate::objects::{Edge, Face, Vertex};
use crate::objects::{Face, HalfEdge, Vertex};

use super::{
ray_segment::RaySegmentIntersection, HorizontalRayToTheRight, Intersect,
Expand All @@ -25,13 +25,13 @@ 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()
.last()
.copied()
.and_then(|edge| (&ray, &edge).intersect());

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

let count_hit = match (hit, previous_hit) {
(
Expand All @@ -41,17 +41,17 @@ impl Intersect for (&Face, &Point<2>) {
// If the ray starts on the boundary of the face,
// there's nothing to else check.
return Some(
FacePointIntersection::PointIsOnEdge(*edge)
FacePointIntersection::PointIsOnEdge(*half_edge)
);
}
(Some(RaySegmentIntersection::RayStartsOnOnFirstVertex), _) => {
let vertex = edge.vertices()[0];
let vertex = half_edge.vertices()[0];
return Some(
FacePointIntersection::PointIsOnVertex(vertex)
);
}
(Some(RaySegmentIntersection::RayStartsOnSecondVertex), _) => {
let vertex = edge.vertices()[1];
let vertex = half_edge.vertices()[1];
return Some(
FacePointIntersection::PointIsOnVertex(vertex)
);
Expand Down Expand Up @@ -120,7 +120,7 @@ pub enum FacePointIntersection {
PointIsInsideFace,

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

/// The point is coincident with a vertex
PointIsOnVertex(Vertex),
Expand Down Expand Up @@ -234,7 +234,7 @@ mod tests {
let intersection = (&face, &point).intersect();

let edge = face
.edge_iter()
.half_edge_iter()
.copied()
.find(|edge| {
let [a, b] = edge.vertices();
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/ray_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use fj_math::Segment;

use crate::{
algorithms::intersect::{HorizontalRayToTheRight, Intersect},
objects::{CurveKind, Edge},
objects::{CurveKind, HalfEdge},
};

use super::ray_segment::RaySegmentIntersection;

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

fn intersect(self) -> Option<Self::Intersection> {
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fj_math::{Point, Scalar, Vector};

use crate::{
algorithms::intersect::face_point::FacePointIntersection,
objects::{Edge, Face, Vertex},
objects::{Face, HalfEdge, Vertex},
};

use super::{HorizontalRayToTheRight, Intersect};
Expand Down Expand Up @@ -142,7 +142,7 @@ pub enum RayFaceIntersection {
RayHitsFaceAndAreParallel,

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

/// The ray hits a vertex
RayHitsVertex(Vertex),
Expand Down Expand Up @@ -213,7 +213,7 @@ mod tests {
.translate([1., 1., 0.]);

let edge = face
.edge_iter()
.half_edge_iter()
.copied()
.find(|edge| {
let [a, b] = edge.vertices();
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/reverse/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl Reverse for Cycle {
let surface = *self.surface();

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

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/reverse/edge.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::objects::Edge;
use crate::objects::HalfEdge;

use super::Reverse;

impl Reverse for Edge {
impl Reverse for HalfEdge {
fn reverse(self) -> Self {
let vertices = {
let &[a, b] = self.vertices();
[b, a]
};

Edge::from_curve_and_vertices(*self.curve(), vertices)
HalfEdge::from_curve_and_vertices(*self.curve(), vertices)
}
}
16 changes: 8 additions & 8 deletions crates/fj-kernel/src/algorithms/reverse/face.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fj_math::{Circle, Line, Point, Vector};

use crate::objects::{
Curve, CurveKind, Cycle, Edge, Face, SurfaceVertex, Vertex,
Curve, CurveKind, Cycle, Face, HalfEdge, SurfaceVertex, Vertex,
};

use super::Reverse;
Expand Down Expand Up @@ -41,9 +41,9 @@ fn reverse_local_coordinates_in_cycles<'r>(
fn reverse_local_coordinates_in_cycle(cycle: &Cycle) -> Cycle {
let surface = cycle.surface().reverse();

let edges = cycle.edges().map(|edge| {
let half_edges = cycle.half_edges().map(|half_edge| {
let curve = {
let local = match edge.curve().kind() {
let local = match half_edge.curve().kind() {
CurveKind::Circle(circle) => {
let center =
Point::from([circle.center().u, -circle.center().v]);
Expand All @@ -66,13 +66,13 @@ fn reverse_local_coordinates_in_cycle(cycle: &Cycle) -> Cycle {
};

Curve::new(
edge.curve().surface().reverse(),
half_edge.curve().surface().reverse(),
local,
*edge.curve().global_form(),
*half_edge.curve().global_form(),
)
};

let vertices = edge.vertices().map(|vertex| {
let vertices = half_edge.vertices().map(|vertex| {
let surface_vertex = {
let vertex = vertex.surface_form();

Expand All @@ -94,10 +94,10 @@ fn reverse_local_coordinates_in_cycle(cycle: &Cycle) -> Cycle {
)
});

Edge::from_curve_and_vertices(curve, vertices)
HalfEdge::from_curve_and_vertices(curve, vertices)
});

Cycle::new(surface, edges)
Cycle::new(surface, half_edges)
}

#[cfg(test)]
Expand Down
Loading