From c8b16f593c7c8677488cf6015a3e9e6826b45177 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 12 Jul 2023 09:11:04 -0400 Subject: [PATCH] Introduce conversion functions --- source/arborx/access_traits.cc | 66 ++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/source/arborx/access_traits.cc b/source/arborx/access_traits.cc index 3c37bc6982..ac2bbf36f7 100644 --- a/source/arborx/access_traits.cc +++ b/source/arborx/access_traits.cc @@ -21,6 +21,22 @@ DEAL_II_NAMESPACE_OPEN namespace ArborXWrappers { + namespace + { + template + dealii::Point<3, float> + to_3d_float_point(dealii::Point p) + { + static_assert(dim >= 1 && dim <= 3); + if (dim == 1) + return {float(p[0]), 0.f, 0.f}; + else if (dim == 2) + return {float(p[0]), float(p[1]), 0.f}; + else + return {float(p[0]), float(p[1]), float(p[2])}; + } + } // namespace + // ------------------- PointPredicate ------------------- // template PointPredicate::PointPredicate( @@ -29,13 +45,7 @@ namespace ArborXWrappers const unsigned int size = dim_points.size(); points.reserve(size); for (unsigned int i = 0; i < size; ++i) - { - points.emplace_back(static_cast(dim_points[i][0]), - dim < 2 ? 0.f : - static_cast(dim_points[i][1]), - dim < 3 ? 0.f : - static_cast(dim_points[i][2])); - } + points.emplace_back(to_3d_float_point(dim_points[i])); } @@ -158,12 +168,8 @@ namespace ArborXWrappers { // ArborX assumes that the center coordinates and the radius use float // and the sphere is 3d - spheres.emplace_back( - dealii::Point<3, float>( - static_cast(dim_spheres[i].first[0]), - dim < 2 ? 0.f : static_cast(dim_spheres[i].first[1]), - dim < 3 ? 0.f : static_cast(dim_spheres[i].first[2])), - static_cast(dim_spheres[i].second)); + spheres.emplace_back(to_3d_float_point(dim_spheres[i].first), + static_cast(dim_spheres[i].second)); } } @@ -214,6 +220,24 @@ DEAL_II_NAMESPACE_CLOSE namespace ArborX { + namespace + { + template + Point + to_arborx_point(dealii::Point p) + { + static_assert(dim >= 1 && dim <= 3); + if (dim == 1) + return {float(p[0]), 0.f, 0.f}; + else if (dim == 2) + return {float(p[0]), float(p[1]), 0.f}; + else + return {float(p[0]), float(p[1]), float(p[2])}; + } + } // namespace + + + // ------------------- Point Primitives AccessTraits ------------------- // template std::size_t @@ -233,9 +257,7 @@ namespace ArborX { // ArborX assumes that the point coordinates use float and that the point // is 3d - return {static_cast(v[i][0]), - dim < 2 ? 0 : static_cast(v[i][1]), - dim < 3 ? 0 : static_cast(v[i][2])}; + return to_arborx_point(v[i]); } @@ -261,12 +283,7 @@ namespace ArborX const dealii::Point max_corner = boundary_points.second; // ArborX assumes that the bounding box coordinates use float and that the // bounding box is 3d - return {{static_cast(min_corner[0]), - dim < 2 ? 0.f : static_cast(min_corner[1]), - dim < 3 ? 0.f : static_cast(min_corner[2])}, - {static_cast(max_corner[0]), - dim < 2 ? 0.f : static_cast(max_corner[1]), - dim < 3 ? 0.f : static_cast(max_corner[2])}}; + return {to_arborx_point(min_corner), to_arborx_point(max_corner)}; } @@ -292,10 +309,7 @@ namespace ArborX { // ArborX assumes that the center coordinates and the radius use float and // the sphere is 3d - return {{static_cast(v[i].first[0]), - dim < 2 ? 0 : static_cast(v[i].first[1]), - dim < 3 ? 0 : static_cast(v[i].first[2])}, - static_cast(v[i].second)}; + return {to_arborx_point(v[i].first), static_cast(v[i].second)}; } } // namespace ArborX -- 2.39.5