9#include "../utility/utility.hpp"
10#include "../macros.hpp"
11#include <hikocpu/hikocpu.hpp>
17hi_export_module(hikogui.geometry : point2);
19hi_export
namespace hi::inline
v1 {
30 using array_type = simd<float, 4>;
31 using value_type = array_type::value_type;
35 constexpr point2& operator=(
point2 const&)
noexcept =
default;
36 constexpr point2& operator=(
point2&&)
noexcept =
default;
40 [[nodiscard]]
constexpr explicit operator array_type() const noexcept
47 [[nodiscard]]
constexpr explicit point2(array_type
const& other) noexcept : _v(other)
49 hi_axiom(holds_invariant());
54 [[nodiscard]]
constexpr point2() noexcept : _v(0.0f, 0.0f, 0.0f, 1.0f) {}
60 [[nodiscard]]
constexpr point2(
float x,
float y) noexcept : _v(x, y, 0.0f, 1.0f) {}
65 [[nodiscard]]
constexpr float&
x() noexcept
73 [[nodiscard]]
constexpr float&
y() noexcept
81 [[nodiscard]]
constexpr float x() const noexcept
89 [[nodiscard]]
constexpr float y() const noexcept
94 constexpr point2& operator+=(vector2
const& rhs)
noexcept
96 return *
this = *
this + rhs;
99 constexpr point2& operator-=(vector2
const& rhs)
noexcept
101 return *
this = *
this - rhs;
111 return point2{lhs._v + array_type{rhs}};
121 return point2{array_type{lhs} + rhs._v};
131 return point2{lhs._v - array_type{rhs}};
141 return vector2{lhs._v - rhs._v};
151 return equal(lhs._v, rhs._v);
154 [[nodiscard]]
friend constexpr point2 midpoint(
point2 const& lhs,
point2 const& rhs)
noexcept
156 return point2{(lhs._v + rhs._v) * array_type::broadcast(0.5f)};
167 return point2{rhs._v - (lhs._v - rhs._v)};
177 return point2{min(lhs._v, rhs._v)};
187 return point2{max(lhs._v, rhs._v)};
194 return point2{round(rhs._v)};
201 return point2{ceil(rhs._v)};
208 return point2{floor(rhs._v)};
215 auto const rhs_ = array_type{rhs}.xy11();
216 return point2{ceil(lhs._v / rhs_) * rhs_};
223 auto const rhs_ = array_type{rhs}.xy11();
224 return point2{floor(lhs._v / rhs_) * rhs_};
227 [[nodiscard]]
friend float distance(
point2 const& lhs,
point2 const& rhs)
noexcept
229 return hypot(rhs - lhs);
237 return _v.z() == 0.0f and _v.w() != 0.0f;
242 return std::format(
"<{}, {}>", rhs._v.x(), rhs._v.y());
247 return lhs << to_string(rhs);
258struct std::formatter<
hi::point2, char> : std::formatter<std::string, char> {
259 auto format(hi::point2
const& t,
auto& fc)
const
261 return std::formatter<std::string, char>::format(std::format(
"<{}, {}>", t.x(), t.y()), fc);
Defined the geo::extent, extent2 and extent3 types.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point2.hpp:28
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:175
constexpr bool holds_invariant() const noexcept
Check if the point is valid.
Definition point2.hpp:235
constexpr friend vector2 operator-(point2 const &lhs, point2 const &rhs) noexcept
Find the vector between two points.
Definition point2.hpp:139
constexpr friend bool operator==(point2 const &lhs, point2 const &rhs) noexcept
Compare if two points are equal.
Definition point2.hpp:149
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:213
constexpr float & y() noexcept
Access the y element from the point.
Definition point2.hpp:73
friend constexpr point2 reflect(point2 const &lhs, point2 const &rhs) noexcept
Reflect a point.
Definition point2.hpp:165
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:221
friend constexpr point2 round(point2 const &rhs) noexcept
Round the coordinates of a point toward nearest integer.
Definition point2.hpp:192
constexpr point2(float x, float y) noexcept
Construct a 3D point from x, y and z elements.
Definition point2.hpp:60
constexpr friend point2 operator-(point2 const &lhs, vector2 const &rhs) noexcept
Move a point backward along the vector.
Definition point2.hpp:129
constexpr float & x() noexcept
Access the x element from the point.
Definition point2.hpp:65
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:185
friend constexpr point2 ceil(point2 const &rhs) noexcept
Round the coordinates of a point toward the right-top.
Definition point2.hpp:199
constexpr float y() const noexcept
Access the y element from the point.
Definition point2.hpp:89
constexpr point2(array_type const &other) noexcept
Construct a point from a array_type-simd.
Definition point2.hpp:47
constexpr friend point2 operator+(point2 const &lhs, vector2 const &rhs) noexcept
Move a point along a vector.
Definition point2.hpp:109
constexpr friend point2 operator+(vector2 const &lhs, point2 const &rhs) noexcept
Move a point along a vector.
Definition point2.hpp:119
friend constexpr point2 floor(point2 const &rhs) noexcept
Round the coordinates of a point toward the left-bottom.
Definition point2.hpp:206
constexpr float x() const noexcept
Access the x element from the point.
Definition point2.hpp:81
constexpr point2() noexcept
Construct a point at the origin of the coordinate system.
Definition point2.hpp:54