11 #define CA_SUPPRESS(x)
15 #include <AtomsUtils/Globals.h>
16 #include <AtomsMath/ImathExport.h>
17 #include <AtomsMath/ImathConfig.h>
18 #include <AtomsMath/ImathVec.h>
19 #include <AtomsMath/ImathVecAlgo.h>
20 #include <AtomsMath/ImathMatrix.h>
21 #include <AtomsMath/ImathMatrixAlgo.h>
22 #include <AtomsMath/ImathQuat.h>
23 #include <AtomsMath/ImathEuler.h>
24 #include <AtomsMath/ImathBox.h>
25 #include <AtomsMath/ImathColor.h>
26 #include <AtomsMath/ImathLine.h>
27 #include <AtomsMath/ImathSphere.h>
28 #include <AtomsMath/ImathRandom.h>
29 #include <AtomsMath/ImathBoxAlgo.h>
40 using Vector2 = ATOMSMATH_NAMESPACE::V2d;
41 using Vector2f = ATOMSMATH_NAMESPACE::V2f;
42 using Vector2i = ATOMSMATH_NAMESPACE::V2i;
43 using Vector3 = ATOMSMATH_NAMESPACE::V3d;
44 using Vector3f = ATOMSMATH_NAMESPACE::V3f;
45 using Vector3i = ATOMSMATH_NAMESPACE::V3i;
46 using Vector4 = ATOMSMATH_NAMESPACE::V4d;
47 using Vector4f = ATOMSMATH_NAMESPACE::V4f;
48 using Vector4i = ATOMSMATH_NAMESPACE::V4i;
49 using Matrix = ATOMSMATH_NAMESPACE::M44d;
50 using Matrixf = ATOMSMATH_NAMESPACE::M44f;
51 using Matrix33 = ATOMSMATH_NAMESPACE::M33d;
52 using Matrix33f = ATOMSMATH_NAMESPACE::M33f;
53 using Quaternion = ATOMSMATH_NAMESPACE::Quatd;
54 using Quaternionf = ATOMSMATH_NAMESPACE::Quatf;
55 using Euler = ATOMSMATH_NAMESPACE::Eulerd;
56 using Eulerf = ATOMSMATH_NAMESPACE::Eulerf;
57 using Box2 = ATOMSMATH_NAMESPACE::Box2d;
58 using Box2f = ATOMSMATH_NAMESPACE::Box2f;
59 using Box2i = ATOMSMATH_NAMESPACE::Box2i;
60 using Box3 = ATOMSMATH_NAMESPACE::Box3d;
61 using Box3f = ATOMSMATH_NAMESPACE::Box3f;
62 using Box3i = ATOMSMATH_NAMESPACE::Box3i;
63 using Color3c = ATOMSMATH_NAMESPACE::Color3c;
64 using Color3f = ATOMSMATH_NAMESPACE::Color3f;
65 using Color4c = ATOMSMATH_NAMESPACE::Color4c;
66 using Color4f = ATOMSMATH_NAMESPACE::Color4f;
67 using Line3 = ATOMSMATH_NAMESPACE::Line3d ;
68 using Line3f = ATOMSMATH_NAMESPACE::Line3f;
69 using Line2 = ATOMSMATH_NAMESPACE::Line2d;
70 using Line2f = ATOMSMATH_NAMESPACE::Line2f;
71 using Sphere3 = ATOMSMATH_NAMESPACE::Sphere3d;
72 using Sphere3f = ATOMSMATH_NAMESPACE::Sphere3f;
74 typedef ATOMSMATH_NAMESPACE::V2d Vector2;
75 typedef ATOMSMATH_NAMESPACE::V2f Vector2f;
76 typedef ATOMSMATH_NAMESPACE::V2i Vector2i;
77 typedef ATOMSMATH_NAMESPACE::V3d Vector3;
78 typedef ATOMSMATH_NAMESPACE::V3f Vector3f;
79 typedef ATOMSMATH_NAMESPACE::V3i Vector3i;
80 typedef ATOMSMATH_NAMESPACE::V4d Vector4;
81 typedef ATOMSMATH_NAMESPACE::V4f Vector4f;
82 typedef ATOMSMATH_NAMESPACE::V4i Vector4i;
83 typedef ATOMSMATH_NAMESPACE::M44d Matrix;
84 typedef ATOMSMATH_NAMESPACE::M44f Matrixf;
85 typedef ATOMSMATH_NAMESPACE::M33d
Matrix33;
86 typedef ATOMSMATH_NAMESPACE::M33f Matrix33f;
87 typedef ATOMSMATH_NAMESPACE::Quatd Quaternion;
88 typedef ATOMSMATH_NAMESPACE::Quatf Quaternionf;
89 typedef ATOMSMATH_NAMESPACE::Eulerd
Euler;
91 typedef ATOMSMATH_NAMESPACE::Box2d Box2;
94 typedef ATOMSMATH_NAMESPACE::Box3d Box3;
97 typedef ATOMSMATH_NAMESPACE::Color3c
Color3c;
99 typedef ATOMSMATH_NAMESPACE::Color4c
Color4c;
102 typedef ATOMSMATH_NAMESPACE::Line3d
Line3;
105 typedef ATOMSMATH_NAMESPACE::Line2d
Line2;
106 typedef ATOMSMATH_NAMESPACE::Line2f
Line2f;
108 typedef ATOMSMATH_NAMESPACE::Sphere3d
Sphere3;
120 return (a < l) ? l : ((a > h) ? h : a);
124 template <
class T,
class W>
126 clip(
const T& p,
const W& box)
135 for (
int i = 0; i < int(box.min.dimensions()); i++)
137 if (p[i] < box.min[i])
139 else if (p[i] > box.max[i])
149 template <
class T,
class W>
151 closestPointInBox(
const T& p,
const W& box)
156 template<
typename T,
typename W>
157 inline typename T::BaseType distanceSq(
const T& point,
const W& box)
159 auto p = closestPointInBox(point, box);
160 return (p - point).length2();
163 template<
typename T,
typename W>
164 inline typename T::BaseType distanceSq(
const T& point,
const W& box)
166 auto p = closestPointInBox(point, box);
167 return (p - point).length2();
171 ATOMSUTILS_EXPORT
double getConvexPolyCross(
const AtomsMath::Vector2f &O,
const AtomsMath::Vector2f &A,
const AtomsMath::Vector2f &B);
173 ATOMSUTILS_EXPORT std::vector<AtomsMath::Vector2f> getConvexPoly(std::vector<AtomsMath::Vector2f> P);
176 T closestPointToSegment(
const T& P0,
const T& P1,
const T& point)
178 auto lineDir = P1 - P0;
179 auto lineLength = lineDir.length();
181 auto dotValue = (point - P0).dot(lineDir);
182 dotValue = dotValue > lineLength ? lineLength : dotValue;
183 dotValue = dotValue < 0.0f ? 0.0f : dotValue;
184 return P0 + lineDir * dotValue;
188 inline typename T::BaseType distanceToSegment(
const T& P0,
const T& P1,
const T& point)
190 return (closestPointToSegment(P0, P1, point) - point).length();
193 inline AtomsMath::Vector2f flatVector3(
const AtomsMath::Vector3& in) {
return AtomsMath::Vector2f(
static_cast<float>(in.x),
static_cast<float>(in.z)); }
198 static _Ty(min)() noexcept {
199 return std::numeric_limits<_Ty>::min();
202 static _Ty(max)() noexcept {
203 return std::numeric_limits<_Ty>::max();
211 static const char* (min)() noexcept {
215 static const char* (max)() noexcept {
224 static Matrix(min)() noexcept {
228 static Matrix(max)() noexcept {
237 static Vector2(min)() noexcept {
238 return Vector2(std::numeric_limits<float>::min());
241 static Vector2(max)() noexcept {
242 return Vector2(std::numeric_limits<float>::max());
250 static Vector3(min)() noexcept {
251 return Vector3(std::numeric_limits<float>::min());
254 static Vector3(max)() noexcept {
255 return Vector3(std::numeric_limits<float>::max());
263 static Vector4(min)() noexcept {
264 return Vector4(std::numeric_limits<float>::min());
267 static Vector4(max)() noexcept {
268 return Vector4(std::numeric_limits<float>::max());
276 static Quaternion(min)() noexcept {
280 static Quaternion(max)() noexcept {
289 static Euler(min)() noexcept {
293 static Euler(max)() noexcept {
302 static Vector2f(min)() noexcept {
303 return Vector2f(std::numeric_limits<float>::min());
306 static Vector2f(max)() noexcept {
307 return Vector2f(std::numeric_limits<float>::max());
315 static Vector3f(min)() noexcept {
316 return Vector3f(std::numeric_limits<float>::min());
319 static Vector3f(max)() noexcept {
320 return Vector3f(std::numeric_limits<float>::max());
328 static Vector4f(min)() noexcept {
329 return Vector4f(std::numeric_limits<float>::min());
332 static Vector4f(max)() noexcept {
333 return Vector4f(std::numeric_limits<float>::max());
342 static _Ty value(ATOMSMATH_NAMESPACE::Rand48& random,
const _Ty& minVal,
const _Ty& maxVal) noexcept {
351 static int(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const int& minValue,
const int& maxValue) noexcept {
352 if (maxValue > minValue)
353 return random.nexti() % (maxValue - minValue) + minValue;
354 else if (maxValue < minValue)
355 return random.nexti() % (minValue - maxValue) + maxValue;
365 static float(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const float& minValue,
const float& maxValue) noexcept {
366 return static_cast<float>(random.nextf(minValue, maxValue));
374 static double(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const double& minValue,
const double& maxValue) noexcept {
375 return random.nextf(minValue, maxValue);
383 static bool(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const bool& minValue,
const bool& maxValue) noexcept {
384 return minValue != maxValue ? random.nextb() : minValue;
392 static Vector2(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Vector2& minValue,
const Vector2& maxValue) noexcept {
394 random.nextf(minValue.x, maxValue.x),
395 random.nextf(minValue.y, maxValue.y));
403 static Vector3(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Vector3& minValue,
const Vector3& maxValue) noexcept {
405 random.nextf(minValue.x, maxValue.x),
406 random.nextf(minValue.y, maxValue.y),
407 random.nextf(minValue.z, maxValue.z));
415 static Vector4(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Vector4& minValue,
const Vector4& maxValue) noexcept {
417 random.nextf(minValue.x, maxValue.x),
418 random.nextf(minValue.y, maxValue.y),
419 random.nextf(minValue.z, maxValue.z),
420 random.nextf(minValue.w, maxValue.w));
428 static Vector2f(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Vector2f& minValue,
const Vector2f& maxValue) noexcept {
430 static_cast<float>(random.nextf(minValue.x, maxValue.x)),
431 static_cast<float>(random.nextf(minValue.y, maxValue.y)));
439 static Vector3f(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Vector3f& minValue,
const Vector3f& maxValue) noexcept {
441 static_cast<float>(random.nextf(minValue.x, maxValue.x)),
442 static_cast<float>(random.nextf(minValue.y, maxValue.y)),
443 static_cast<float>(random.nextf(minValue.z, maxValue.z)));
451 static Vector4f(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Vector4f& minValue,
const Vector4f& maxValue) noexcept {
453 static_cast<float>(random.nextf(minValue.x, maxValue.x)),
454 static_cast<float>(random.nextf(minValue.y, maxValue.y)),
455 static_cast<float>(random.nextf(minValue.z, maxValue.z)),
456 static_cast<float>(random.nextf(minValue.w, maxValue.w)));
464 static Matrix(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Matrix& m_minValue,
const Matrix& m_maxValue) noexcept {
466 random.nextf(m_minValue[0][0], m_maxValue[0][0]), random.nextf(m_minValue[0][1], m_maxValue[0][1]), random.nextf(m_minValue[0][2], m_maxValue[0][2]), random.nextf(m_minValue[0][3], m_maxValue[0][3]),
467 random.nextf(m_minValue[1][0], m_maxValue[1][0]), random.nextf(m_minValue[1][1], m_maxValue[1][1]), random.nextf(m_minValue[1][2], m_maxValue[1][2]), random.nextf(m_minValue[1][3], m_maxValue[1][3]),
468 random.nextf(m_minValue[2][0], m_maxValue[2][0]), random.nextf(m_minValue[2][1], m_maxValue[2][1]), random.nextf(m_minValue[2][2], m_maxValue[2][2]), random.nextf(m_minValue[2][3], m_maxValue[2][3]),
469 random.nextf(m_minValue[3][0], m_maxValue[3][0]), random.nextf(m_minValue[3][1], m_maxValue[3][1]), random.nextf(m_minValue[3][2], m_maxValue[3][2]), random.nextf(m_minValue[3][3], m_maxValue[3][3]));
477 static Matrixf(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Matrixf& m_minValue,
const Matrixf& m_maxValue) noexcept {
479 static_cast<float>(random.nextf(m_minValue[0][0], m_maxValue[0][0])),
static_cast<float>(random.nextf(m_minValue[0][1], m_maxValue[0][1])),
static_cast<float>(random.nextf(m_minValue[0][2], m_maxValue[0][2])),
static_cast<float>(random.nextf(m_minValue[0][3], m_maxValue[0][3])),
480 static_cast<float>(random.nextf(m_minValue[1][0], m_maxValue[1][0])),
static_cast<float>(random.nextf(m_minValue[1][1], m_maxValue[1][1])),
static_cast<float>(random.nextf(m_minValue[1][2], m_maxValue[1][2])),
static_cast<float>(random.nextf(m_minValue[1][3], m_maxValue[1][3])),
481 static_cast<float>(random.nextf(m_minValue[2][0], m_maxValue[2][0])),
static_cast<float>(random.nextf(m_minValue[2][1], m_maxValue[2][1])),
static_cast<float>(random.nextf(m_minValue[2][2], m_maxValue[2][2])),
static_cast<float>(random.nextf(m_minValue[2][3], m_maxValue[2][3])),
482 static_cast<float>(random.nextf(m_minValue[3][0], m_maxValue[3][0])),
static_cast<float>(random.nextf(m_minValue[3][1], m_maxValue[3][1])),
static_cast<float>(random.nextf(m_minValue[3][2], m_maxValue[3][2])),
static_cast<float>(random.nextf(m_minValue[3][3], m_maxValue[3][3])));
490 static Quaternion(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Quaternion& minValue,
const Quaternion& maxValue) noexcept {
492 random.nextf(minValue.r, maxValue.r),
493 random.nextf(minValue.v.x, maxValue.v.x),
494 random.nextf(minValue.v.y, maxValue.v.y),
495 random.nextf(minValue.v.z, maxValue.v.z)
504 static Quaternionf(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Quaternionf& minValue,
const Quaternionf& maxValue) noexcept {
506 static_cast<float>(random.nextf(minValue.r, maxValue.r)),
507 static_cast<float>(random.nextf(minValue.v.x, maxValue.v.x)),
508 static_cast<float>(random.nextf(minValue.v.y, maxValue.v.y)),
509 static_cast<float>(random.nextf(minValue.v.z, maxValue.v.z))
518 static Euler(value)(ATOMSMATH_NAMESPACE::Rand48& random,
const Euler& minValue,
const Euler& maxValue) noexcept {
520 static_cast<float>(random.nextf(minValue.x, maxValue.x)),
521 static_cast<float>(random.nextf(minValue.y, maxValue.y)),
522 static_cast<float>(random.nextf(minValue.z, maxValue.z)));
526 ATOMSUTILS_EXPORT
bool isBoundingBoxVisible(
const AtomsMath::Box3& bbox,
const AtomsMath::Matrix& cameraWorldMatrix,
const AtomsMath::Matrix& cameraProjectionMatrix,
bool isOrtho,
double overscanX = 0.0,
double overscanY = 0.0,
double overscanZ=0.0);
527 ATOMSUTILS_EXPORT
bool isPointVisible(
const AtomsMath::Vector3& point,
const AtomsMath::Matrix& cameraWorldMatrix,
const AtomsMath::Matrix& cameraProjectionMatrix,
bool isOrtho,
double overscanX = 0.0,
double overscanY = 0.0,
double overscanZ = 0.0);
Definition: AtomsMath.h:340
Definition: AtomsMath.h:196
Definition: ImathBox.h:36
Definition: ImathColor.h:29
Definition: ImathColor.h:115
Definition: ImathEuler.h:118
Definition: ImathLine.h:180
Definition: ImathLine.h:25
Definition: ImathMatrix.h:305
Definition: ImathSphere.h:25