Skip to content

Commit db1ac4a

Browse files
committed
Add segment-box intersection
1 parent 166aba4 commit db1ac4a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/geometry/algorithms/ArborX_Intersects.hpp

+36
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,42 @@ struct intersects<SegmentTag, SegmentTag, Segment, Segment>
476476
}
477477
};
478478

479+
template <typename Segment, typename Box>
480+
struct intersects<SegmentTag, BoxTag, Segment, Box>
481+
{
482+
KOKKOS_FUNCTION static constexpr bool apply(Segment const &segment,
483+
Box const &box)
484+
{
485+
static_assert(GeometryTraits::dimension_v<Segment> == 2);
486+
487+
if (Details::intersects(segment.a, box) ||
488+
Details::intersects(segment.b, box))
489+
return true;
490+
491+
using Point = std::decay_t<decltype(box.minCorner())>;
492+
493+
auto const &bottom_left = box.minCorner();
494+
auto const &top_right = box.maxCorner();
495+
auto const top_left = Point{bottom_left[0], top_right[1]};
496+
auto const bottom_right = Point{top_right[0], bottom_left[1]};
497+
498+
return Details::intersects(segment, Segment{bottom_left, top_left}) ||
499+
Details::intersects(segment, Segment{bottom_left, bottom_right}) ||
500+
Details::intersects(segment, Segment{top_right, top_left}) ||
501+
Details::intersects(segment, Segment{top_right, bottom_right});
502+
}
503+
};
504+
505+
template <typename Box, typename Segment>
506+
struct intersects<BoxTag, SegmentTag, Box, Segment>
507+
{
508+
KOKKOS_FUNCTION static constexpr bool apply(Box const &box,
509+
Segment const &segment)
510+
{
511+
return Details::intersects(segment, box);
512+
}
513+
};
514+
479515
} // namespace Dispatch
480516

481517
} // namespace ArborX::Details

0 commit comments

Comments
 (0)