Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 5 additions & 46 deletions src/geometry/algorithms/ArborX_Distance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <ArborX_GeometryTraits.hpp>
#include <ArborX_Triangle.hpp>
#include <algorithms/ArborX_ClosestPoint.hpp>
#include <algorithms/ArborX_ReverseDispatch.hpp>
#include <kokkos_ext/ArborX_KokkosExtArithmeticTraits.hpp>
#include <misc/ArborX_Vector.hpp>

Expand All @@ -37,10 +38,10 @@ KOKKOS_INLINE_FUNCTION auto distance(Geometry1 const &geometry1,
{
static_assert(GeometryTraits::dimension_v<Geometry1> ==
GeometryTraits::dimension_v<Geometry2>);
return Details::Dispatch::distance<GeometryTraits::tag_t<Geometry1>,
GeometryTraits::tag_t<Geometry2>,
Geometry1, Geometry2>::apply(geometry1,
geometry2);
return Details::Dispatch::DoApply<
Details::Dispatch::distance, GeometryTraits::tag_t<Geometry1>,
GeometryTraits::tag_t<Geometry2>, Geometry1, Geometry2>::apply(geometry1,
geometry2);
}

namespace Details::Dispatch
Expand Down Expand Up @@ -78,15 +79,6 @@ struct distance<PointTag, BoxTag, Point, Box>
}
};

template <typename Box, typename Point>
struct distance<BoxTag, PointTag, Box, Point>
{
KOKKOS_FUNCTION static auto apply(Box const &box, Point const &point)
{
return ::ArborX::distance(point, box);
}
};

// distance point-sphere
template <typename Point, typename Sphere>
struct distance<PointTag, SphereTag, Point, Sphere>
Expand All @@ -100,16 +92,6 @@ struct distance<PointTag, SphereTag, Point, Sphere>
}
};

// distance sphere-point
template <typename Sphere, typename Point>
struct distance<SphereTag, PointTag, Sphere, Point>
{
KOKKOS_FUNCTION static auto apply(Sphere const &sphere, Point const &point)
{
return ::ArborX::distance(point, sphere);
}
};

// distance sphere-sphere
template <typename Sphere1, typename Sphere2>
struct distance<SphereTag, SphereTag, Sphere1, Sphere2>
Expand Down Expand Up @@ -176,19 +158,6 @@ struct distance<PointTag, TetrahedronTag, Point, Tetrahedron>
}
};

// distance tetrahedron-point
template <typename Tetrahedron, typename Point>
struct distance<TetrahedronTag, PointTag, Tetrahedron, Point>
{
static constexpr int DIM = dimension_v<Point>;
using Coordinate = coordinate_type_t<Tetrahedron>;

KOKKOS_FUNCTION static auto apply(Tetrahedron const &tet, Point const &p)
{
return ::ArborX::distance(p, tet);
}
};

// distance box-box
template <typename Box1, typename Box2>
struct distance<BoxTag, BoxTag, Box1, Box2>
Expand Down Expand Up @@ -239,16 +208,6 @@ struct distance<SphereTag, BoxTag, Sphere, Box>
}
};

// distance sphere-box
template <typename Box, typename Sphere>
struct distance<BoxTag, SphereTag, Box, Sphere>
{
KOKKOS_FUNCTION static auto apply(Box const &box, Sphere const &sphere)
{
return ::ArborX::distance(sphere, box);
}
};

template <typename Point, typename Segment>
struct distance<PointTag, SegmentTag, Point, Segment>
{
Expand Down
107 changes: 5 additions & 102 deletions src/geometry/algorithms/ArborX_Intersects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <ArborX_GeometryTraits.hpp>
#include <ArborX_Ray.hpp>
#include <ArborX_Segment.hpp>
#include <algorithms/ArborX_ReverseDispatch.hpp>
#include <misc/ArborX_Vector.hpp>

#include <Kokkos_Array.hpp>
Expand All @@ -36,10 +37,10 @@ KOKKOS_INLINE_FUNCTION constexpr bool intersects(Geometry1 const &geometry1,
{
static_assert(GeometryTraits::dimension_v<Geometry1> ==
GeometryTraits::dimension_v<Geometry2>);
return Details::Dispatch::intersects<GeometryTraits::tag_t<Geometry1>,
GeometryTraits::tag_t<Geometry2>,
Geometry1, Geometry2>::apply(geometry1,
geometry2);
return Details::Dispatch::DoApply<
Details::Dispatch::intersects, GeometryTraits::tag_t<Geometry1>,
GeometryTraits::tag_t<Geometry2>, Geometry1, Geometry2>::apply(geometry1,
geometry2);
}

namespace Details::Dispatch
Expand Down Expand Up @@ -77,15 +78,6 @@ struct intersects<PointTag, BoxTag, Point, Box>
return true;
}
};
template <typename Box, typename Point>
struct intersects<BoxTag, PointTag, Box, Point>
{
KOKKOS_FUNCTION static constexpr bool apply(Box const &box,
Point const &point)
{
return ::ArborX::intersects(point, box);
}
};

// check if a sphere intersects with an axis-aligned bounding box
template <typename Sphere, typename Box>
Expand Down Expand Up @@ -121,16 +113,6 @@ struct intersects<SphereTag, PointTag, Sphere, Point>
}
};

template <typename Point, typename Sphere>
struct intersects<PointTag, SphereTag, Point, Sphere>
{
KOKKOS_FUNCTION static constexpr bool apply(Point const &point,
Sphere const &sphere)
{
return ::ArborX::intersects(sphere, point);
}
};

// check if a sphere intersects with a triangle
template <typename Sphere, typename Triangle>
struct intersects<SphereTag, TriangleTag, Sphere, Triangle>
Expand All @@ -142,16 +124,6 @@ struct intersects<SphereTag, TriangleTag, Sphere, Triangle>
}
};

template <typename Triangle, typename Sphere>
struct intersects<TriangleTag, SphereTag, Triangle, Sphere>
{
KOKKOS_FUNCTION static constexpr bool apply(Triangle const &triangle,
Sphere const &sphere)
{
return ::ArborX::intersects(sphere, triangle);
}
};

template <typename Point, typename Triangle>
struct intersects<PointTag, TriangleTag, Point, Triangle>
{
Expand Down Expand Up @@ -353,14 +325,6 @@ struct intersects<KDOPTag, BoxTag, KDOP, Box>
}
};

template <typename Box, typename KDOP>
struct intersects<BoxTag, KDOPTag, Box, KDOP>
{
KOKKOS_FUNCTION static constexpr bool apply(Box const &box, KDOP const &kdop)
{
return ::ArborX::intersects(kdop, box);
}
};
template <typename Triangle, typename Box>
struct intersects<TriangleTag, BoxTag, Triangle, Box>
{
Expand Down Expand Up @@ -393,16 +357,6 @@ struct intersects<PointTag, KDOPTag, Point, KDOP>
}
};

template <typename KDOP, typename Point>
struct intersects<KDOPTag, PointTag, KDOP, Point>
{
KOKKOS_FUNCTION static constexpr bool apply(KDOP const &kdop,
Point const &point)
{
return ::ArborX::intersects(point, kdop);
}
};

template <typename KDOP1, typename KDOP2>
struct intersects<KDOPTag, KDOPTag, KDOP1, KDOP2>
{
Expand Down Expand Up @@ -540,16 +494,6 @@ struct intersects<SegmentTag, BoxTag, Segment, Box>
}
};

template <typename Box, typename Segment>
struct intersects<BoxTag, SegmentTag, Box, Segment>
{
KOKKOS_FUNCTION static constexpr bool apply(Box const &box,
Segment const &segment)
{
return ::ArborX::intersects(segment, box);
}
};

template <typename Segment, typename Triangle>
struct intersects<SegmentTag, TriangleTag, Segment, Triangle>
{
Expand All @@ -570,17 +514,6 @@ struct intersects<SegmentTag, TriangleTag, Segment, Triangle>
}
};

template <typename Triangle, typename Segment>
struct intersects<TriangleTag, SegmentTag, Triangle, Segment>
{
KOKKOS_FUNCTION static constexpr bool apply(Triangle const &triangle,
Segment const &segment)

{
return ::ArborX::intersects(segment, triangle);
}
};

namespace
{
// Computes x^t R y
Expand Down Expand Up @@ -608,16 +541,6 @@ struct intersects<EllipsoidTag, PointTag, Ellipsoid, Point>
}
};

template <typename Point, typename Ellipsoid>
struct intersects<PointTag, EllipsoidTag, Point, Ellipsoid>
{
KOKKOS_FUNCTION static constexpr bool apply(Point const &point,
Ellipsoid const &ellipsoid)
{
return ::ArborX::intersects(ellipsoid, point);
}
};

template <typename Ellipsoid, typename Segment>
struct intersects<EllipsoidTag, SegmentTag, Ellipsoid, Segment>
{
Expand Down Expand Up @@ -658,16 +581,6 @@ struct intersects<EllipsoidTag, SegmentTag, Ellipsoid, Segment>
}
};

template <typename Segment, typename Ellipsoid>
struct intersects<SegmentTag, EllipsoidTag, Segment, Ellipsoid>
{
KOKKOS_FUNCTION static constexpr bool apply(Segment const &segment,
Ellipsoid const &ellipsoid)
{
return ::ArborX::intersects(ellipsoid, segment);
}
};

template <typename Ellipsoid, typename Box>
struct intersects<EllipsoidTag, BoxTag, Ellipsoid, Box>
{
Expand Down Expand Up @@ -764,16 +677,6 @@ struct intersects<EllipsoidTag, BoxTag, Ellipsoid, Box>
}
};

template <typename Box, typename Ellipsoid>
struct intersects<BoxTag, EllipsoidTag, Box, Ellipsoid>
{
KOKKOS_FUNCTION static constexpr bool apply(Box const &box,
Ellipsoid const &ellipsoid)
{
return ::ArborX::intersects(ellipsoid, box);
}
};

} // namespace Details::Dispatch

} // namespace ArborX
Expand Down
50 changes: 50 additions & 0 deletions src/geometry/algorithms/ArborX_ReverseDispatch.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/****************************************************************************
* Copyright (c) 2025, ArborX authors *
* All rights reserved. *
* *
* This file is part of the ArborX library. ArborX is *
* distributed under a BSD 3-clause license. For the licensing terms see *
* the LICENSE file in the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/

#ifndef ARBORX_DETAILS_GEOMETRY_REVERSE_DISPATCH_HPP
#define ARBORX_DETAILS_GEOMETRY_REVERSE_DISPATCH_HPP

#include <Kokkos_Macros.hpp>

#include <concepts>

namespace ArborX::Details::Dispatch
{

template <typename Algorithm, typename Geometry1, typename Geometry2>
concept CanApply =
requires(Geometry1 const &geometry1, Geometry2 const &geometry2) {
{
Algorithm::apply(geometry1, geometry2)
};
};

template <template <typename, typename, typename, typename> typename Algorithm,
typename Tag1, typename Tag2, typename Geometry1, typename Geometry2>
struct DoApply
{
using ForwardAlgorithm = Algorithm<Tag1, Tag2, Geometry1, Geometry2>;
using ReverseAlgorithm = Algorithm<Tag2, Tag1, Geometry2, Geometry1>;
static KOKKOS_FUNCTION constexpr auto apply(Geometry1 const &geometry1,
Geometry2 const &geometry2)
{
if constexpr (!std::same_as<Geometry1, Geometry2> &&
!CanApply<ForwardAlgorithm, Geometry1, Geometry2> &&
CanApply<ReverseAlgorithm, Geometry2, Geometry1>)
return ReverseAlgorithm::apply(geometry2, geometry1);
else
return ForwardAlgorithm::apply(geometry1, geometry2);
}
};

} // namespace ArborX::Details::Dispatch

#endif