1#ifndef DONUT_SHAPES_HPP
2#define DONUT_SHAPES_HPP
14template <length_t L,
typename T>
23template <length_t L,
typename T>
32template <length_t L,
typename T>
44template <length_t L,
typename T>
90template <length_t L,
typename T>
109template <length_t L,
typename T>
156template <length_t L,
typename T>
159 .
min = min(line.pointA, line.pointB),
160 .max = max(line.pointA, line.pointB),
171template <length_t L,
typename T>
201template <length_t L,
typename T>
204 .
min = min(capsule.centerLine.pointA, capsule.centerLine.pointB) -
Length<L, T>{capsule.radius},
205 .max = max(capsule.centerLine.pointA, capsule.centerLine.pointB) +
Length<L, T>{capsule.radius},
216template <length_t L,
typename T>
230 return static_cast<Box<2, T>>(rectangle);
242template <length_t L,
typename T>
244 return distance2(a.center, b.center) < length2(a.radius + b.radius);
270template <length_t L,
typename T>
272 for (length_t i = 0; i < L; ++i) {
273 if (a.min[i] >= b.max[i] || a.max[i] <= b.min[i]) {
359template <length_t L,
typename T>
361 return distance2(a.center, clamp(a.center, b.min, b.max)) < length2(a.radius);
373template <length_t L,
typename T>
471template <length_t L,
typename T>
473 const T combinedRadiusSquared = length2(a.radius + b.radius);
474 const vec<L, T> linePointAToPointB = b.centerLine.pointB - b.centerLine.pointA;
475 const vec<L, T> linePointAToSphereCenter = a.center - b.centerLine.pointA;
476 const T linePointAToSphereCenterAlongLine = dot(linePointAToSphereCenter, linePointAToPointB);
477 if (linePointAToSphereCenterAlongLine <= 0.0f) {
478 return length2(linePointAToSphereCenter) < combinedRadiusSquared;
480 const vec<L, T> linePointBToSphereCenter = a.center - b.centerLine.pointB;
481 const T linePointBToSphereCenterAlongLine = dot(linePointBToSphereCenter, linePointAToPointB);
482 if (linePointBToSphereCenterAlongLine >= 0.0f) {
483 return length2(linePointBToSphereCenter) < combinedRadiusSquared;
485 const vec<L, T> lineToSphereCenterOrthogonal = linePointAToSphereCenter - linePointAToPointB * (linePointAToSphereCenterAlongLine / length2(linePointAToPointB));
486 return length2(lineToSphereCenterOrthogonal) < combinedRadiusSquared;
498template <length_t L,
typename T>
540template <length_t L,
typename T>
554template <length_t L,
typename T>
587template <length_t L,
typename T>
589 return distance2(center, point) < length2(radius);
597template <length_t L,
typename T>
602template <length_t L,
typename T>
604 for (length_t i = 0; i < L; ++i) {
605 if (point[i] < min[i] || point[i] >= max[i]) {
Definition Application.hpp:9
vec< L, T > Point
Generic point in space.
Definition shapes.hpp:15
vec< L, T > Length
Generic length in space.
Definition shapes.hpp:24
constexpr Box< L, T > getAabbOf(const LineSegment< L, T > &line) noexcept
Get the axis-aligned bounding box of a line segment.
Definition shapes.hpp:157
constexpr bool intersects(const Sphere< L, T > &a, const Sphere< L, T > &b) noexcept
Check if two spheres intersect.
Definition shapes.hpp:243
Generic axis-aligned box shape with minimum and maximum extents.
Definition shapes.hpp:110
constexpr bool contains(const Point< L, T > &point) const noexcept
Check if a given point is contained within the extents of this box.
Definition shapes.hpp:603
Point< L, T > max
Position with the maximum coordinates of the box extents on each coordinate axis.
Definition shapes.hpp:112
Point< L, T > min
Position with the minimum coordinates of the box extents on each coordinate axis.
Definition shapes.hpp:111
Generic capsule shape with a center line segment and radius.
Definition shapes.hpp:91
T radius
Radius of the capsule from the center line.
Definition shapes.hpp:93
LineSegment< L, T > centerLine
Center line of the capsule.
Definition shapes.hpp:92
constexpr bool contains(const Point< L, T > &point) const noexcept
Check if a given point is contained within the extents of this capsule.
Definition shapes.hpp:598
Flat 2D circle shape with a center and radius.
Definition shapes.hpp:63
T radius
Radius of the circle.
Definition shapes.hpp:65
Point< 2, T > center
Position of the center of the circle.
Definition shapes.hpp:64
constexpr bool contains(const Point< 2, T > &point) const noexcept
Check if a given point is contained within the extents of this circle.
Definition shapes.hpp:593
Generic line segment between two points.
Definition shapes.hpp:33
Point< L, T > pointA
Position of the first point of the line segment.
Definition shapes.hpp:34
Point< L, T > pointB
Position of the second point of the line segment.
Definition shapes.hpp:35
Flat 2D axis-aligned rectangle shape with a position and size.
Definition shapes.hpp:128
Length< 2, T > size
Width and height of the rectangle.
Definition shapes.hpp:130
Point< 2, T > position
Position of the bottom left corner of the rectangle.
Definition shapes.hpp:129
constexpr bool contains(const Point< 2, T > &point) const noexcept
Check if a given point is contained within the extents of this rectangle.
Definition shapes.hpp:613
Generic sphere shape with a center and radius.
Definition shapes.hpp:45
T radius
Radius of the sphere.
Definition shapes.hpp:47
constexpr bool contains(const Point< L, T > &point) const noexcept
Check if a given point is contained within the extents of this sphere.
Definition shapes.hpp:588
Point< L, T > center
Position of the center of the sphere.
Definition shapes.hpp:46