7#include "../rapid/numeric_array.hpp"
12namespace hi::inline v1 {
25 static_assert(D == 2 || D == 3,
"Only 2D or 3D points are supported");
27 constexpr point(
point const &)
noexcept =
default;
29 constexpr point &operator=(
point const &)
noexcept =
default;
30 constexpr point &operator=(
point &&)
noexcept =
default;
35 requires(E < D) [[nodiscard]]
constexpr point(
point<E> const &other) noexcept : _v(
static_cast<f32x4>(other))
37 hi_axiom(holds_invariant());
42 [[nodiscard]]
constexpr point(
point<2> const &other,
float z)
noexcept requires(D == 3) : _v(static_cast<
f32x4>(other))
45 hi_axiom(holds_invariant());
53 requires(E > D) [[nodiscard]]
constexpr explicit point(
point<E> const &other) noexcept : _v(
static_cast<f32x4>(other))
58 hi_axiom(holds_invariant());
63 [[nodiscard]]
constexpr explicit operator f32x4() const noexcept
65 hi_axiom(holds_invariant());
71 [[nodiscard]]
constexpr explicit point(
f32x4 const &other) noexcept : _v(other)
73 hi_axiom(holds_invariant());
78 [[nodiscard]]
constexpr point() noexcept : _v(0.0, 0.0, 0.0, 1.0) {}
84 [[nodiscard]]
constexpr point(
float x,
float y)
noexcept requires(D == 2) : _v(x, y, 0.0, 1.0) {}
91 [[nodiscard]]
constexpr point(
float x,
float y,
float z = 0.0) noexcept requires(D == 3) : _v(x, y, z, 1.0) {}
96 [[nodiscard]]
constexpr float &
x() noexcept
104 [[nodiscard]]
constexpr float &
y() noexcept
112 [[nodiscard]]
constexpr float &
z() noexcept requires(D == 3)
120 [[nodiscard]]
constexpr float const &
x() const noexcept
128 [[nodiscard]]
constexpr float const &
y() const noexcept
136 [[nodiscard]]
constexpr float const &
z() const noexcept requires(D == 3)
142 requires(E <= D)
constexpr point &
operator+=(
vector<E> const &rhs)
noexcept
144 hi_axiom(holds_invariant() && rhs.holds_invariant());
145 _v = _v +
static_cast<f32x4>(rhs);
150 requires(E <= D)
constexpr point &
operator-=(vector<E>
const &rhs)
noexcept
152 hi_axiom(holds_invariant() && rhs.holds_invariant());
153 _v = _v -
static_cast<f32x4>(rhs);
165 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
177 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
189 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
200 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
211 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
212 return lhs._v == rhs._v;
216 [[nodiscard]]
friend constexpr auto midpoint(
point const &lhs,
point<E> const &rhs)
noexcept
222 [[nodiscard]]
friend constexpr auto reflect(point
const &lhs, point<E>
const &rhs)
noexcept
224 return point<
std::max(D, E)>{reflect_point(
static_cast<f32x4
>(lhs),
static_cast<f32x4
>(rhs))};
283 return point{floor(
f32x4{lhs} / rhs_) * rhs_};
286 [[nodiscard]]
friend constexpr float distance(
point const &lhs,
point const &rhs)
noexcept
288 return hypot(rhs - lhs);
296 return _v.w() != 0.0f && (D == 3 || _v.z() == 0.0f);
301 if constexpr (D == 2) {
302 return std::format(
"<{}, {}>", rhs._v.x(), rhs._v.y());
303 }
else if constexpr (D == 3) {
304 return std::format(
"<{}, {}, {}>", rhs._v.x(), rhs._v.y(), rhs._v.z());
306 hi_static_no_default();
321using point2 = geo::point<2>;
322using point3 = geo::point<3>;
326template<
typename CharT>
327struct std::formatter<hi::geo::point<2>, CharT> {
333 auto format(hi::geo::point<2>
const &t,
auto &fc)
335 return std::vformat_to(fc.out(),
"<{}, {}>", std::make_format_args(t.x(), t.y()));
339template<
typename CharT>
340struct std::formatter<hi::geo::point<3>, CharT> : std::formatter<float, CharT> {
346 auto format(hi::geo::point<3>
const &t,
auto &fc)
348 return std::vformat_to(fc.out(),
"<{}, {}, {}>", std::make_format_args(t.x(), t.y(), t.z()));
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point.hpp:23
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:244
constexpr float const & y() const noexcept
Access the y element from the point.
Definition point.hpp:128
friend constexpr point floor(point const &lhs, extent2 rhs) noexcept
Round the coordinates of a point toward the left-bottom with the given granularity.
Definition point.hpp:280
constexpr friend auto operator-(point const &lhs, vector< E > const &rhs) noexcept
Move a point backward along the vector.
Definition point.hpp:187
constexpr point(point< E > const &other) noexcept
Construct a point from a lower dimension point.
Definition point.hpp:35
constexpr bool holds_invariant() const noexcept
Check if the point is valid.
Definition point.hpp:294
constexpr point(float x, float y, float z=0.0) noexcept
Construct a 3D point from x, y and z elements.
Definition point.hpp:91
constexpr float const & z() const noexcept
Access the z element from the point.
Definition point.hpp:136
constexpr friend auto operator+(point const &lhs, vector< E > const &rhs) noexcept
Move a point along a vector.
Definition point.hpp:163
constexpr friend auto operator+(vector< E > const &rhs, point const &lhs) noexcept
Move a point along a vector.
Definition point.hpp:175
constexpr point(point< E > const &other) noexcept
Construct a point from a higher dimension point.
Definition point.hpp:53
constexpr float & x() noexcept
Access the x element from the point.
Definition point.hpp:96
friend constexpr point round(point const &rhs) noexcept
Round the coordinates of a point toward nearest integer.
Definition point.hpp:251
friend constexpr point ceil(point const &rhs) noexcept
Round the coordinates of a point toward the right-top.
Definition point.hpp:258
constexpr point() noexcept
Construct a point at the origin of the coordinate system.
Definition point.hpp:78
constexpr friend vector< D > operator-(point const &lhs, point const &rhs) noexcept
Find the vector between two points.
Definition point.hpp:198
friend constexpr point ceil(point const &lhs, extent2 rhs) noexcept
Round the coordinates of a point toward the top-right with the given granularity.
Definition point.hpp:272
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:233
constexpr point(float x, float y) noexcept
Construct a 2D point from x and y elements.
Definition point.hpp:84
constexpr point(f32x4 const &other) noexcept
Construct a point from a f32x4-numeric_array.
Definition point.hpp:71
constexpr float & z() noexcept
Access the z element from the point.
Definition point.hpp:112
constexpr friend bool operator==(point const &lhs, point const &rhs) noexcept
Compare if two points are equal.
Definition point.hpp:209
constexpr point(point< 2 > const &other, float z) noexcept
Construct a point from a lower dimension point.
Definition point.hpp:42
constexpr float & y() noexcept
Access the y element from the point.
Definition point.hpp:104
friend constexpr point floor(point const &rhs) noexcept
Round the coordinates of a point toward the left-bottom.
Definition point.hpp:265
constexpr float const & x() const noexcept
Access the x element from the point.
Definition point.hpp:120
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector.hpp:20