16#if defined( _MSC_VER ) && !defined( __clang__ ) && defined( _M_ARM64 )
17#define MR_BOX_NO_VECTOR __pragma( loop( no_vector ) )
19#define MR_BOX_NO_VECTOR
31std::array<Vector3<T>, 8>
getCorners(
const Box<Vector3<T>> & box );
41 using Vb =
typename VTraits::template ChangeBaseType<bool>;
61 template <typename VV = V, typename std::enable_if_t<VectorTraits<VV>::supportNoInit,
int> = 0>
63 template <typename VV = V, typename std::enable_if_t<!VectorTraits<VV>::supportNoInit,
int> = 0>
102 for (
int i = 0; i <
elements; ++i )
125 for (
int i = 0; i <
elements; ++i )
134 for (
int i = 0; i <
elements; ++i )
139 lo = v < lo ? v : lo;
140 hi = hi < v ? v : hi;
148 for (
int i = 0; i <
elements; ++i )
154 lo = bLo < lo ? bLo : lo;
155 hi = hi < bHi ? bHi : hi;
162 for (
int i = 0; i <
elements; ++i )
171 for (
int i = 0; i <
elements; ++i )
182 for (
int i = 0; i <
elements; ++i )
190 for (
int i = 0; i <
elements; ++i )
202 for (
int i = 0; i <
elements; ++i )
217 for (
int i = 0; i <
elements; ++i )
229 for (
int i = 0; i <
elements; ++i )
248 T minDist = std::numeric_limits<T>::max();
252 for (
auto dim = 0; dim <
elements; ++dim )
254 for (
const auto& border : {
min,
max } )
274 return Box(
min - expansion,
max + expansion );
282 for (
int i = 0; i <
elements; ++i )
293 {
return !( *
this == a ); }
297 return s << box.
min <<
'\n' << box.
max;
302 return s >> box.
min >> box.
max;
310 assert( box.valid() );
313 Vector3<T>{ box.min.x, box.min.y, box.min.z },
314 Vector3<T>{ box.max.x, box.min.y, box.min.z },
315 Vector3<T>{ box.min.x, box.max.y, box.min.z },
316 Vector3<T>{ box.max.x, box.max.y, box.min.z },
317 Vector3<T>{ box.min.x, box.min.y, box.max.z },
318 Vector3<T>{ box.max.x, box.min.y, box.max.z },
319 Vector3<T>{ box.min.x, box.max.y, box.max.z },
327 assert( box.valid() );
343 auto maxCorner = minCorner;
344 for (
auto & v : maxCorner )
362 for (
int i = 0; i < Box<V>::elements; ++i )
364 const auto & row = xf.
A[i];
366 for (
int j = 0; j < Box<V>::elements; ++j )
368 const bool pos = row[j] >= 0;
369 lo[j] = pos ? box.
min[j] : box.
max[j];
370 hi[j] = pos ? box.
max[j] : box.
min[j];
372 res.
min[i] =
dot( row, lo ) + xf.
b[i];
373 res.
max[i] =
dot( row, hi ) + xf.
b[i];
388 return box.
max.x - box.
min.x;
395 return box.
max.y - box.
min.y;
402 return box.
max.z - box.
min.z;
413 auto boxDiag = box.max - box.min;
414 std::pair<float, int> ps[es];
415 for (
int i = 0; i < es; ++i )
416 ps[i] = { boxDiag[i], i };
419 for (
int i = 0; i + 1 < es; ++i )
420 for (
int j = i + 1; j < es; ++j )
422 std::swap( ps[i], ps[j] );
425 for (
int i = 0; i < es; ++i )
426 res[i] = ps[i].second;
431template<
size_t I,
typename V>
432constexpr const V&
get(
const Box<V>& box )
noexcept {
return box[int( I )]; }
433template<
size_t I,
typename V>
434constexpr V&
get(
Box<V>& box )
noexcept {
return box[int( I )]; }
443template<
size_t I,
typename V>
444struct tuple_element<I, MR::
Box<V>> {
using type = V; };
447struct tuple_size<MR::
Box<V>> : integral_constant<size_t, 2> {};
#define MR_BOX_NO_VECTOR
Definition MRBox.h:19
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:33
auto width(const Box< V > &box)
returns size along x axis
Definition MRBox.h:386
constexpr const V & get(const Box< V > &box) noexcept
get<0> returns min, get<1> returns max
Definition MRBox.h:432
std::array< Vector3< T >, 8 > getCorners(const Box< Vector3< T > > &box)
returns all corners of given box
Definition MRBox.h:308
auto findSortedBoxDims(const Box< V > &box) -> typename VectorTraits< V >::template ChangeBaseType< int >
Definition MRBox.h:410
auto height(const Box< V > &box)
returns size along y axis
Definition MRBox.h:393
auto depth(const Box< V > &box)
returns size along z axis
Definition MRBox.h:400
Box< V > transformed(const Box< V > &box, const AffineXf< V > &xf)
find the tightest box enclosing this one after transformation
Definition MRBox.h:355
MinMax< typename Box< V >::T > getTouchPlanes(const Box< V > &box, const V &n)
Definition MRBox.h:340
T nextUp(T x)
Definition MRNextUpDown.h:41
Box< T > MinMax
Definition MRMeshFwd.h:415
Box
Definition MRMeshFwd.h:395
constexpr auto sqr(T x) noexcept -> decltype(x *x)
squared value; the result type is the type of x*x, which is int for small integer types (char,...
Definition MRMeshFwd.h:799
auto dot(const Matrix2< T > &a, const Matrix2< T > &b) -> decltype(dot(a.x, b.x))
double-dot product: x = a : b
Definition MRMatrix2.h:142
static constexpr int size
Definition MRVectorTraits.h:22
T nextDown(T x)
Definition MRNextUpDown.h:55
static constexpr auto && getElem(int i, U &&value)
Definition MRVectorTraits.h:32
static constexpr bool supportNoInit
Definition MRVectorTraits.h:23
constexpr NoInit noInit
Definition MRMeshFwd.h:103
V b
Definition MRAffineXf.h:31
M A
Definition MRAffineXf.h:30
V BaseType
Definition MRVectorTraits.h:21
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRAffineXf.h:26
Box given by its min- and max- corners.
Definition MRBox.h:36
friend std::ostream & operator<<(std::ostream &s, const Box< T > &box)
Definition MRBox.h:295
Box(const T &min, const T &max)
Definition MRBox.h:52
typename VTraits::BaseType T
Definition MRBox.h:39
void include(const T &pt)
Definition MRBox.h:131
typename VTraits::template ChangeBaseType< bool > Vb
Definition MRBox.h:41
T getBoxClosestPointTo(const T &pt) const
Definition MRBox.h:178
T getDistanceSq(const Box &b) const
Definition MRBox.h:213
T diagonal() const
Definition MRBox.h:118
void include(const Box &b)
Definition MRBox.h:145
VectorTraits< Vb > VbTraits
if V is Vector3<T> then Vb is Vector3b
Definition MRBox.h:42
T getProjection(const T &pt) const
Definition MRBox.h:242
Box expanded(const T &expansion) const
Definition MRBox.h:271
T max
Definition MRBox.h:44
Box insignificantlyExpanded() const
Definition MRBox.h:278
static Vb getMaxBoxCorner(const T &n)
Definition MRBox.h:109
T corner(const Vb &c) const
Definition MRBox.h:89
T center() const
Definition MRBox.h:84
T getDistanceSq(const T &pt) const
Definition MRBox.h:225
T size() const
Definition MRBox.h:115
VectorTraits< V > VTraits
Definition MRBox.h:38
static Vb getMinBoxCorner(const T &n)
Definition MRBox.h:99
bool intersects(const Box &b) const
Definition MRBox.h:188
static constexpr int elements
Definition MRBox.h:40
T volume() const
Definition MRBox.h:121
static Box fromMinAndSize(const T &min, const T &size)
Definition MRBox.h:72
Box()
create invalid box by default
Definition MRBox.h:51
const V & operator[](int e) const
min/max access by 0/1 index
Definition MRBox.h:47
bool operator!=(const Box &a) const
Definition MRBox.h:292
T min
Definition MRBox.h:44
Box intersection(const Box &b) const
Definition MRBox.h:199
friend std::istream & operator>>(std::istream &s, Box< T > &box)
Definition MRBox.h:300
bool contains(const Box &otherbox) const
Definition MRBox.h:169
bool contains(const T &pt) const
Definition MRBox.h:160
Box & intersect(const Box &b)
Definition MRBox.h:209
bool valid() const
Definition MRBox.h:75
Box(NoInit)
Definition MRBox.h:62
bool operator==(const Box &a) const
Definition MRBox.h:290
Definition MRMeshFwd.h:102
Definition MRVector2.h:29
Definition MRVector3.h:33
Common traits for (mathematical) vectors.
Definition MRVectorTraits.h:18