Skip to content

Commit

Permalink
Merge pull request #951 from hannobraun/intersect
Browse files Browse the repository at this point in the history
Make names of enum variants more explicit
  • Loading branch information
hannobraun authored Aug 12, 2022
2 parents f536e77 + 01d7dce commit 03faae5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
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 @@ -36,9 +36,9 @@ impl Intersect for (&Face, &Point<2>) {
let count_hit = match (hit, previous_hit) {
(
Some(
RaySegmentIntersection::OnSegment
| RaySegmentIntersection::OnFirstVertex
| RaySegmentIntersection::OnSecondVertex,
RaySegmentIntersection::RayStartsOnSegment
| RaySegmentIntersection::RayStartsOnOnFirstVertex
| RaySegmentIntersection::RayStartsOnSecondVertex,
),
_,
) => {
Expand All @@ -47,17 +47,17 @@ impl Intersect for (&Face, &Point<2>) {
// this intersection test, the face contains the point.
return Some(FacePointIntersection::FaceContainsPoint);
}
(Some(RaySegmentIntersection::Segment), _) => {
(Some(RaySegmentIntersection::RayHitsSegment), _) => {
// We're hitting a segment right-on. Clear case.
true
}
(
Some(RaySegmentIntersection::UpperVertex),
Some(RaySegmentIntersection::LowerVertex),
Some(RaySegmentIntersection::RayHitsUpperVertex),
Some(RaySegmentIntersection::RayHitsLowerVertex),
)
| (
Some(RaySegmentIntersection::LowerVertex),
Some(RaySegmentIntersection::UpperVertex),
Some(RaySegmentIntersection::RayHitsLowerVertex),
Some(RaySegmentIntersection::RayHitsUpperVertex),
) => {
// If we're hitting a vertex, only count it if we've hit
// the other kind of vertex right before.
Expand All @@ -74,7 +74,7 @@ impl Intersect for (&Face, &Point<2>) {
// passing through anything.
true
}
(Some(RaySegmentIntersection::Parallel), _) => {
(Some(RaySegmentIntersection::RayHitsSegmentAndAreParallel), _) => {
// A parallel edge must be completely ignored. Its
// presence won't change anything, so we can treat it as
// if it wasn't there, and its neighbors were connected
Expand Down
56 changes: 28 additions & 28 deletions crates/fj-kernel/src/algorithms/intersect/ray_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &Segment<2>) {
}

if ray.origin.u == a.u {
return Some(RaySegmentIntersection::OnFirstVertex);
return Some(RaySegmentIntersection::RayStartsOnOnFirstVertex);
}
if ray.origin.u == b.u {
return Some(RaySegmentIntersection::OnSecondVertex);
return Some(RaySegmentIntersection::RayStartsOnSecondVertex);
}
if ray.origin.u > left.u && ray.origin.u < right.u {
return Some(RaySegmentIntersection::OnSegment);
return Some(RaySegmentIntersection::RayStartsOnSegment);
}

return Some(RaySegmentIntersection::Parallel);
return Some(RaySegmentIntersection::RayHitsSegmentAndAreParallel);
}

let pa = robust::Coord {
Expand All @@ -60,26 +60,26 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &Segment<2>) {
// ray starts on the line

if ray.origin.v == a.v {
return Some(RaySegmentIntersection::OnFirstVertex);
return Some(RaySegmentIntersection::RayStartsOnOnFirstVertex);
}
if ray.origin.v == b.v {
return Some(RaySegmentIntersection::OnSecondVertex);
return Some(RaySegmentIntersection::RayStartsOnSecondVertex);
}

return Some(RaySegmentIntersection::OnSegment);
return Some(RaySegmentIntersection::RayStartsOnSegment);
}

if robust::orient2d(pa, pb, pc) > 0. {
// ray starts left of the line

if ray.origin.v == upper.v {
return Some(RaySegmentIntersection::UpperVertex);
return Some(RaySegmentIntersection::RayHitsUpperVertex);
}
if ray.origin.v == lower.v {
return Some(RaySegmentIntersection::LowerVertex);
return Some(RaySegmentIntersection::RayHitsLowerVertex);
}

return Some(RaySegmentIntersection::Segment);
return Some(RaySegmentIntersection::RayHitsSegment);
}

None
Expand All @@ -90,25 +90,25 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &Segment<2>) {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum RaySegmentIntersection {
/// The ray hit the segment itself
Segment,
RayHitsSegment,

/// The ray hit the lower vertex of the segment
LowerVertex,
RayHitsLowerVertex,

/// The ray hit the upper vertex of the segment
UpperVertex,
RayHitsUpperVertex,

/// The ray hit the whole segment, as it is parallel to the ray
Parallel,
RayHitsSegmentAndAreParallel,

/// The ray starts on the segment
OnSegment,
RayStartsOnSegment,

/// The ray starts on the first vertex of the segment
OnFirstVertex,
RayStartsOnOnFirstVertex,

/// The ray starts on the second vertex of the segment
OnSecondVertex,
RayStartsOnSecondVertex,
}

#[cfg(test)]
Expand All @@ -131,7 +131,7 @@ mod tests {
assert!((&ray, &above).intersect().is_none());
assert!(matches!(
(&ray, &same_level).intersect(),
Some(RaySegmentIntersection::Segment)
Some(RaySegmentIntersection::RayHitsSegment)
));
}

Expand All @@ -156,15 +156,15 @@ mod tests {
assert!((&ray, &no_hit).intersect().is_none());
assert!(matches!(
(&ray, &hit_segment).intersect(),
Some(RaySegmentIntersection::Segment)
Some(RaySegmentIntersection::RayHitsSegment)
));
assert!(matches!(
(&ray, &hit_upper).intersect(),
Some(RaySegmentIntersection::UpperVertex),
Some(RaySegmentIntersection::RayHitsUpperVertex),
));
assert!(matches!(
(&ray, &hit_lower).intersect(),
Some(RaySegmentIntersection::LowerVertex),
Some(RaySegmentIntersection::RayHitsLowerVertex),
));
}

Expand All @@ -178,15 +178,15 @@ mod tests {

assert!(matches!(
(&ray, &hit_segment).intersect(),
Some(RaySegmentIntersection::OnSegment)
Some(RaySegmentIntersection::RayStartsOnSegment)
));
assert!(matches!(
(&ray, &hit_upper).intersect(),
Some(RaySegmentIntersection::OnSecondVertex),
Some(RaySegmentIntersection::RayStartsOnSecondVertex),
));
assert!(matches!(
(&ray, &hit_lower).intersect(),
Some(RaySegmentIntersection::OnFirstVertex),
Some(RaySegmentIntersection::RayStartsOnOnFirstVertex),
));
}

Expand All @@ -200,7 +200,7 @@ mod tests {
assert!((&ray, &left).intersect().is_none());
assert!(matches!(
(&ray, &right).intersect(),
Some(RaySegmentIntersection::Parallel)
Some(RaySegmentIntersection::RayHitsSegmentAndAreParallel)
));
}

Expand All @@ -214,15 +214,15 @@ mod tests {

assert!(matches!(
(&ray, &left).intersect(),
Some(RaySegmentIntersection::OnSecondVertex)
Some(RaySegmentIntersection::RayStartsOnSecondVertex)
));
assert!(matches!(
(&ray, &overlapping).intersect(),
Some(RaySegmentIntersection::OnSegment),
Some(RaySegmentIntersection::RayStartsOnSegment),
));
assert!(matches!(
(&ray, &right).intersect(),
Some(RaySegmentIntersection::OnFirstVertex),
Some(RaySegmentIntersection::RayStartsOnOnFirstVertex),
));
}
}
18 changes: 9 additions & 9 deletions crates/fj-kernel/src/algorithms/triangulate/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ impl Polygon {
let count_hit = match (hit, previous_hit) {
(
Some(
RaySegmentIntersection::OnSegment
| RaySegmentIntersection::OnFirstVertex
| RaySegmentIntersection::OnSecondVertex,
RaySegmentIntersection::RayStartsOnSegment
| RaySegmentIntersection::RayStartsOnOnFirstVertex
| RaySegmentIntersection::RayStartsOnSecondVertex,
),
_,
) => {
Expand All @@ -186,17 +186,17 @@ impl Polygon {
// point.
return true;
}
(Some(RaySegmentIntersection::Segment), _) => {
(Some(RaySegmentIntersection::RayHitsSegment), _) => {
// We're hitting a segment right-on. Clear case.
true
}
(
Some(RaySegmentIntersection::UpperVertex),
Some(RaySegmentIntersection::LowerVertex),
Some(RaySegmentIntersection::RayHitsUpperVertex),
Some(RaySegmentIntersection::RayHitsLowerVertex),
)
| (
Some(RaySegmentIntersection::LowerVertex),
Some(RaySegmentIntersection::UpperVertex),
Some(RaySegmentIntersection::RayHitsLowerVertex),
Some(RaySegmentIntersection::RayHitsUpperVertex),
) => {
// If we're hitting a vertex, only count it if we've hit
// the other kind of vertex right before.
Expand All @@ -213,7 +213,7 @@ impl Polygon {
// passing through anything.
true
}
(Some(RaySegmentIntersection::Parallel), _) => {
(Some(RaySegmentIntersection::RayHitsSegmentAndAreParallel), _) => {
// A parallel edge must be completely ignored. Its
// presence won't change anything, so we can treat it as
// if it wasn't there, and its neighbors were connected
Expand Down

0 comments on commit 03faae5

Please sign in to comment.