7#include "../rapid/numeric_array.hpp"
24 static_assert(D == 2 || D == 3,
"Only 2D or 3D points are supported");
26 constexpr point(
point const &)
noexcept =
default;
28 constexpr point &operator=(
point const &)
noexcept =
default;
29 constexpr point &operator=(
point &&)
noexcept =
default;
34 requires(E < D) [[nodiscard]]
constexpr point(
point<E> const &other) noexcept : _v(
static_cast<f32x4>(other))
43 requires(E > D) [[nodiscard]]
constexpr explicit point(
point<E> const &other) noexcept : _v(
static_cast<f32x4>(other))
45 for (
size_t i = D; i != E; ++i) {
53 [[nodiscard]]
constexpr explicit operator f32x4() const noexcept
61 [[nodiscard]]
constexpr explicit point(
f32x4 const &other) noexcept : _v(other)
68 [[nodiscard]]
constexpr point() noexcept : _v(0.0, 0.0, 0.0, 1.0) {}
74 [[nodiscard]]
constexpr point(
float x,
float y)
noexcept requires(D == 2) : _v(
x,
y, 0.0, 1.0) {}
81 [[nodiscard]]
constexpr point(
float x,
float y,
float z = 0.0) noexcept requires(D == 3) : _v(
x,
y,
z, 1.0) {}
86 [[nodiscard]]
constexpr float &
x() noexcept
94 [[nodiscard]]
constexpr float &
y() noexcept
102 [[nodiscard]]
constexpr float &
z() noexcept requires(D == 3)
110 [[nodiscard]]
constexpr float const &
x() const noexcept
118 [[nodiscard]]
constexpr float const &
y() const noexcept
126 [[nodiscard]]
constexpr float const &
z() const noexcept requires(D == 3)
132 requires(E <= D)
constexpr point &
operator+=(
vector<E> const &rhs)
noexcept
134 tt_axiom(
is_valid() && rhs.is_valid());
135 _v = _v +
static_cast<f32x4>(rhs);
147 tt_axiom(lhs.is_valid() && rhs.is_valid());
159 tt_axiom(lhs.is_valid() && rhs.is_valid());
171 tt_axiom(lhs.is_valid() && rhs.is_valid());
182 tt_axiom(lhs.is_valid() && rhs.is_valid());
193 tt_axiom(lhs.is_valid() && rhs.is_valid());
194 return lhs._v == rhs._v;
198 [[nodiscard]]
friend constexpr auto midpoint(
point const &lhs,
point<E> const &rhs)
noexcept
204 [[nodiscard]]
friend constexpr auto reflect(
point const &lhs, point<E>
const &rhs)
noexcept
206 return point<
std::max(D, E)>{reflect_point(
static_cast<f32x4
>(lhs),
static_cast<f32x4
>(rhs))};
255 [[nodiscard]]
constexpr bool is_valid() const noexcept
257 return _v.w() != 0.0f && (D == 3 || _v.z() == 0.0f);
262 if constexpr (D == 2) {
263 return std::format(
"<{}, {}>", rhs._v.x(), rhs._v.y());
264 }
else if constexpr (D == 3) {
265 return std::format(
"<{}, {}, {}>", rhs._v.x(), rhs._v.y(), rhs._v.z());
267 tt_static_no_default();
273 return lhs << to_string(rhs);
282using point2 = geo::point<2>;
283using point3 = geo::point<3>;
289template<
typename CharT>
290struct formatter<tt::geo::point<2>, CharT> {
298 return std::vformat_to(fc.out(),
"<{}, {}>", std::make_format_args(t.
x(), t.
y()));
302template<
typename CharT>
303struct formatter<tt::geo::point<3>, CharT> : formatter<float, CharT> {
311 return std::vformat_to(fc.out(),
"<{}, {}, {}>", std::make_format_args(t.
x(), t.
y(), t.
z()));
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point.hpp:22
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:157
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:226
constexpr float & x() noexcept
Access the x element from the point.
Definition point.hpp:86
constexpr float const & y() const noexcept
Access the y element from the point.
Definition point.hpp:118
constexpr point(point< E > const &other) noexcept
Construct a point from a higher dimension point.
Definition point.hpp:43
constexpr point(float x, float y) noexcept
Construct a 2D point from x and y elements.
Definition point.hpp:74
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:145
friend constexpr point round(point const &rhs) noexcept
Round the coordinates of a point toward nearest integer.
Definition point.hpp:233
constexpr point(float x, float y, float z=0.0) noexcept
Construct a 3D point from x, y and z elements.
Definition point.hpp:81
friend constexpr point ceil(point const &rhs) noexcept
Round the coordinates of a point toward the right-top.
Definition point.hpp:240
constexpr point(point< E > const &other) noexcept
Construct a point from a lower dimension point.
Definition point.hpp:34
constexpr point(f32x4 const &other) noexcept
Construct a point from a f32x4-numeric_array.
Definition point.hpp:61
constexpr float const & z() const noexcept
Access the z element from the point.
Definition point.hpp:126
constexpr friend vector< D > operator-(point const &lhs, point const &rhs) noexcept
Find the vector between two points.
Definition point.hpp:180
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:215
constexpr point() noexcept
Construct a point at the origin of the coordinate system.
Definition point.hpp:68
constexpr friend bool operator==(point const &lhs, point const &rhs) noexcept
Compare if two points are equal.
Definition point.hpp:191
constexpr bool is_valid() const noexcept
Check if the point is valid.
Definition point.hpp:255
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:169
constexpr float const & x() const noexcept
Access the x element from the point.
Definition point.hpp:110
constexpr float & z() noexcept
Access the z element from the point.
Definition point.hpp:102
friend constexpr point floor(point const &rhs) noexcept
Round the coordinates of a point toward the left-bottom.
Definition point.hpp:247
constexpr float & y() noexcept
Access the y element from the point.
Definition point.hpp:94
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector.hpp:20