36template<
typename T,
int N>
86 template<std::convertible_to<T>... Args>
87 requires(
sizeof...(Args) == N)
88 constexpr explicit Point(Args&&... args) noexcept
89 : m_coords(std::forward<Args>(args)...) {}
94 constexpr T&
x() noexcept requires(N > 0) {
return m_coords.x(); }
96 constexpr T&
y() noexcept requires(N > 1) {
return m_coords.y(); }
98 constexpr T&
z() noexcept requires(N > 2) {
return m_coords.z(); }
100 constexpr T&
w() noexcept requires(N > 3) {
return m_coords.w(); }
103 constexpr T
x() const noexcept requires(N > 0) {
return m_coords.x(); }
105 constexpr T
y() const noexcept requires(N > 1) {
return m_coords.y(); }
107 constexpr T
z() const noexcept requires(N > 2) {
return m_coords.z(); }
109 constexpr T
w() const noexcept requires(N > 3) {
return m_coords.w(); }
112 constexpr int dims() const noexcept {
return N; }
117 constexpr const T&
operator[](
int index)
const {
return m_coords[index]; }
119 constexpr T&
operator[](
int index) {
return m_coords[index]; }
121 constexpr const T&
at(
int index)
const {
return m_coords.at(index); }
146 constexpr bool operator<(
const Point& rhs)
const {
147 for (
int i = 0; i < N; i ++) {
148 if (!
is_less(m_coords[i], rhs.m_coords[i]))
155 constexpr bool operator<=(
const Point& rhs)
const {
156 for (
int i = 0; i < N; i ++) {
167 for (
int i = 0; i < N; i ++) {
168 if (!
is_greater(m_coords[i], rhs.m_coords[i]))
178 for (
int i = 0; i < N; i ++) {
179 if (
is_less(m_coords[i], rhs.m_coords[i]))
193 for (
int i = 0; i < N; i ++) {
194 if (!
is_equal(m_coords[i], rhs.m_coords[i]))
219 os <<
"Point" << N <<
"(";
220 for (
int i = 0; i < N; ++i) {
221 os << point[i] << (i == N - 1 ?
"" :
", ");
233 return this->
to_vector() - rhs.to_vector();
A template class for an N-dimensional point in space.
Definition point.hpp:37
constexpr T w() const noexcept
Const access to the fourth coordinate (w-axis).
Definition point.hpp:109
constexpr Point mid(const Point< T, N > &rhs) const noexcept
Calculates the midpoint between two points.
Definition point.hpp:263
constexpr bool operator==(const Point &rhs) const
equal
Definition point.hpp:192
constexpr Point & operator+=(const Vector< T, N > &rhs) noexcept
Translates the point by adding a vector.
Definition point.hpp:140
constexpr Point operator+(const Vector< T, N > &rhs) const noexcept
Rule 2: Translates a point by a vector, resulting in a new point (Point + Vector = Point).
Definition point.hpp:241
constexpr bool operator>=(const Point &rhs) const
greater than or equal
Definition point.hpp:177
constexpr T x() const noexcept
Const access to the first coordinate (x-axis).
Definition point.hpp:103
constexpr T & x() noexcept
Accesses the first coordinate (x-axis).
Definition point.hpp:94
constexpr T y() const noexcept
Const access to the second coordinate (y-axis).
Definition point.hpp:105
constexpr T z() const noexcept
Const access to the third coordinate (z-axis).
Definition point.hpp:107
constexpr Point() noexcept
Default constructor. Initializes the point at the origin.
Definition point.hpp:71
constexpr Vector< T, N > operator-(const Point &rhs) const noexcept
Rule 1: Calculates the displacement vector between two points (Point - Point = Vector).
Definition point.hpp:232
constexpr T & w() noexcept
Accesses the fourth coordinate (w-axis).
Definition point.hpp:100
static constexpr Point zeros() noexcept
Creates a point at the origin (0, 0, ...).
Definition point.hpp:58
static constexpr Point filled(T value) noexcept
Creates a point filled with a specified value.
Definition point.hpp:52
friend std::ostream & operator<<(std::ostream &os, const Point &point)
Stream insertion operator for printing the point's coordinates.
Definition point.hpp:218
constexpr Point operator-(const Vector< T, N > &rhs) const noexcept
Rule 3: Translates a point by the negative of a vector (Point - Vector = Point).
Definition point.hpp:252
constexpr Vector< T, N > to_vector() const noexcept
Explicitly converts the point to its underlying coordinate vector.
Definition point.hpp:131
constexpr T & z() noexcept
Accesses the third coordinate (z-axis).
Definition point.hpp:98
constexpr Point(const Vector< T, N > &vec) noexcept
Constructs a point from a coordinate vector.
Definition point.hpp:77
constexpr const T & operator[](int index) const
Provides const access to the point's coordinates by index.
Definition point.hpp:117
constexpr T & operator[](int index)
Provides mutable access to the point's coordinates by index.
Definition point.hpp:119
static constexpr Point ones() noexcept
Creates a point with all coordinates set to one.
Definition point.hpp:64
constexpr int dims() const noexcept
Returns the number of dimensions of the point.
Definition point.hpp:112
constexpr Point(Args &&... args) noexcept
Constructs a point from a list of individual coordinate values.
Definition point.hpp:88
constexpr bool operator>(const Point &rhs) const
greater than
Definition point.hpp:166
constexpr const T & at(int index) const
Provides safe const access to the point's coordinates by index.
Definition point.hpp:121
constexpr Point & operator-=(const Vector< T, N > &rhs) noexcept
Translates the point by subtracting a vector.
Definition point.hpp:205
constexpr T & y() noexcept
Accesses the second coordinate (y-axis).
Definition point.hpp:96
A template class for N-dimensional mathematical vectors.
Definition vector.hpp:35
static constexpr Vector zeros() noexcept
Creates a vector with all components set to zero.
Definition vector.hpp:56
static constexpr Vector ones() noexcept
Creates a vector with all components set to one.
Definition vector.hpp:62
static constexpr Vector filled(T value) noexcept
Creates a vector with all components set to a single scalar value.
Definition vector.hpp:46
Provides basic, constexpr-aware mathematical functions.
The namespace for math library implementation.
Definition bounding_box.hpp:9
Point< Float, 2 > Pt2
A 2-dimensional point of type Float.
Definition point.hpp:272
constexpr bool is_greater(T a, T b)
Compares if a is greater than b.
Definition function.hpp:301
Point< Float, 3 > Pt3
A 3-dimensional point of type Float.
Definition point.hpp:274
constexpr bool is_equal(T a, T b)
Compares two floating-point values for equality.
Definition function.hpp:287
constexpr bool is_less(T a, T b)
Compares if a is less than b.
Definition function.hpp:329
Point< Float, 4 > Pt4
A 4-dimensional point of type Float.
Definition point.hpp:276
Defines a generic, N-dimensional, constexpr-friendly vector class.