Clustering
C++20 header-only: DBSCAN, HDBSCAN, k-means.
Loading...
Searching...
No Matches
aabb.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <span>
5#include <type_traits>
6
8#ifdef CLUSTERING_USE_AVX2
9#include "clustering/math/detail/aabb_gap_avx2.h"
10#endif
11
13
43template <class T>
44[[nodiscard]] inline T pointAabbGapSq(const T *point, std::span<const T> boxMin,
45 std::span<const T> boxMax) noexcept {
46 static_assert(std::is_same_v<T, float>,
47 "pointAabbGapSq: T must be float; a double specialization is out of scope.");
48 CLUSTERING_ALWAYS_ASSERT(boxMin.size() == boxMax.size());
49 const std::size_t d = boxMin.size();
50#ifdef CLUSTERING_USE_AVX2
51 return detail::pointAabbGapSqAvx2F32(point, boxMin.data(), boxMax.data(), d);
52#else
53 T sum = T{0};
54 for (std::size_t j = 0; j < d; ++j) {
55 T gap = T{0};
56 if (point[j] < boxMin[j]) {
57 gap = boxMin[j] - point[j];
58 } else if (point[j] > boxMax[j]) {
59 gap = point[j] - boxMax[j];
60 }
61 sum += gap * gap;
62 }
63 return sum;
64#endif
65}
66
67} // namespace clustering::math
#define CLUSTERING_ALWAYS_ASSERT(cond)
Release-active assertion: evaluates cond in every build configuration.
T pointAabbGapSq(const T *point, std::span< const T > boxMin, std::span< const T > boxMax) noexcept
Squared gap distance between a point and an axis-aligned bounding box.
Definition aabb.h:44
T sum(const NDArray< T, 1, L > &x) noexcept
Naive single-pass sum of a rank-1 array.
Definition reduce.h:25