42#ifndef UFO_GEOMETRY_CYLINDER_HPP
43#define UFO_GEOMETRY_CYLINDER_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; }
138 [[nodiscard]]
constexpr T
diameter() const noexcept
167 if (
length < std::numeric_limits<T>::epsilon()) {
173 for (std::size_t i = 0; i < Dim; ++i) {
174 T s = std::sqrt(std::max(T(0), T(1) -
axis[i] *
axis[i]));
191 [[nodiscard]]
constexpr T
volume() const noexcept
193 if constexpr (1 == Dim) {
195 }
else if constexpr (2 == Dim) {
197 }
else if constexpr (3 == Dim) {
218template <std::
size_t Dim, std::
floating_po
int T>
227template <std::
size_t Dim, std::
floating_po
int T>
230 return out <<
"Start: [" << cylinder.
start <<
"], End: [" << cylinder.
end
231 <<
"], Radius: " << cylinder.
radius;
234template <std::
floating_po
int T>
235using Cylinder1 = Cylinder<1, T>;
236template <std::
floating_po
int T>
237using Cylinder2 = Cylinder<2, T>;
238template <std::
floating_po
int T>
239using Cylinder3 = Cylinder<3, T>;
240template <std::
floating_po
int T>
241using Cylinder4 = Cylinder<4, T>;
243using Cylinder1f = Cylinder<1, float>;
244using Cylinder2f = Cylinder<2, float>;
245using Cylinder3f = Cylinder<3, float>;
246using Cylinder4f = Cylinder<4, float>;
248using Cylinder1d = Cylinder<1, double>;
249using Cylinder2d = Cylinder<2, double>;
250using Cylinder3d = Cylinder<3, double>;
251using Cylinder4d = Cylinder<4, double>;
255template <std::
size_t Dim, std::
floating_po
int T>
256 requires std::formattable<T, char>
257struct std::formatter<
ufo::Cylinder<Dim, T>> {
258 constexpr auto parse(std::format_parse_context& ctx) {
return ctx.begin(); }
262 return std::format_to(ctx.out(),
"Start: [{}], End: [{}], Radius: {}", cylinder.
start,
All vision-related classes and functions.
constexpr T length(Vec< Dim, T > const &v) noexcept
Computes the Euclidean length (magnitude) of a vector.
Vec< 3, T > axis(Quat< T > const &q) noexcept
Extracts the unit rotation axis from a unit quaternion.
Axis-Aligned Bounding Box (AABB) in Dim-dimensional space.
Cylinder in Dim-dimensional space.
constexpr Cylinder() noexcept=default
Default constructor.
constexpr AABB< Dim, T > aabb() const noexcept
Returns the AABB of the cylinder.
bool operator==(Cylinder const &) const =default
Equality operator.
constexpr T diameter() const noexcept
Returns the diameter of the cylinder.
constexpr bool isDegenerate() const noexcept
Returns whether the cylinder is degenerate.
T radius
The radius of the cylinder.
constexpr Cylinder(Cylinder const &) noexcept=default
Copy constructor.
constexpr T length() const noexcept
Returns the height (length) of the cylinder.
constexpr Cylinder(Cylinder< Dim, U > const &other) noexcept
Converting constructor from a cylinder with a different scalar type.
constexpr T volume() const noexcept
Returns the volume (or area/length) of the cylinder.
Vec< Dim, T > end
The end point of the second cap of the cylinder.
constexpr Vec< Dim, T > at(T t) const noexcept
Returns the point at parameter t along the cylinder axis.
constexpr Vec< Dim, T > center() const noexcept
Returns the center of the cylinder.
Vec< Dim, T > start
The center of the first cap of the cylinder.
static constexpr std::size_t dimension() noexcept
Returns the dimensionality of the cylinder.
A fixed-size arithmetic vector of up to 4 dimensions.