Skip to content

Commit a1c6690

Browse files
committed
Add intersects ellipsoid-point
1 parent 288238e commit a1c6690

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/geometry/algorithms/ArborX_Intersects.hpp

+38
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ArborX_Distance.hpp"
1515
#include "ArborX_Expand.hpp"
1616
#include <ArborX_GeometryTraits.hpp>
17+
#include <misc/ArborX_Vector.hpp>
1718

1819
#include <Kokkos_Array.hpp>
1920
#include <Kokkos_MathematicalFunctions.hpp>
@@ -512,6 +513,43 @@ struct intersects<BoxTag, SegmentTag, Box, Segment>
512513
}
513514
};
514515

516+
namespace
517+
{
518+
// Computes x^t R y
519+
template <int DIM, typename Coordinate>
520+
KOKKOS_INLINE_FUNCTION auto rmt_multiply(Details::Vector<DIM, Coordinate> x,
521+
Coordinate const rmt[DIM][DIM],
522+
Details::Vector<DIM, Coordinate> y)
523+
{
524+
Coordinate r = 0;
525+
for (int i = 0; i < DIM; ++i)
526+
for (int j = 0; j < DIM; ++j)
527+
r += x[i] * rmt[i][j] * y[j];
528+
return r;
529+
}
530+
} // namespace
531+
532+
template <typename Ellipsoid, typename Point>
533+
struct intersects<EllipsoidTag, PointTag, Ellipsoid, Point>
534+
{
535+
KOKKOS_FUNCTION static constexpr bool apply(Ellipsoid const &ellipsoid,
536+
Point const &point)
537+
{
538+
auto d = point - ellipsoid.centroid();
539+
return rmt_multiply(d, ellipsoid.rmt(), d) <= 1;
540+
}
541+
};
542+
543+
template <typename Point, typename Ellipsoid>
544+
struct intersects<PointTag, EllipsoidTag, Point, Ellipsoid>
545+
{
546+
KOKKOS_FUNCTION static constexpr bool apply(Point const &point,
547+
Ellipsoid const &ellipsoid)
548+
{
549+
return Details::intersects(ellipsoid, point);
550+
}
551+
};
552+
515553
} // namespace Dispatch
516554

517555
} // namespace ArborX::Details

test/tstDetailsAlgorithms.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,21 @@ BOOST_AUTO_TEST_CASE(intersects)
342342
BOOST_TEST(!intersects(Segment2{{0.5, 1.6}, {2, 0}}, box2));
343343
BOOST_TEST(intersects(box2, Segment2{{-1, 2}, {2, -1}}));
344344
BOOST_TEST(!intersects(Segment2{{0.5, 1.6}, {2, 0}}, box2));
345+
346+
// ellipsoid
347+
using Ellipse = ArborX::Experimental::Ellipsoid<2>;
348+
constexpr Ellipse ellipse{{1.f, 1.f}, {{2.f, -1.5f}, {-1.5f, 2.f}}};
349+
BOOST_TEST(intersects(ellipse, Point2{1.f, 1.f}));
350+
BOOST_TEST(intersects(ellipse, Point2{0.f, 0.f}));
351+
BOOST_TEST(!intersects(ellipse, Point2{-0.01f, -0.01f}));
352+
BOOST_TEST(intersects(ellipse, Point2{0.f, 0.5f}));
353+
BOOST_TEST(!intersects(ellipse, Point2{0.f, 0.6f}));
354+
BOOST_TEST(intersects(ellipse, Point2{2.f, 2.f}));
355+
BOOST_TEST(!intersects(ellipse, Point2{0.5f, 1.5f}));
356+
BOOST_TEST(intersects(ellipse, Point2{1.f, 0.3f}));
357+
BOOST_TEST(!intersects(ellipse, Point2{1.f, 0.29f}));
358+
BOOST_TEST(intersects(ellipse, Point2{1.f, 1.69f}));
359+
BOOST_TEST(intersects(ellipse, Point2{1.f, 1.70f}));
345360
}
346361

347362
BOOST_AUTO_TEST_CASE(equals)

0 commit comments

Comments
 (0)