7#include "numeric_array.hpp"
23 static_assert(D == 2 || D == 3,
"Only 2D or 3D points are supported");
25 constexpr point(
point const &)
noexcept =
default;
27 constexpr point &operator=(
point const &)
noexcept =
default;
28 constexpr point &operator=(
point &&)
noexcept =
default;
33 requires(E < D) [[nodiscard]]
constexpr point(
point<E> const &other) noexcept : _v(
static_cast<f32x4>(other))
42 requires(E > D) [[nodiscard]]
constexpr explicit point(
point<E> const &other) noexcept : _v(
static_cast<f32x4>(other))
44 for (
size_t i = D; i != E; ++i) {
52 [[nodiscard]]
constexpr explicit operator f32x4() const noexcept
60 [[nodiscard]]
constexpr explicit point(
f32x4 const &other) noexcept : _v(other)
67 [[nodiscard]]
constexpr point() noexcept : _v(0.0, 0.0, 0.0, 1.0) {}
73 [[nodiscard]]
constexpr point(
float x,
float y)
noexcept requires(D == 2) : _v(
x,
y, 0.0, 1.0) {}
80 [[nodiscard]]
constexpr point(
float x,
float y,
float z = 0.0) noexcept requires(D == 3) : _v(
x,
y,
z, 1.0) {}
85 [[nodiscard]]
constexpr float &
x() noexcept
93 [[nodiscard]]
constexpr float &
y() noexcept
101 [[nodiscard]]
constexpr float &
z() noexcept requires(D == 3)
109 [[nodiscard]]
constexpr float const &
x() const noexcept
117 [[nodiscard]]
constexpr float const &
y() const noexcept
125 [[nodiscard]]
constexpr float const &
z() const noexcept requires(D == 3)
130 template<
int E>
requires (E <= D)
134 _v = _v +
static_cast<f32x4>(rhs);
146 tt_axiom(lhs.is_valid() && rhs.
is_valid());
158 tt_axiom(lhs.is_valid() && rhs.
is_valid());
170 tt_axiom(lhs.is_valid() && rhs.
is_valid());
181 tt_axiom(lhs.is_valid() && rhs.
is_valid());
192 tt_axiom(lhs.is_valid() && rhs.
is_valid());
193 return lhs._v == rhs._v;
197 [[nodiscard]]
friend constexpr auto midpoint(
point const &lhs,
point<E> const &rhs)
noexcept
203 [[nodiscard]]
friend constexpr auto reflect(
point const &lhs, point<E>
const &rhs)
noexcept
205 return point<
std::max(D, E)>{reflect_point(
static_cast<f32x4
>(lhs),
static_cast<f32x4
>(rhs))};
254 [[nodiscard]]
constexpr bool is_valid() const noexcept
256 return _v.w() != 0.0f && (D == 3 || _v.z() == 0.0f);
261 if constexpr (D == 2) {
262 return fmt::format(
"<{}, {}>", rhs._v.x(), rhs._v.y());
263 }
else if constexpr (D == 3) {
264 return fmt::format(
"<{}, {}, {}>", rhs._v.x(), rhs._v.y(), rhs._v.z());
266 tt_static_no_default();
272 return lhs << to_string(rhs);
281using point2 = geo::point<2>;
282using point3 = geo::point<3>;
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point.hpp:21
constexpr friend point< std::max(D, E)> operator+(vector< E > const &rhs, point const &lhs) noexcept
Move a point along a vector.
Definition point.hpp:156
friend constexpr auto max(point const &lhs, point< E > const &rhs) noexcept
Mix the two points and get the heighest value of each element.
Definition point.hpp:225
constexpr float & x() noexcept
Access the x element from the point.
Definition point.hpp:85
constexpr float const & y() const noexcept
Access the y element from the point.
Definition point.hpp:117
constexpr point(point< E > const &other) noexcept
Construct a point from a higher dimension point.
Definition point.hpp:42
constexpr point(float x, float y) noexcept
Construct a 2D point from x and y elements.
Definition point.hpp:73
constexpr friend point< std::max(D, E)> operator+(point const &lhs, vector< E > const &rhs) noexcept
Move a point along a vector.
Definition point.hpp:144
friend constexpr point round(point const &rhs) noexcept
Round the coordinates of a point toward nearest integer.
Definition point.hpp:232
constexpr point(float x, float y, float z=0.0) noexcept
Construct a 3D point from x, y and z elements.
Definition point.hpp:80
friend constexpr point ceil(point const &rhs) noexcept
Round the coordinates of a point toward the right-top.
Definition point.hpp:239
constexpr point(point< E > const &other) noexcept
Construct a point from a lower dimension point.
Definition point.hpp:33
constexpr point(f32x4 const &other) noexcept
Construct a point from a f32x4-numeric_array.
Definition point.hpp:60
constexpr float const & z() const noexcept
Access the z element from the point.
Definition point.hpp:125
constexpr friend vector< D > operator-(point const &lhs, point const &rhs) noexcept
Find the vector between two points.
Definition point.hpp:179
friend constexpr auto min(point const &lhs, point< E > const &rhs) noexcept
Mix the two points and get the lowest value of each element.
Definition point.hpp:214
constexpr point() noexcept
Construct a point at the origin of the coordinate system.
Definition point.hpp:67
constexpr friend bool operator==(point const &lhs, point const &rhs) noexcept
Compare if two points are equal.
Definition point.hpp:190
constexpr bool is_valid() const noexcept
Check if the point is valid.
Definition point.hpp:254
constexpr friend point< std::max(D, E)> operator-(point const &lhs, vector< E > const &rhs) noexcept
Move a point backward along the vector.
Definition point.hpp:168
constexpr float const & x() const noexcept
Access the x element from the point.
Definition point.hpp:109
constexpr float & z() noexcept
Access the z element from the point.
Definition point.hpp:101
friend constexpr point floor(point const &rhs) noexcept
Round the coordinates of a point toward the left-bottom.
Definition point.hpp:246
constexpr float & y() noexcept
Access the y element from the point.
Definition point.hpp:93
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector.hpp:20
constexpr bool is_valid() const noexcept
Check if the vector is valid.
Definition vector.hpp:297