42#ifndef UFO_GEOMETRY_RAY_HPP
43#define UFO_GEOMETRY_RAY_HPP
46#include <ufo/geometry/aabb.hpp>
47#include <ufo/numeric/vec.hpp>
65template <std::
size_t Dim = 3, std::
floating_po
int T =
float>
84 constexpr Ray() noexcept = default;
89 constexpr
Ray(
Ray const&) noexcept = default;
108 template <std::convertible_to<T> U>
118 [[nodiscard]]
static constexpr std::size_t
dimension() noexcept {
return Dim; }
145 [[nodiscard]]
constexpr T
volume() const noexcept {
return T(0); }
151 [[nodiscard]]
constexpr T
diameter() const noexcept
153 return std::numeric_limits<T>::infinity();
164 for (std::size_t i = 0; i < Dim; ++i) {
166 max[i] = std::numeric_limits<T>::infinity();
168 min[i] = -std::numeric_limits<T>::infinity();
179template <std::
size_t Dim, std::
floating_po
int T>
180Ray(Vec<Dim, T>, Vec<Dim, T>) -> Ray<Dim, T>;
185template <std::
size_t Dim, std::
floating_po
int T>
186std::ostream& operator<<(std::ostream& out,
Ray<Dim, T> const& ray)
188 return out <<
"Origin: [" << ray.
origin <<
"], Direction: [" << ray.
direction <<
"]";
191template <std::
floating_po
int T>
192using Ray1 = Ray<1, T>;
193template <std::
floating_po
int T>
194using Ray2 = Ray<2, T>;
195template <std::
floating_po
int T>
196using Ray3 = Ray<3, T>;
197template <std::
floating_po
int T>
198using Ray4 = Ray<4, T>;
200using Ray1f = Ray<1, float>;
201using Ray2f = Ray<2, float>;
202using Ray3f = Ray<3, float>;
203using Ray4f = Ray<4, float>;
205using Ray1d = Ray<1, double>;
206using Ray2d = Ray<2, double>;
207using Ray3d = Ray<3, double>;
208using Ray4d = Ray<4, double>;
212template <std::
size_t Dim, std::
floating_po
int T>
213 requires std::formattable<T, char>
214struct std::formatter<
ufo::Ray<Dim, T>> {
215 constexpr auto parse(std::format_parse_context& ctx) {
return ctx.begin(); }
219 return std::format_to(ctx.out(),
"Origin: [{}], Direction: [{}]", ray.
origin,
constexpr T dot(Quat< T > const &a, Quat< T > const &b) noexcept
Computes the four-component dot product a.w*b.w + a.x*b.x + a.y*b.y + a.z*b.z.
All vision-related classes and functions.
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.
Ray in Dim-dimensional space.
static constexpr std::size_t dimension() noexcept
Returns the dimensionality of the ray.
constexpr AABB< Dim, T > aabb() const noexcept
Returns the AABB of the ray.
constexpr Ray() noexcept=default
Default constructor.
constexpr T volume() const noexcept
Returns the volume of the ray.
constexpr Ray(Ray< Dim, U > const &other) noexcept
Converting constructor from a ray with a different scalar type.
bool operator==(Ray const &) const =default
Equality operator.
Vec< Dim, T > direction
The direction of the ray.
constexpr T diameter() const noexcept
Returns the diameter of the ray.
constexpr bool isDegenerate() const noexcept
Returns whether the ray is degenerate.
constexpr Vec< Dim, T > at(T t) const
Returns the point at distance t along the ray.
Vec< Dim, T > origin
The origin of the ray.
A fixed-size arithmetic vector of up to 4 dimensions.