9#include "../SIMD/module.hpp"
10#include "../utility/utility.hpp"
11#include "../macros.hpp"
28 using array_type = simd<float, 4>;
29 using value_type = array_type::value_type;
33 constexpr point2& operator=(
point2 const&)
noexcept =
default;
34 constexpr point2& operator=(
point2&&)
noexcept =
default;
38 [[nodiscard]]
constexpr explicit operator array_type() const noexcept
45 [[nodiscard]]
constexpr explicit point2(array_type
const& other) noexcept : _v(other)
47 hi_axiom(holds_invariant());
52 [[nodiscard]]
constexpr point2() noexcept : _v(0.0f, 0.0f, 0.0f, 1.0f) {}
58 [[nodiscard]]
constexpr point2(
float x,
float y) noexcept : _v(x, y, 0.0f, 1.0f) {}
63 [[nodiscard]]
constexpr float&
x() noexcept
71 [[nodiscard]]
constexpr float&
y() noexcept
79 [[nodiscard]]
constexpr float x() const noexcept
87 [[nodiscard]]
constexpr float y() const noexcept
92 constexpr point2& operator+=(vector2
const& rhs)
noexcept
94 return *
this = *
this + rhs;
97 constexpr point2& operator-=(vector2
const& rhs)
noexcept
99 return *
this = *
this - rhs;
109 return point2{lhs._v + array_type{rhs}};
119 return point2{array_type{lhs} + rhs._v};
129 return point2{lhs._v - array_type{rhs}};
139 return vector2{lhs._v - rhs._v};
149 return equal(lhs._v, rhs._v);
152 [[nodiscard]]
friend constexpr point2 midpoint(
point2 const& lhs,
point2 const& rhs)
noexcept
154 return point2{midpoint(lhs._v, rhs._v)};
157 [[nodiscard]]
friend constexpr point2 reflect(point2
const& lhs, point2
const& rhs)
noexcept
159 return point2{reflect_point(lhs._v, rhs._v)};
169 return point2{min(lhs._v, rhs._v)};
179 return point2{max(lhs._v, rhs._v)};
186 return point2{round(rhs._v)};
193 return point2{ceil(rhs._v)};
200 return point2{floor(rhs._v)};
207 hilet rhs_ = array_type{rhs}.xy11();
208 return point2{ceil(lhs._v / rhs_) * rhs_};
215 hilet rhs_ = array_type{rhs}.xy11();
216 return point2{floor(lhs._v / rhs_) * rhs_};
219 [[nodiscard]]
friend float distance(
point2 const& lhs,
point2 const& rhs)
noexcept
221 return hypot(rhs - lhs);
229 return _v.z() == 0.0f and _v.w() != 0.0f;
234 return std::format(
"<{}, {}>", rhs._v.x(), rhs._v.y());
239 return lhs << to_string(rhs);
248template<
typename CharT>
249struct std::formatter<
hi::point2, CharT> {
255 auto format(hi::point2
const& t,
auto& fc)
const
257 return std::vformat_to(fc.out(),
"<{}, {}>", std::make_format_args(t.x(), t.y()));
Defined the geo::extent, extent2 and extent3 types.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point2.hpp:26
friend constexpr point2 min(point2 const &lhs, point2 const &rhs) noexcept
Mix the two points and get the lowest value of each element.
Definition point2.hpp:167
constexpr bool holds_invariant() const noexcept
Check if the point is valid.
Definition point2.hpp:227
constexpr friend vector2 operator-(point2 const &lhs, point2 const &rhs) noexcept
Find the vector between two points.
Definition point2.hpp:137
constexpr friend bool operator==(point2 const &lhs, point2 const &rhs) noexcept
Compare if two points are equal.
Definition point2.hpp:147
friend constexpr point2 ceil(point2 const &lhs, extent2 rhs) noexcept
Round the coordinates of a point toward the top-right with the given granularity.
Definition point2.hpp:205
constexpr float & y() noexcept
Access the y element from the point.
Definition point2.hpp:71
friend constexpr point2 floor(point2 const &lhs, extent2 rhs) noexcept
Round the coordinates of a point toward the left-bottom with the given granularity.
Definition point2.hpp:213
friend constexpr point2 round(point2 const &rhs) noexcept
Round the coordinates of a point toward nearest integer.
Definition point2.hpp:184
constexpr point2(float x, float y) noexcept
Construct a 3D point from x, y and z elements.
Definition point2.hpp:58
constexpr friend point2 operator-(point2 const &lhs, vector2 const &rhs) noexcept
Move a point backward along the vector.
Definition point2.hpp:127
constexpr float & x() noexcept
Access the x element from the point.
Definition point2.hpp:63
friend constexpr point2 max(point2 const &lhs, point2 const &rhs) noexcept
Mix the two points and get the highest value of each element.
Definition point2.hpp:177
friend constexpr point2 ceil(point2 const &rhs) noexcept
Round the coordinates of a point toward the right-top.
Definition point2.hpp:191
constexpr float y() const noexcept
Access the y element from the point.
Definition point2.hpp:87
constexpr point2(array_type const &other) noexcept
Construct a point from a array_type-simd.
Definition point2.hpp:45
constexpr friend point2 operator+(point2 const &lhs, vector2 const &rhs) noexcept
Move a point along a vector.
Definition point2.hpp:107
constexpr friend point2 operator+(vector2 const &lhs, point2 const &rhs) noexcept
Move a point along a vector.
Definition point2.hpp:117
friend constexpr point2 floor(point2 const &rhs) noexcept
Round the coordinates of a point toward the left-bottom.
Definition point2.hpp:198
constexpr float x() const noexcept
Access the x element from the point.
Definition point2.hpp:79
constexpr point2() noexcept
Construct a point at the origin of the coordinate system.
Definition point2.hpp:52