25 #include <olp/core/math/Vector.h>
42 int IntegerBits = std::is_integral<T>::value ?
sizeof(T) * 8 : 0,
43 bool IsSigned = std::numeric_limits<T>::is_signed>
97 template <
typename T,
unsigned int N>
101 static const unsigned int numCorners = 1 << N;
103 static const unsigned int dimensions = N;
143 template <
typename OtherT>
226 bool Contains(
const VectorType& point, T epsilon = T())
const;
301 template <
typename U,
unsigned int X>
311 template <
typename T>
312 bool CheckAddOperationOverflow(T a, T b) {
313 return ((a > 0) && (b > 0) && (a > (std::numeric_limits<T>::max() - b))) ||
314 ((a < 0) && (b < 0) && (a < (std::numeric_limits<T>::min() - b)));
320 AlignedBox<double, 3>;
322 template <
typename T,
unsigned int N>
324 : minimum_(std::numeric_limits<T>::max()),
325 maximum_(std::numeric_limits<T>::lowest()) {}
327 template <
typename T,
unsigned int N>
328 template <
typename OtherT>
330 : minimum_(other.min()), maximum_(other.max()) {}
332 template <
typename T,
unsigned int N>
334 : minimum_(min), maximum_(max) {}
336 template <
typename T,
unsigned int N>
338 minimum_ =
VectorType(std::numeric_limits<T>::max());
339 maximum_ =
VectorType(std::numeric_limits<T>::lowest());
342 template <
typename T,
unsigned int N>
348 template <
typename T,
unsigned int N>
352 if (std::numeric_limits<OverflowType>::is_integer &&
354 for (
unsigned dim = 0; dim < dimensions; ++dim) {
355 if (CheckAddOperationOverflow<OverflowType>(maximum_[dim],
369 template <
typename T,
unsigned int N>
372 return result.
x || result.
y || result.
z;
375 template <
typename T,
unsigned int N>
377 return Empty() ?
VectorType(0) : maximum_ - minimum_;
380 template <
typename T,
unsigned int N>
385 template <
typename T,
unsigned int N>
390 template <
typename T,
unsigned int N>
396 for (
unsigned dim = 0; dim < dimensions; dim++) {
397 if (minimum_[dim] - epsilon > point[dim] ||
398 maximum_[dim] + epsilon < point[dim])
405 template <
typename T,
unsigned int N>
411 for (
unsigned dim = 0; dim < dimensions; ++dim) {
412 if (box.minimum_[dim] < minimum_[dim] ||
413 box.maximum_[dim] > maximum_[dim]) {
421 template <
typename T,
unsigned int N>
429 for (
unsigned dim = 0; dim < dimensions; dim++) {
430 if ((maximum_[dim] < otherMin[dim]) || (minimum_[dim] > otherMax[dim]))
437 template <
typename T,
unsigned int N>
439 return static_cast<ValueType>(sqrt(distance2(point)));
442 template <
typename T,
unsigned int N>
445 for (
unsigned dim = 0; dim < dimensions; dim++) {
446 if (point[dim] < minimum_[dim]) {
447 T dimDistance = minimum_[dim] - point[dim];
448 distance2 += dimDistance * dimDistance;
449 }
else if (point[dim] > maximum_[dim]) {
450 T dimDistance = point[dim] - maximum_[dim];
451 distance2 += dimDistance * dimDistance;
458 template <
typename T,
unsigned int N>
464 bool thisEmpty = Empty();
465 bool otherEmpty = box.
Empty();
466 if (thisEmpty || otherEmpty) {
467 return thisEmpty == otherEmpty;
473 template <
typename T,
unsigned int N>
475 return !(*
this == box);
The aligned bounding-box implementation.
Definition: AlignedBox.h:98
ValueType Distance(const VectorType &point) const
Computes the distance from a point to the box.
Definition: AlignedBox.h:438
bool Intersects(const AlignedBox &box) const
Tests whether the box intersects another box.
Definition: AlignedBox.h:422
bool operator==(const AlignedBox &box) const
Checks whether two boxes are equal.
Definition: AlignedBox.h:459
ValueType Distance2(const VectorType &point) const
Computes the squared distance from a point to the box.
Definition: AlignedBox.h:443
VectorType Center() const
Gets the center point of the box.
Definition: AlignedBox.h:349
typename OverflowTrait< T >::Type OverflowType
An alias for the overflow trait.
Definition: AlignedBox.h:108
Vector< OverflowType, N > OverflowVectorType
An alias for the overflow vector type.
Definition: AlignedBox.h:112
bool Empty() const
Tests whether the box is empty.
Definition: AlignedBox.h:370
const VectorType & Minimum() const
Gets the box minimum corner point.
Definition: AlignedBox.h:381
void Reset()
Resets the box to empty.
Definition: AlignedBox.h:337
bool operator!=(const AlignedBox &box) const
Checks whether two boxes are not equal.
Definition: AlignedBox.h:474
typename std::array< VectorType, numCorners > CornerArrayType
An alias for the corner points array type.
Definition: AlignedBox.h:117
VectorType Size() const
Gets the size of the box.
Definition: AlignedBox.h:376
T ValueType
An alias for the box value type.
Definition: AlignedBox.h:106
Vector< ValueType, N > VectorType
An alias for the vector type of the box.
Definition: AlignedBox.h:110
bool Contains(const VectorType &point, T epsilon=T()) const
Tests whether the box contains a point.
Definition: AlignedBox.h:391
CornerArrayType Corners() const
Gets the corner points of the box.
const VectorType & Maximum() const
Gets the box maximum corner point.
Definition: AlignedBox.h:386
VectorType NearestPoint(const VectorType &point) const
Computes the nearest point on the box to a point.
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24
A specialization for 16-bit unsigned integers.
Definition: AlignedBox.h:72
uint32_t Type
An alias for uint32_t integer type.
Definition: AlignedBox.h:74
A specialization for 16-bit signed integers.
Definition: AlignedBox.h:65
int32_t Type
An alias for the int32_t integer type.
Definition: AlignedBox.h:67
A specialization for 32-bit unsigned integers.
Definition: AlignedBox.h:86
uint64_t Type
An alias for the uint64_t integer type.
Definition: AlignedBox.h:88
A specialization for 32-bit signed integers.
Definition: AlignedBox.h:79
int64_t Type
An alias for the int64_t integer type.
Definition: AlignedBox.h:81
A specialization for 8-bit unsigned integers.
Definition: AlignedBox.h:58
uint16_t Type
An alias for the uint16_t integer type.
Definition: AlignedBox.h:60
A specialization for 8-bit signed integers.
Definition: AlignedBox.h:51
int16_t Type
An alias for the int16_t integer type.
Definition: AlignedBox.h:53
Maps an integer type to the one that can handle arithmetic overflows.
Definition: AlignedBox.h:44
T Type
An alias for the integer type.
Definition: AlignedBox.h:46
Represents 3D vectors and points.
Definition: Vector.h:86
Vector3< bool > LessThan(Vector3< T > const &v) const
Checks whether the parameters of one vector are less than the parameters of the other vector.
Definition: Vector.h:142
T z
The Z component of the vector.
Definition: Vector.h:151
T y
The Y component of the vector.
Definition: Vector.h:149
T x
The X component of the vector.
Definition: Vector.h:147