/**************************************************************************** * Copyright (c) 2017-2022 by the 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_PREDICATE_HPP #define ARBORX_PREDICATE_HPP #include namespace ArborX { namespace Details { struct NearestPredicateTag {}; struct SpatialPredicateTag {}; struct OrderedSpatialPredicateTag {}; // nvcc has problems with using std::interal_constant here. template struct is_valid_predicate_tag { static constexpr bool value = std::is_same{} || std::is_same{} || std::is_same{}; }; } // namespace Details template struct Nearest { using Tag = Details::NearestPredicateTag; KOKKOS_DEFAULTED_FUNCTION Nearest() = default; KOKKOS_FUNCTION Nearest(Geometry const &geometry, int k) : _geometry(geometry) , _k(k) {} template KOKKOS_FUNCTION auto distance(OtherGeometry const &other) const { using Details::distance; return distance(_geometry, other); } Geometry _geometry; int _k = 0; }; template struct Intersects { using Tag = Details::SpatialPredicateTag; KOKKOS_DEFAULTED_FUNCTION Intersects() = default; KOKKOS_FUNCTION Intersects(Geometry const &geometry) : _geometry(geometry) {} template KOKKOS_FUNCTION bool operator()(OtherGeometry const &other) const { using Details::intersects; return intersects(_geometry, other); } Geometry _geometry; }; namespace Experimental { template struct OrderedSpatial { using Tag = Details::OrderedSpatialPredicateTag; KOKKOS_DEFAULTED_FUNCTION OrderedSpatial() = default; KOKKOS_FUNCTION OrderedSpatial(Geometry const &geometry) : _geometry(geometry) {} template KOKKOS_FUNCTION auto distance(OtherGeometry const &other) const { using Details::distance; return distance(_geometry, other); } Geometry _geometry; }; } // namespace Experimental template KOKKOS_INLINE_FUNCTION Nearest nearest(Geometry const &geometry, int k = 1) { return Nearest(geometry, k); } template KOKKOS_INLINE_FUNCTION Intersects intersects(Geometry const &geometry) { return Intersects(geometry); } template KOKKOS_INLINE_FUNCTION int getK(Nearest const &pred) { return pred._k; } namespace Experimental { template KOKKOS_INLINE_FUNCTION OrderedSpatial ordered_intersects(Geometry const &geometry) { return OrderedSpatial(geometry); } } // namespace Experimental template KOKKOS_INLINE_FUNCTION Geometry const & getGeometry(Nearest const &pred) { return pred._geometry; } template KOKKOS_INLINE_FUNCTION Geometry const & getGeometry(Intersects const &pred) { return pred._geometry; } template KOKKOS_INLINE_FUNCTION Geometry const & getGeometry(Experimental::OrderedSpatial const &pred) { return pred._geometry; } template struct PredicateWithAttachment : Predicate { KOKKOS_DEFAULTED_FUNCTION PredicateWithAttachment() = default; KOKKOS_INLINE_FUNCTION PredicateWithAttachment(Predicate const &pred, Data const &data) : Predicate{pred} , _data{data} {} KOKKOS_INLINE_FUNCTION PredicateWithAttachment(Predicate &&pred, Data &&data) : Predicate(std::forward(pred)) , _data(std::forward(data)) {} Data _data; }; template KOKKOS_INLINE_FUNCTION Data const & getData(PredicateWithAttachment const &pred) noexcept { return pred._data; } template KOKKOS_INLINE_FUNCTION Predicate const & getPredicate(PredicateWithAttachment const &pred) noexcept { return static_cast(pred); // slicing } template KOKKOS_INLINE_FUNCTION constexpr auto attach(Predicate &&pred, Data &&data) { return PredicateWithAttachment, std::decay_t>{ std::forward(pred), std::forward(data)}; } } // namespace ArborX #endif