4#ifndef GREM_CORE_GEOMETRY_HPP
5#define GREM_CORE_GEOMETRY_HPP
28template <
size_t N,
typename T>
37template <
size_t N,
typename T>
46template <
size_t N,
typename T>
48 static constexpr size_t RANK = N;
65 if (!inverseDistance) {
68 return Ray{.origin =
origin, .direction = difference * *inverseDistance, .maxDistance =
distance};
109template <
size_t N,
typename T>
122template <
size_t N,
typename T>
133template <
size_t N,
typename T>
135 static constexpr size_t RANK = N;
148template <
size_t N,
typename T>
150 static constexpr size_t RANK = N;
161 template <
typename U>
194 const vec<N, T> minIntersection = (
min - ray.origin) * ray.directionInverse;
195 const vec<N, T> maxIntersection = (
max - ray.origin) * ray.directionInverse;
200 if constexpr (N == 2) {
207 return t <= minLeave;
218 const vec<N, T> minIntersection = (
min - ray.origin) * ray.directionInverse;
219 const vec<N, T> maxIntersection = (
max - ray.origin) * ray.directionInverse;
224 if constexpr (N == 2) {
237 const vec<N, T> point = ray.origin + t * ray.direction;
239 .localOffset = point,
274 return {.min =
min - expansion, .max =
max + expansion};
298 static constexpr size_t RANK = 2;
309 template <
typename U>
340 return toBox().contains(point);
351 return toBox().intersects(ray);
362 return toBox().raycast(ray);
391 static constexpr size_t RANK = 2;
402 template <
typename U>
442 return toBox().contains(point);
453 return toBox().intersects(ray);
464 return toBox().raycast(ray);
493 static constexpr size_t RANK = 3;
504 template <
typename U>
535 return toBox().contains(point);
546 return toBox().intersects(ray);
557 return toBox().raycast(ray);
585template <
size_t N,
typename T>
587 static constexpr size_t RANK = N;
599 template <
typename U>
634 return !
raycast(ray).template is<RayMiss>();
645 if constexpr (N == 2) {
660 size_t farthestFrontFacingFaceIndex = 0;
661 for (
size_t faceIndex = 0; faceIndex < 3; ++faceIndex) {
662 const Point<N, T> facePoint = facePoints[faceIndex];
663 const vec<N, T> faceNormal = faceNormals[faceIndex];
665 const T faceNormalAlongRay =
dot(faceNormal, ray.direction);
666 const T rayOffsetFromFaceAlongFaceNormal =
dot(ray.origin - facePoint, faceNormal);
669 if (rayIsParallelWithFacePlane) {
670 const bool rayIsInFrontOfFacePlane = rayOffsetFromFaceAlongFaceNormal > T{};
671 if (rayIsInFrontOfFacePlane) {
682 const T t = -rayOffsetFromFaceAlongFaceNormal / faceNormalAlongRay;
684 const bool faceIsFrontFacing = faceNormalAlongRay < T{};
685 if (faceIsFrontFacing) {
687 if (t > closestBackFacingDistance) {
692 if (t > farthestFrontFacingDistance) {
693 farthestFrontFacingDistance = t;
694 farthestFrontFacingFaceIndex = faceIndex;
698 if (t < farthestFrontFacingDistance) {
703 if (t < closestBackFacingDistance) {
704 closestBackFacingDistance = t;
709 if (farthestFrontFacingDistance >= T{}) {
711 if (farthestFrontFacingDistance > ray.maxDistance) {
715 .localOffset = ray.origin + farthestFrontFacingDistance * ray.direction,
716 .distance = farthestFrontFacingDistance,
717 .normal =
tryNormalize(faceNormals[farthestFrontFacingFaceIndex]).value_or(-ray.direction),
721 if (closestBackFacingDistance >= T{}) {
733 const T nAlongRay =
dot(n, ray.direction);
737 const T d = T{1} / nAlongRay;
738 const T u = d *
dot(-q, ac);
739 const T v = d *
dot(q, ab);
740 if (u < T{} || v < T{} || u + v > T{1}) {
743 const T t = d *
dot(-n, ao);
744 if (t < T{} || t > ray.maxDistance) {
748 .localOffset = ray.origin + t * ray.direction,
771template <
size_t N,
typename T>
773 static constexpr size_t RANK = N;
785 template <
typename U>
819template <
size_t N,
typename T>
821 static constexpr size_t RANK = N;
832 template <
typename U>
867 const T offsetPerRadiiSquared =
length2(offsetPerRadii);
868 if (offsetPerRadiiSquared < T{1}) {
872 const T directionPerRadiiSquared =
length2(directionPerRadii);
873 const T offsetAlongDirectionPerRadii =
dot(offsetPerRadii, directionPerRadii);
874 const T discriminant =
length2(offsetAlongDirectionPerRadii) - directionPerRadiiSquared * (offsetPerRadiiSquared - T{1});
875 if (discriminant < T{}) {
878 const T t = (-offsetAlongDirectionPerRadii -
sqrt(discriminant)) / directionPerRadiiSquared;
879 return t >= T{} && t <= ray.maxDistance;
892 const T offsetPerRadiiSquared =
length2(offsetPerRadii);
893 if (offsetPerRadiiSquared < T{1}) {
897 const T directionPerRadiiSquared =
length2(directionPerRadii);
898 const T offsetAlongDirectionPerRadii =
dot(offsetPerRadii, directionPerRadii);
899 const T discriminant =
length2(offsetAlongDirectionPerRadii) - directionPerRadiiSquared * (offsetPerRadiiSquared - T{1});
900 if (discriminant < T{}) {
903 const T t = (-offsetAlongDirectionPerRadii -
sqrt(discriminant)) / directionPerRadiiSquared;
904 if (t < T{} || t > ray.maxDistance) {
907 const Point<N, T> point = ray.origin + t * ray.direction;
909 .localOffset = point,
944 static constexpr size_t RANK = 2;
955 template <
typename U>
1017template <
size_t N,
typename T>
1030 template <
typename U>
1049 constexpr operator Ellipse<T>() const noexcept requires(N == 2) {
1082 const T differenceAlongRay =
dot(difference, ray.direction);
1084 if (differenceOfSquares < T{}) {
1087 if (differenceAlongRay > T{}) {
1090 const T discriminant =
length2(differenceAlongRay) - differenceOfSquares;
1091 if (discriminant < T{}) {
1094 const T t = -differenceAlongRay -
sqrt(discriminant);
1095 return t >= T{} && t <= ray.maxDistance;
1107 const T differenceAlongRay =
dot(difference, ray.direction);
1109 if (differenceOfSquares < T{}) {
1112 if (differenceAlongRay > T{}) {
1115 const T discriminant =
length2(differenceAlongRay) - differenceOfSquares;
1116 if (discriminant < T{}) {
1119 const T t = -differenceAlongRay -
sqrt(discriminant);
1120 if (t < T{} || t > ray.maxDistance) {
1123 const Point<N, T> point = ray.origin + t * ray.direction;
1125 .localOffset = point,
1167template <
typename T>
1180 template <
typename U>
1270template <
size_t N,
typename T>
1283 template <
typename U>
1324template <
typename T>
1340 T{1}, T{0}, T{0}, T{0},
1341 T{0}, T{1}, T{0}, T{0},
1342 T{0}, T{0}, T{-1}, T{0},
1343 T{0}, T{0}, T{1}, T{1},
1349 T{1}, T{0}, T{0}, T{0},
1350 T{0}, T{1}, T{0}, T{0},
1351 T{0}, T{0}, T{2}, T{0},
1352 T{0}, T{0}, T{-1}, T{1},
1356 constexpr mat<4, 4, T> DEPTH_CONVERSION_MATRIX = CONVERT_DEPTH_FROM_ZO_TO_NO * CONVERT_DEPTH_REVERSE_RANGE;
1358 const mat<4, 4, T> transposedViewProjectionMatrix =
transpose(DEPTH_CONVERSION_MATRIX * viewProjectionMatrix);
1364 const vec<4, T> left = normalizeXYZ(transposedViewProjectionMatrix[3] + transposedViewProjectionMatrix[0]);
1365 const vec<4, T> right = normalizeXYZ(transposedViewProjectionMatrix[3] - transposedViewProjectionMatrix[0]);
1366 const vec<4, T> bottom = normalizeXYZ(transposedViewProjectionMatrix[3] + transposedViewProjectionMatrix[1]);
1367 const vec<4, T> top = normalizeXYZ(transposedViewProjectionMatrix[3] - transposedViewProjectionMatrix[1]);
1368 const vec<4, T> farPlane = normalizeXYZ(transposedViewProjectionMatrix[3] + transposedViewProjectionMatrix[2]);
1369 const vec<4, T> nearPlane = normalizeXYZ(transposedViewProjectionMatrix[3] - transposedViewProjectionMatrix[2]);
1371 const Array planeNormalCrossProducts{
1389 const Array planes{left, right, bottom, top, farPlane, nearPlane};
1392 getCorner<0, 2, 4>(
planes, planeNormalCrossProducts),
1393 getCorner<0, 3, 4>(
planes, planeNormalCrossProducts),
1394 getCorner<1, 2, 4>(
planes, planeNormalCrossProducts),
1395 getCorner<1, 3, 4>(
planes, planeNormalCrossProducts),
1396 getCorner<0, 2, 5>(
planes, planeNormalCrossProducts),
1397 getCorner<0, 3, 5>(
planes, planeNormalCrossProducts),
1398 getCorner<1, 2, 5>(
planes, planeNormalCrossProducts),
1399 getCorner<1, 3, 5>(
planes, planeNormalCrossProducts),
1472 template <
typename U>
1475 for (
size_t i = 0; i <
planes.size(); ++i) {
1478 for (
size_t i = 0; i <
corners.size(); ++i) {
1494 const Array aabbCorners{
1518 bool culled =
false;
1520 culled |=
dot(sphere.center,
vec<3, T>{plane}) + sphere.radius < -plane.w;
1526 [[nodiscard]]
static constexpr size_t getPlaneNormalCrossProductIndex(
size_t planeIndexA,
size_t planeIndexB)
noexcept {
1527 return planeIndexA * (9 - planeIndexA) / 2 + planeIndexB - 1;
1530 template <
size_t PlaneIndexA,
size_t PlaneIndexB,
size_t PlaneIndexC>
1531 [[nodiscard]]
static constexpr Point<3, T> getCorner(
Span<
const vec<4, T>, 6>
planes,
Span<
const vec<3, T>, 15> planeNormalCrossProducts)
noexcept {
1532 const vec<4, T>& a =
planes[PlaneIndexA];
1533 const vec<4, T>& b =
planes[PlaneIndexB];
1534 const vec<4, T>& c =
planes[PlaneIndexC];
1535 constexpr size_t ab = getPlaneNormalCrossProductIndex(PlaneIndexA, PlaneIndexB);
1536 constexpr size_t ac = getPlaneNormalCrossProductIndex(PlaneIndexA, PlaneIndexC);
1537 constexpr size_t bc = getPlaneNormalCrossProductIndex(PlaneIndexB, PlaneIndexC);
1538 const vec<3, T> axb = planeNormalCrossProducts[ab];
1539 const vec<3, T> axc = planeNormalCrossProducts[ac];
1540 const vec<3, T> bxc = planeNormalCrossProducts[bc];
1541 return (mat<3, 3, T>{bxc, axc, axb} * vec<3, T>{a.w, -b.w, c.w}) * (-1.0f /
dot(vec<3, T>{a}, bxc));
1550template <
typename T>
1562template <
typename T>
1572template <
typename T>
1582template <
typename T>
1594template <
size_t N,
typename T>
1596 if (points.empty()) {
1600 .min = points.front(),
1601 .max = points.front(),
1603 for (
const Point<N, T> vertex : points.subspan(1)) {
1617template <
size_t N,
typename T>
1623 return sqrt(result);
1636template <
size_t N,
typename T>
1640 const Length<N, T> halfExtents = localCenter - aabb.min;
1641 Box<N, T> result{.min = center, .max = center};
1642 for (
size_t y = 0; y < N; ++y) {
1643 for (
size_t x = 0; x < N; ++x) {
1644 const T a = transformation[y][x] * -halfExtents[y];
1645 const T b = transformation[y][x] * halfExtents[y];
1646 result.
min[x] +=
min(a, b);
1647 result.
max[x] +=
max(a, b);
1663 const auto sphereA = a.toSphere();
1664 const auto sphereB = b.toSphere();
1665 return distance2(sphereA.center, sphereB.center) <
length2(sphereA.radius + sphereB.radius);
1678 const auto boxA = a.toBox();
1679 const auto boxB = b.toBox();
1693 const auto sphereA = a.toSphere();
1694 const auto boxB = b.toBox();
1695 return distance2(sphereA.center,
clamp(sphereA.center, boxB.min, boxB.max)) <
length2(sphereA.radius);
1720template <
size_t N,
typename T>
1723 return (ray) ? a.intersects(*ray) : a.contains(b.pointA);
1735template <
size_t N,
typename T>
1749template <
typename T>
1752 const Circle<T> capsuleCircleA{.center = b.centerLine.pointA, .radius = b.radius};
1753 const Circle<T> capsuleCircleB{.center = b.centerLine.pointB, .radius = b.radius};
1762 return boxA.
getExpanded(boxExpansion).intersects(*ray);
1774template <
typename T>
1788template <
size_t N,
typename T>
1791 const T combinedRadiusSquared =
length2(sphereA.
radius + b.radius);
1792 const vec<N, T> linePointAToPointB = b.centerLine.pointB - b.centerLine.pointA;
1793 const vec<N, T> linePointAToSphereCenter = sphereA.
center - b.centerLine.pointA;
1794 const T linePointAToSphereCenterAlongLine =
dot(linePointAToSphereCenter, linePointAToPointB);
1795 if (linePointAToSphereCenterAlongLine <= 0.0f) {
1796 return length2(linePointAToSphereCenter) < combinedRadiusSquared;
1798 const vec<N, T> linePointBToSphereCenter = sphereA.
center - b.centerLine.pointB;
1799 const T linePointBToSphereCenterAlongLine =
dot(linePointBToSphereCenter, linePointAToPointB);
1800 if (linePointBToSphereCenterAlongLine >= 0.0f) {
1801 return length2(linePointBToSphereCenter) < combinedRadiusSquared;
1803 const vec<N, T> lineToSphereCenterOrthogonal = linePointAToSphereCenter - linePointAToPointB * (linePointAToSphereCenterAlongLine /
length2(linePointAToPointB));
1804 return length2(lineToSphereCenterOrthogonal) < combinedRadiusSquared;
1816template <
size_t N,
typename T>
1830template <
size_t N,
typename T>
1844template <
size_t N,
typename T>
1858template <
typename T>
1872template <
typename T>
1877template <
size_t N,
typename T>
#define GREM_ASSERT(expression)
Definition assertions.hpp:77
#define GREM_ALWAYS_INLINE
Definition attributes.hpp:10
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Definition StridedSpan.hpp:427
friend class Variant
Definition Variant.hpp:1402
Concept that checks if a given type is an axis-aligned box shape type.
Definition geometry.hpp:1563
Concept that checks if a given type is an axis-aligned ellipsoid shape type.
Definition geometry.hpp:1573
Definition concepts.hpp:47
Definition concepts.hpp:85
Concept that checks if a given type is a raycastable shape type.
Definition geometry.hpp:1551
Concept that checks if a given type is a spherical shape type.
Definition geometry.hpp:1583
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL length2(T a)
Definition math.hpp:1969
GREM_ALWAYS_INLINE constexpr bool GREM_VECTORCALL lessThan(T a, T b)
Definition math.hpp:1240
GREM_ALWAYS_INLINE constexpr T midpoint(T a, T b)
Get the midpoint between two values.
Definition fundamentals.hpp:559
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL distance(T a, T b)
Definition math.hpp:2038
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL flipSignIf(T value, bool flip)
Get a value with its sign flipped if a boolean is true.
Definition math.hpp:3983
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL sqrt(T a)
Get the square root of a value.
Definition math.hpp:1114
GREM_ALWAYS_INLINE constexpr vec< N, T > GREM_VECTORCALL normalize(vec< N, T > a)
Convert a vector to a unit vector of length 1 in the same direction.
Definition math.hpp:2057
constexpr Box< N, T > getTransformedBoundingBox(const mat< N+1, N+1, T > &transformation, const Box< N, T > &aabb) noexcept
Get the axis-aligned bounding box of an axis-aligned box with an affine transformation applied to it.
Definition geometry.hpp:1637
constexpr T calculateBoundingRadius(StridedSpan< const Point< N, T > > points) noexcept
Calculate the bounding radius from the origin of a set of points.
Definition geometry.hpp:1618
GREM_ALWAYS_INLINE constexpr decltype(auto) clamp(T &&value, Low &&minValue, High &&maxValue)
Clamp a value to a specific interval.
Definition fundamentals.hpp:630
GREM_ALWAYS_INLINE constexpr Optional< T > GREM_VECTORCALL tryDivide(T a, T b)
Try to divide a floating-point value by a scalar and produce a defined result.
Definition math.hpp:2101
GREM_ALWAYS_INLINE constexpr bool GREM_VECTORCALL greaterThan(T a, T b)
Definition math.hpp:1250
vec< N, T > Length
Generic length in N-dimensional space.
Definition geometry.hpp:38
constexpr bool intersects(const spherical_shape auto &a, const spherical_shape auto &b) noexcept
Check if two spherical shapes intersect.
Definition geometry.hpp:1662
GREM_ALWAYS_INLINE constexpr mat< R, C, T > transpose(const mat< C, R, T > &a)
Definition math.hpp:2247
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL cross(vec< 2, T > a, vec< 2, T > b)
Definition math.hpp:2426
GREM_ALWAYS_INLINE constexpr vec< N, T > GREM_VECTORCALL abs(vec< N, T > a)
Definition math.hpp:1386
constexpr bool noneOf(input_range auto &&range, auto predicate)
Definition algorithms.hpp:230
Span(R &&range) -> Span< std::remove_reference_t< decltype(*std::data(range))> >
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL distance2(T a, T b)
Definition math.hpp:2026
vec< N, T > Point
Generic point in N-dimensional space.
Definition geometry.hpp:29
GREM_ALWAYS_INLINE constexpr Optional< vec< N, T > > GREM_VECTORCALL tryNormalize(vec< N, T > a)
Try to convert a vector to a unit vector of length 1 in the same direction.
Definition math.hpp:2082
GREM_ALWAYS_INLINE constexpr vec< N, T > GREM_VECTORCALL trunc(vec< N, T > a)
Definition math.hpp:1420
GREM_ALWAYS_INLINE constexpr decltype(auto) max(A &&a, B &&b)
Get the greater of two values, or the first value if they are equivalent.
Definition fundamentals.hpp:598
GREM_ALWAYS_INLINE vec< N, bool > GREM_VECTORCALL signbit(vec< N, T > values)
Get the sign bits of the components of a vector.
Definition math.hpp:3584
GREM_ALWAYS_INLINE constexpr bool GREM_VECTORCALL greaterThanEqual(T a, T b)
Definition math.hpp:1255
GREM_ALWAYS_INLINE constexpr decltype(auto) min(A &&a, B &&b)
Get the smaller of two values, or the first value if they are equivalent.
Definition fundamentals.hpp:585
GREM_ALWAYS_INLINE constexpr bool GREM_VECTORCALL all(bool a)
Definition math.hpp:1285
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL length(T a)
Definition math.hpp:2001
constexpr bool allOf(input_range auto &&range, auto predicate)
Definition algorithms.hpp:226
constexpr Box< N, T > calculateBoundingBox(StridedSpan< const Point< N, T > > points) noexcept
Calculate the axis-aligned bounding box of a set of points.
Definition geometry.hpp:1595
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL dot(vec< 1, T > a, vec< 1, T > b)
Definition math.hpp:1942
Generic axis-aligned box shape with minimum and maximum extents in N-dimensional space.
Definition geometry.hpp:149
constexpr Box< N, T > getExpanded(T expansion) const noexcept
Get a version of the box that is symmetrically expanded by a certain amount.
Definition geometry.hpp:286
constexpr bool contains(const Point< N, T > &point) const noexcept
Check if a given point is contained within the extents of this box.
Definition geometry.hpp:182
constexpr Box< N, T > getExpanded(Length< N, T > expansion) const noexcept
Get a version of the box that is symmetrically expanded by a certain amount.
Definition geometry.hpp:272
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:150
Point< N, T > max
Position with the maximum coordinates of the box extents on each coordinate axis.
Definition geometry.hpp:154
bool operator==(const Box &other) const =default
Compare this box to another for equality.
constexpr Box< N, T > toBox() const noexcept
Convert this shape to an equivalent axis-aligned bounding box.
Definition geometry.hpp:259
constexpr RaycastResult< N, T > raycast(const Ray< N, T > &ray) const noexcept
Find the closest intersection of this box with a given ray.
Definition geometry.hpp:217
constexpr Box< N, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the box.
Definition geometry.hpp:250
constexpr bool intersects(const Ray< N, T > &ray) const noexcept
Check if this box intersects a given ray.
Definition geometry.hpp:193
T Component
Scalar coordinate component type.
Definition geometry.hpp:151
Point< N, T > min
Position with the minimum coordinates of the box extents on each coordinate axis.
Definition geometry.hpp:153
Generic capsule shape with a center line segment and radius in N-dimensional space.
Definition geometry.hpp:1271
constexpr Box< N, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the capsule.
Definition geometry.hpp:1311
T radius
Radius of the capsule from the center line.
Definition geometry.hpp:1276
bool operator==(const Capsule &other) const =default
Compare this capsule to another for equality.
LineSegment< N, T > centerLine
Center line of the capsule.
Definition geometry.hpp:1275
T Component
Scalar coordinate component type.
Definition geometry.hpp:1273
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:1272
constexpr bool contains(const Point< N, T > &point) const noexcept
Check if a given point is contained within the extents of this capsule.
Definition geometry.hpp:1878
Flat 2D circle shape with a center and radius.
Definition geometry.hpp:1168
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:1169
constexpr Sphere< 2, T > toSphere() const noexcept
Convert this shape to an equivalent sphere.
Definition geometry.hpp:1258
T Component
Scalar coordinate component type.
Definition geometry.hpp:1170
constexpr Ellipsoid< 2, T > toEllipsoid() const noexcept
Convert this shape to an equivalent ellipsoid.
Definition geometry.hpp:1249
T radius
Radius of the circle.
Definition geometry.hpp:1173
constexpr bool contains(const Point< 2, T > &point) const noexcept
Check if a given point is contained within the extents of this circle.
Definition geometry.hpp:1228
constexpr Box< 2, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the circle.
Definition geometry.hpp:1237
Point< 2, T > center
Position of the center of the circle.
Definition geometry.hpp:1172
bool operator==(const Circle &other) const =default
Compare this circle to another for equality.
3D axis-aligned cube shape with a position and width.
Definition geometry.hpp:492
constexpr bool contains(const Point< 3, T > &point) const noexcept
Check if a given point is contained within the extents of this cube.
Definition geometry.hpp:534
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:493
constexpr bool intersects(const Ray< 3, T > &ray) const noexcept
Check if this cube intersects a given ray.
Definition geometry.hpp:545
constexpr Box< 3, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the cube.
Definition geometry.hpp:565
T width
Width, height and depth of the cube.
Definition geometry.hpp:497
Point< 3, T > position
Position of the far bottom left corner of the cube.
Definition geometry.hpp:496
constexpr RaycastResult< 3, T > raycast(const Ray< 3, T > &ray) const noexcept
Find the closest intersection of this cube with a given ray.
Definition geometry.hpp:556
constexpr Box< 3, T > toBox() const noexcept
Convert this shape to an equivalent axis-aligned bounding box.
Definition geometry.hpp:574
T Component
Scalar coordinate component type.
Definition geometry.hpp:494
bool operator==(const Cube &other) const =default
Compare this cube to another for equality.
Flat 2D ellipse shape with a center and axis-aligned radii.
Definition geometry.hpp:943
Point< 2, T > center
Position of the center of the ellipse.
Definition geometry.hpp:947
Length< 2, T > radii
Radii of the ellipse along each axis.
Definition geometry.hpp:948
constexpr Ellipsoid< 2, T > toEllipsoid() const noexcept
Convert this shape to an equivalent ellipsoid.
Definition geometry.hpp:1006
T Component
Scalar coordinate component type.
Definition geometry.hpp:945
constexpr bool contains(const Point< 2, T > &point) const noexcept
Check if a given point is contained within the extents of this ellipse.
Definition geometry.hpp:985
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:944
constexpr Box< 2, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the ellipse.
Definition geometry.hpp:994
bool operator==(const Ellipse &other) const =default
Compare this ellipse to another for equality.
Generic ellipsoid shape with a center and axis-aligned radii in N-dimensional space.
Definition geometry.hpp:820
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:821
constexpr bool intersects(const Ray< N, T > &ray) const noexcept
Check if this ellipsoid intersects a given ray.
Definition geometry.hpp:864
Length< N, T > radii
Radii of the ellipsoid along each axis.
Definition geometry.hpp:825
constexpr Ellipsoid< N, T > toEllipsoid() const noexcept
Convert this shape to an equivalent ellipsoid.
Definition geometry.hpp:932
Point< N, T > center
Position of the center of the ellipsoid.
Definition geometry.hpp:824
constexpr RaycastResult< N, T > raycast(const Ray< N, T > &ray) const noexcept
Find the closest intersection of this ellipsoid with a given ray.
Definition geometry.hpp:889
constexpr Box< N, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the sphere.
Definition geometry.hpp:920
bool operator==(const Ellipsoid &other) const =default
Compare this ellipsoid to another for equality.
T Component
Scalar coordinate component type.
Definition geometry.hpp:822
constexpr bool contains(const Point< N, T > &point) const noexcept
Check if a given point is contained within the extents of this ellipsoid.
Definition geometry.hpp:853
Truncated pyramid shape in 3D space.
Definition geometry.hpp:1325
constexpr bool isPotentiallyIntersecting(const Box< 3, T > &aabb) const noexcept
Check if an axis-aligned bounding box is potentially intersecting with the frustum.
Definition geometry.hpp:1493
Array< Point< 3, T >, 8 > corners
Positions of the 8 corners of the frustum, in the following order:
Definition geometry.hpp:1465
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:1326
Array< vec< 4, T >, 6 > planes
Plane equation coefficients of the 6 planes of the frustum, pointing inwards, in the following order:
Definition geometry.hpp:1452
static constexpr Frustum fromViewProjectionMatrix(const mat< 4, 4, T > &viewProjectionMatrix) noexcept
Create a world-space view frustum from a combined view-projection matrix.
Definition geometry.hpp:1337
static constexpr Frustum fromCorners(StridedSpan< const Point< 3, T >, 8 > corners)
Create a frustum from its corners.
Definition geometry.hpp:1424
T Component
Scalar coordinate component type.
Definition geometry.hpp:1327
constexpr bool isPotentiallyIntersecting(const Sphere< 3, T > &sphere) const noexcept
Check if a sphere is potentially intersecting with the frustum.
Definition geometry.hpp:1517
Definition fundamentals.hpp:27
static constexpr T MAX
Definition fundamentals.hpp:29
static constexpr T MIN
Definition fundamentals.hpp:28
Generic line segment between two points in N-dimensional space.
Definition geometry.hpp:772
constexpr Box< N, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the line segment.
Definition geometry.hpp:804
Point< N, T > pointB
Position of the second point of the line segment.
Definition geometry.hpp:777
Point< N, T > pointA
Position of the first point of the line segment.
Definition geometry.hpp:776
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:773
T Component
Scalar coordinate component type.
Definition geometry.hpp:774
bool operator==(const LineSegment &other) const =default
Compare this line segment to another for equality.
Result of an interor raycast hit.
Definition geometry.hpp:123
vec< N, T > localOffset
Offset from the object's center of mass in shape-local space at which the hit occured.
Definition geometry.hpp:124
Result of a raycast hit.
Definition geometry.hpp:110
vec< N, T > normal
Unit normal vector of the surface that was hit.
Definition geometry.hpp:113
vec< N, T > localOffset
Offset from the object's center of mass in shape-local space at which the hit occured.
Definition geometry.hpp:111
T distance
Distance from the ray origin, along the ray direction, at which the hit occured.
Definition geometry.hpp:112
Result of a raycast miss.
Definition geometry.hpp:101
Generic ray with an origin and direction in N-dimensional space.
Definition geometry.hpp:47
vec< N, T > direction
Unit vector pointing in the direction of the ray.
Definition geometry.hpp:81
Point< N, T > origin
Starting position of the ray.
Definition geometry.hpp:74
static constexpr Optional< Ray > between(Point< N, T > origin, Point< N, T > destination)
Create a ray between two points.
Definition geometry.hpp:61
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:48
T maxDistance
Maximum hit distance of the ray.
Definition geometry.hpp:88
T Component
Scalar coordinate component type.
Definition geometry.hpp:49
vec< N, T > directionInverse
Component-wise reciprocal of the ray direction.
Definition geometry.hpp:95
Result of a raycast.
Definition geometry.hpp:134
T Component
Scalar coordinate component type.
Definition geometry.hpp:136
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:135
Flat 2D axis-aligned rectangle shape with a position and size.
Definition geometry.hpp:297
constexpr Box< 2, T > toBox() const noexcept
Convert this shape to an equivalent axis-aligned bounding box.
Definition geometry.hpp:379
constexpr RaycastResult< 2, T > raycast(const Ray< 2, T > &ray) const noexcept
Find the closest intersection of this rectangle with a given ray.
Definition geometry.hpp:361
T Component
Scalar coordinate component type.
Definition geometry.hpp:299
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:298
constexpr Box< 2, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the rectangle.
Definition geometry.hpp:370
constexpr bool intersects(const Ray< 2, T > &ray) const noexcept
Check if this rectangle intersects a given ray.
Definition geometry.hpp:350
Point< 2, T > position
Position of the bottom left corner of the rectangle.
Definition geometry.hpp:301
constexpr bool contains(const Point< 2, T > &point) const noexcept
Check if a given point is contained within the extents of this rectangle.
Definition geometry.hpp:339
bool operator==(const Rectangle &other) const =default
Compare this rectangle to another for equality.
Length< 2, T > size
Width and height of the rectangle.
Definition geometry.hpp:302
Generic sphere shape with a center and radius in N-dimensional space.
Definition geometry.hpp:1018
constexpr Ellipsoid< N, T > toEllipsoid() const noexcept
Convert this shape to an equivalent ellipsoid.
Definition geometry.hpp:1148
bool operator==(const Sphere &other) const =default
Compare this sphere to another for equality.
constexpr bool intersects(const Ray< N, T > &ray) const noexcept
Check if this sphere intersects a given ray.
Definition geometry.hpp:1080
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:1019
constexpr RaycastResult< N, T > raycast(const Ray< N, T > &ray) const noexcept
Find the closest intersection of this sphere with a given ray.
Definition geometry.hpp:1105
T radius
Radius of the sphere.
Definition geometry.hpp:1023
constexpr bool contains(const Point< N, T > &point) const noexcept
Check if a given point is contained within the extents of this sphere.
Definition geometry.hpp:1069
Point< N, T > center
Position of the center of the sphere.
Definition geometry.hpp:1022
constexpr Box< N, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the sphere.
Definition geometry.hpp:1136
constexpr Sphere< N, T > toSphere() const noexcept
Convert this shape to an equivalent sphere.
Definition geometry.hpp:1157
T Component
Scalar coordinate component type.
Definition geometry.hpp:1020
Flat 2D axis-aligned square shape with a position and width.
Definition geometry.hpp:390
constexpr bool contains(const Point< 2, T > &point) const noexcept
Check if a given point is contained within the extents of this square.
Definition geometry.hpp:441
constexpr RaycastResult< 2, T > raycast(const Ray< 2, T > &ray) const noexcept
Find the closest intersection of this square with a given ray.
Definition geometry.hpp:463
constexpr Box< 2, T > toBox() const noexcept
Convert this shape to an equivalent axis-aligned bounding box.
Definition geometry.hpp:481
bool operator==(const Square &other) const =default
Compare this square to another for equality.
Point< 2, T > position
Position of the bottom left corner of the square.
Definition geometry.hpp:394
T width
Width and height of the square.
Definition geometry.hpp:395
constexpr Box< 2, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the square.
Definition geometry.hpp:472
T Component
Scalar coordinate component type.
Definition geometry.hpp:392
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:391
constexpr bool intersects(const Ray< 2, T > &ray) const noexcept
Check if this square intersects a given ray.
Definition geometry.hpp:452
Generic triangle shape in N-dimensional space.
Definition geometry.hpp:586
constexpr bool contains(const Point< N, T > &point) const noexcept
Check if a given point is contained within the extents of this triangle.
Definition geometry.hpp:620
Point< N, T > pointB
Second point of the triangle.
Definition geometry.hpp:591
bool operator==(const Triangle &other) const =default
Compare this triangle to another for equality.
constexpr Box< N, T > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the triangle.
Definition geometry.hpp:760
Point< N, T > pointC
Third point of the triangle.
Definition geometry.hpp:592
static constexpr size_t RANK
Number of dimensions of the vector space.
Definition geometry.hpp:587
constexpr bool intersects(const Ray< N, T > &ray) const noexcept
Check if this triangle intersects a given ray.
Definition geometry.hpp:633
constexpr RaycastResult< N, T > raycast(const Ray< N, T > &ray) const noexcept
Find the closest intersection of this triangle with a given ray.
Definition geometry.hpp:644
T Component
Scalar coordinate component type.
Definition geometry.hpp:588
Point< N, T > pointA
First point of the triangle.
Definition geometry.hpp:590