9#include "../SIMD/module.hpp"
10#include "../utility/module.hpp"
13namespace hi::inline
v1 {
23template<
typename T,
int D>
27 using array_type = simd<value_type, 4>;
29 static_assert(D == 2 || D == 3,
"Only 2D or 3D points are supported");
31 constexpr point(
point const&)
noexcept =
default;
33 constexpr point& operator=(
point const&)
noexcept =
default;
34 constexpr point& operator=(
point&&)
noexcept =
default;
49 : _v(static_cast<array_type>(other))
63 _v[i] = value_type{0};
70 [[nodiscard]]
constexpr explicit operator array_type() const noexcept
78 [[nodiscard]]
constexpr explicit point(array_type
const& other) noexcept : _v(other)
85 [[nodiscard]]
constexpr point() noexcept : _v(value_type{0}, value_type{0}, value_type{0}, value_type{1}) {}
91 [[nodiscard]]
constexpr point(value_type x, value_type y)
noexcept
93 : _v(x, y, value_type{0}, value_type{1})
102 [[nodiscard]]
constexpr point(value_type x, value_type y, value_type z = value_type{0})
noexcept
104 : _v(x, y, z, value_type{1})
111 [[nodiscard]]
constexpr value_type&
x() noexcept
119 [[nodiscard]]
constexpr value_type&
y() noexcept
127 [[nodiscard]]
constexpr value_type&
z() noexcept
136 [[nodiscard]]
constexpr value_type
x() const noexcept
144 [[nodiscard]]
constexpr value_type
y() const noexcept
152 [[nodiscard]]
constexpr value_type
z() const noexcept
162 hi_axiom(holds_invariant() && rhs.holds_invariant());
163 _v = _v +
static_cast<array_type
>(rhs);
169 constexpr point&
operator-=(vector<value_type, E>
const& rhs)
noexcept
171 hi_axiom(holds_invariant() && rhs.holds_invariant());
172 _v = _v -
static_cast<array_type
>(rhs);
184 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
185 return point<value_type,
std::max(D, E)>{lhs._v +
static_cast<array_type
>(rhs)};
196 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
197 return point<value_type,
std::max(D, E)>{lhs._v +
static_cast<array_type
>(rhs)};
208 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
209 return point<value_type,
std::max(D, E)>{lhs._v -
static_cast<array_type
>(rhs)};
219 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
230 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
231 return equal(lhs._v, rhs._v);
237 return point<value_type,
std::max(D, E)>{midpoint(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
241 [[nodiscard]]
friend constexpr auto reflect(point
const& lhs, point<value_type, E>
const& rhs)
noexcept
243 return point<value_type,
std::max(D, E)>{reflect_point(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
254 return point<value_type,
std::max(D, E)>{min(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
265 return point<value_type,
std::max(D, E)>{max(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
271 requires std::is_same_v<value_type, float>
273 return point{round(
static_cast<array_type
>(rhs))};
279 requires std::is_same_v<value_type, float>
281 return point{ceil(
static_cast<array_type
>(rhs))};
287 requires std::is_same_v<value_type, float>
289 return point{floor(
static_cast<array_type
>(rhs))};
294 [[nodiscard]]
friend constexpr point ceil(
point const& lhs, extent<value_type, D> rhs)
noexcept
295 requires std::is_same_v<value_type, float>
297 hilet rhs_ = array_type{rhs}.xy11();
298 return point{ceil(array_type{lhs} / rhs_) * rhs_};
303 [[nodiscard]]
friend constexpr point ceil(
point const& lhs, extent<value_type, D> rhs)
noexcept
304 requires std::is_same_v<value_type, int>
306 hilet rhs_ = array_type{rhs}.xy11();
307 hilet lhs_ = array_type{lhs};
308 return point{(lhs_ + (rhs_ - 1)) / rhs_ * rhs_};
313 [[nodiscard]]
friend constexpr point floor(
point const& lhs, extent<value_type, D> rhs)
noexcept
314 requires std::is_same_v<value_type, float>
316 hilet rhs_ = array_type{rhs}.xy11();
317 return point{floor(array_type{lhs} / rhs_) * rhs_};
322 [[nodiscard]]
friend constexpr point floor(
point const& lhs, extent<value_type, D> rhs)
noexcept
323 requires std::is_same_v<value_type, int>
325 hilet rhs_ = array_type{rhs}.xy11();
326 hilet lhs_ = array_type{lhs};
327 return point{lhs_ / rhs_ * rhs_};
330 [[nodiscard]]
friend constexpr value_type distance(
point const& lhs,
point const& rhs)
noexcept
332 return hypot(rhs - lhs);
340 return _v.w() != value_type{0} && (D == 3 || _v.z() == value_type{0});
345 if constexpr (D == 2) {
346 return std::format(
"<{}, {}>", rhs._v.x(), rhs._v.y());
347 }
else if constexpr (D == 3) {
348 return std::format(
"<{}, {}, {}>", rhs._v.x(), rhs._v.y(), rhs._v.z());
365using point2 = geo::point<float, 2>;
366using point3 = geo::point<float, 3>;
370template<
typename CharT>
371struct std::formatter<
hi::geo::point<float, 2>, CharT> {
377 auto format(hi::geo::point<float, 2>
const& t,
auto& fc)
379 return std::vformat_to(fc.out(),
"<{}, {}>", std::make_format_args(t.x(), t.y()));
383template<
typename CharT>
384struct std::formatter<
hi::geo::point<float, 3>, CharT> {
390 auto format(hi::geo::point<float, 3>
const& t,
auto& fc)
392 return std::vformat_to(fc.out(),
"<{}, {}, {}>", std::make_format_args(t.x(), t.y(), t.z()));
396template<
typename CharT>
397struct std::formatter<
hi::geo::point<int, 2>, CharT> {
403 auto format(hi::geo::point<int, 2>
const& t,
auto& fc)
405 return std::vformat_to(fc.out(),
"<{}, {}>", std::make_format_args(t.x(), t.y()));
409template<
typename CharT>
410struct std::formatter<
hi::geo::point<int, 3>, CharT> {
416 auto format(hi::geo::point<int, 3>
const& t,
auto& fc)
418 return std::vformat_to(fc.out(),
"<{}, {}, {}>", std::make_format_args(t.x(), t.y(), t.z()));
Defined the geo::extent, extent2 and extent3 types.
#define hi_static_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:323
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point.hpp:24
friend constexpr point ceil(point const &rhs) noexcept
Round the coordinates of a point toward the right-top.
Definition point.hpp:278
constexpr value_type & y() noexcept
Access the y element from the point.
Definition point.hpp:119
constexpr value_type x() const noexcept
Access the x element from the point.
Definition point.hpp:136
constexpr point() noexcept
Construct a point at the origin of the coordinate system.
Definition point.hpp:85
friend constexpr auto max(point const &lhs, point< value_type, E > const &rhs) noexcept
Mix the two points and get the highest value of each element.
Definition point.hpp:263
constexpr friend auto operator-(point const &lhs, vector< value_type, E > const &rhs) noexcept
Move a point backward along the vector.
Definition point.hpp:206
constexpr point(value_type x, value_type y) noexcept
Construct a 2D point from x and y elements.
Definition point.hpp:91
constexpr friend vector< value_type, D > operator-(point const &lhs, point const &rhs) noexcept
Find the vector between two points.
Definition point.hpp:217
constexpr point(point< value_type, E > const &other) noexcept
Construct a point from a lower dimension point.
Definition point.hpp:40
constexpr point(point< value_type, E > const &other) noexcept
Construct a point from a higher dimension point.
Definition point.hpp:60
friend constexpr point floor(point const &lhs, extent< value_type, D > rhs) noexcept
Round the coordinates of a point toward the left-bottom with the given granularity.
Definition point.hpp:322
friend constexpr point ceil(point const &lhs, extent< value_type, D > rhs) noexcept
Round the coordinates of a point toward the top-right with the given granularity.
Definition point.hpp:294
friend constexpr auto min(point const &lhs, point< value_type, E > const &rhs) noexcept
Mix the two points and get the lowest value of each element.
Definition point.hpp:252
constexpr friend auto operator+(point const &lhs, vector< value_type, E > const &rhs) noexcept
Move a point along a vector.
Definition point.hpp:182
constexpr value_type y() const noexcept
Access the y element from the point.
Definition point.hpp:144
constexpr value_type z() const noexcept
Access the z element from the point.
Definition point.hpp:152
friend constexpr point floor(point const &lhs, extent< value_type, D > rhs) noexcept
Round the coordinates of a point toward the left-bottom with the given granularity.
Definition point.hpp:313
friend constexpr point ceil(point const &lhs, extent< value_type, D > rhs) noexcept
Round the coordinates of a point toward the top-right with the given granularity.
Definition point.hpp:303
constexpr point(array_type const &other) noexcept
Construct a point from a array_type-simd.
Definition point.hpp:78
friend constexpr point floor(point const &rhs) noexcept
Round the coordinates of a point toward the left-bottom.
Definition point.hpp:286
constexpr value_type & x() noexcept
Access the x element from the point.
Definition point.hpp:111
constexpr bool holds_invariant() const noexcept
Check if the point is valid.
Definition point.hpp:338
constexpr friend bool operator==(point const &lhs, point const &rhs) noexcept
Compare if two points are equal.
Definition point.hpp:228
constexpr point(value_type x, value_type y, value_type z=value_type{0}) noexcept
Construct a 3D point from x, y and z elements.
Definition point.hpp:102
friend constexpr point round(point const &rhs) noexcept
Round the coordinates of a point toward nearest integer.
Definition point.hpp:270
constexpr point(point< value_type, 2 > const &other, value_type z) noexcept
Construct a point from a lower dimension point.
Definition point.hpp:47
constexpr value_type & z() noexcept
Access the z element from the point.
Definition point.hpp:127
constexpr friend auto operator+(vector< value_type, E > const &rhs, point const &lhs) noexcept
Move a point along a vector.
Definition point.hpp:194
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector.hpp:21