42#ifndef UFO_GEOMETRY_SPHERE_HPP
43#define UFO_GEOMETRY_SPHERE_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>
83 constexpr Sphere() noexcept = default;
105 template <std::convertible_to<T> U>
115 [[nodiscard]]
static constexpr std::size_t
dimension() noexcept {
return Dim; }
157 [[nodiscard]]
constexpr T
volume() const noexcept
159 if constexpr (1 == Dim) {
161 }
else if constexpr (2 == Dim) {
163 }
else if constexpr (3 == Dim) {
165 }
else if constexpr (4 == Dim) {
184template <std::
size_t Dim, std::
floating_po
int T>
190template <std::
size_t Dim, std::
floating_po
int T>
193 return out <<
"Center: [" << sphere.
center() <<
"], Radius: " << sphere.
radius;
196template <std::
floating_po
int T>
197using Sphere1 = Sphere<1, T>;
198template <std::
floating_po
int T>
199using Sphere2 = Sphere<2, T>;
200template <std::
floating_po
int T>
201using Sphere3 = Sphere<3, T>;
202template <std::
floating_po
int T>
203using Sphere4 = Sphere<4, T>;
205using Sphere1f = Sphere<1, float>;
206using Sphere2f = Sphere<2, float>;
207using Sphere3f = Sphere<3, float>;
208using Sphere4f = Sphere<4, float>;
210using Sphere1d = Sphere<1, double>;
211using Sphere2d = Sphere<2, double>;
212using Sphere3d = Sphere<3, double>;
213using Sphere4d = Sphere<4, double>;
217template <std::
size_t Dim, std::
floating_po
int T>
218 requires std::formattable<T, char>
219struct std::formatter<
ufo::Sphere<Dim, T>> {
220 constexpr auto parse(std::format_parse_context& ctx) {
return ctx.begin(); }
224 return std::format_to(ctx.out(),
"Center: [{}], Radius: {}", sphere.
center(),
All vision-related classes and functions.
Axis-Aligned Bounding Box (AABB) in Dim-dimensional space.
Sphere in Dim-dimensional space.
constexpr bool isDegenerate() const noexcept
Returns whether the sphere is degenerate.
constexpr Vec< Dim, T > & center() noexcept
Returns the center of the sphere.
static constexpr std::size_t dimension() noexcept
Returns the dimensionality of the sphere.
constexpr Sphere(Sphere< Dim, U > const &other) noexcept
Converting constructor from a sphere with a different scalar type.
constexpr Vec< Dim, T > const & center() const noexcept
Returns the center of the sphere.
constexpr T diameter() const noexcept
Returns the diameter of the sphere.
constexpr Sphere() noexcept=default
Default constructor.
constexpr T volume() const noexcept
Returns the volume of the sphere.
constexpr Sphere(Sphere const &) noexcept=default
Copy constructor.
T radius
The radius of the sphere.
constexpr AABB< Dim, T > aabb() const noexcept
Returns the AABB of the sphere.
Vec< Dim, T > center_
The center of the sphere.
bool operator==(Sphere const &) const =default
Equality operator.
A fixed-size arithmetic vector of up to 4 dimensions.