42#ifndef UFO_GEOMETRY_CAPSULE_HPP
43#define UFO_GEOMETRY_CAPSULE_HPP
46#include <ufo/geometry/aabb.hpp>
47#include <ufo/numeric/vec.hpp>
66template <std::
size_t Dim = 3, std::
floating_po
int T =
float>
111 template <std::convertible_to<T> U>
115 ,
radius(
static_cast<T
>(other.radius))
123 [[nodiscard]]
static constexpr std::size_t
dimension() noexcept {
return Dim; }
165 [[nodiscard]]
constexpr T
volume() const noexcept
168 if constexpr (1 == Dim) {
170 }
else if constexpr (2 == Dim) {
172 }
else if constexpr (3 == Dim) {
174 return std::numbers::pi_v<T> * r2 * h +
175 (T(4) / T(3)) * std::numbers::pi_v<T> * r2 *
radius;
192template <std::
size_t Dim, std::
floating_po
int T>
198template <std::
size_t Dim, std::
floating_po
int T>
201 return out <<
"Start: [" << capsule.
start <<
"], End: [" << capsule.
end
202 <<
"], Radius: " << capsule.
radius;
205template <std::
floating_po
int T>
206using Capsule1 = Capsule<1, T>;
207template <std::
floating_po
int T>
208using Capsule2 = Capsule<2, T>;
209template <std::
floating_po
int T>
210using Capsule3 = Capsule<3, T>;
211template <std::
floating_po
int T>
212using Capsule4 = Capsule<4, T>;
214using Capsule1f = Capsule<1, float>;
215using Capsule2f = Capsule<2, float>;
216using Capsule3f = Capsule<3, float>;
217using Capsule4f = Capsule<4, float>;
219using Capsule1d = Capsule<1, double>;
220using Capsule2d = Capsule<2, double>;
221using Capsule3d = Capsule<3, double>;
222using Capsule4d = Capsule<4, double>;
226template <std::
size_t Dim, std::
floating_po
int T>
227 requires std::formattable<T, char>
228struct std::formatter<
ufo::Capsule<Dim, T>> {
229 constexpr auto parse(std::format_parse_context& ctx) {
return ctx.begin(); }
233 return std::format_to(ctx.out(),
"Start: [{}], End: [{}], Radius: {}", capsule.
start,
All vision-related classes and functions.
constexpr T length(Vec< Dim, T > const &v) noexcept
Computes the Euclidean length (magnitude) of a vector.
constexpr Vec< Geometry::dimension(), typename Geometry::value_type > max(Geometry const &g)
Returns the maximum coordinate of the minimum spanning axis-aligned bounding box of a geometry.
constexpr Vec< Geometry::dimension(), typename Geometry::value_type > min(Geometry const &g)
Returns the minimum coordinate of the minimum spanning axis-aligned bounding box of a geometry.
Axis-Aligned Bounding Box (AABB) in Dim-dimensional space.
Capsule in Dim-dimensional space.
static constexpr std::size_t dimension() noexcept
Returns the dimensionality of the capsule.
constexpr T length() const noexcept
Returns the length of the segment between start and end.
Vec< Dim, T > end
The end point of the capsule segment.
Vec< Dim, T > start
The start point of the capsule segment.
constexpr Capsule(Capsule< Dim, U > const &other) noexcept
Converting constructor from a capsule with a different scalar type.
bool operator==(Capsule const &) const =default
Equality operator.
constexpr bool isDegenerate() const noexcept
Returns whether the capsule is degenerate.
constexpr T diameter() const noexcept
Returns the diameter of the capsule.
constexpr AABB< Dim, T > aabb() const noexcept
Returns the AABB of the capsule.
T radius
The radius of the capsule.
constexpr T volume() const noexcept
Returns the volume (or area/length) of the capsule.
constexpr Capsule(Capsule const &) noexcept=default
Copy constructor.
constexpr Vec< Dim, T > center() const noexcept
Returns the center of the capsule.
constexpr Capsule() noexcept=default
Default constructor.
A fixed-size arithmetic vector of up to 4 dimensions.