10#include "../utility/utility.hpp"
11#include "../macros.hpp"
12#include <hikocpu/hikocpu.hpp>
18hi_export_module(hikogui.geometry : point3);
20hi_export
namespace hi::inline
v1 {
31 using array_type = simd<float, 4>;
32 using value_type = array_type::value_type;
36 constexpr point3& operator=(
point3 const&)
noexcept =
default;
37 constexpr point3& operator=(
point3&&)
noexcept =
default;
41 [[nodiscard]]
constexpr point3(
point2 const& other) noexcept : _v(
static_cast<array_type
>(other)) {}
43 [[nodiscard]]
constexpr explicit operator point2() const noexcept
52 [[nodiscard]]
constexpr point3(
point2 const& other,
float z) noexcept : _v(
static_cast<array_type
>(other))
59 [[nodiscard]]
constexpr explicit operator array_type() const noexcept
66 [[nodiscard]]
constexpr explicit point3(array_type
const& other) noexcept : _v(other)
68 hi_axiom(holds_invariant());
73 [[nodiscard]]
constexpr point3() noexcept : _v(0.0f, 0.0f, 0.0f, 1.0f) {}
80 [[nodiscard]]
constexpr point3(
float x,
float y,
float z = 0.0f) noexcept : _v(x, y, z, 1.0f) {}
85 [[nodiscard]]
constexpr float&
x() noexcept
93 [[nodiscard]]
constexpr float&
y() noexcept
101 [[nodiscard]]
constexpr float&
z() noexcept
109 [[nodiscard]]
constexpr float x() const noexcept
117 [[nodiscard]]
constexpr float y() const noexcept
125 [[nodiscard]]
constexpr float z() const noexcept
130 constexpr point3& operator+=(vector3
const& rhs)
noexcept
132 return *
this = *
this + rhs;
135 constexpr point3& operator-=(vector3
const& rhs)
noexcept
137 return *
this = *
this - rhs;
147 return point3{lhs._v + array_type{rhs}};
157 return point3{array_type{lhs} + rhs._v};
167 return point3{lhs._v - array_type{rhs}};
177 return vector3{lhs._v - rhs._v};
187 return equal(lhs._v, rhs._v);
190 [[nodiscard]]
friend constexpr point3 midpoint(
point3 const& lhs,
point3 const& rhs)
noexcept
192 return point3{(lhs._v + rhs._v) * array_type::broadcast(0.5f)};
203 return point3{rhs._v - (lhs._v - rhs._v)};
213 return point3{min(lhs._v, rhs._v)};
223 return point3{max(lhs._v, rhs._v)};
230 return point3{round(rhs._v)};
237 return point3{ceil(rhs._v)};
244 return point3{floor(rhs._v)};
251 auto const rhs_ = array_type{rhs}.xyz1();
252 return point3{ceil(lhs._v / rhs_) * rhs_};
259 auto const rhs_ = array_type{rhs}.xyz1();
260 return point3{floor(lhs._v / rhs_) * rhs_};
263 [[nodiscard]]
friend float distance(
point3 const& lhs,
point3 const& rhs)
noexcept
265 return hypot(rhs - lhs);
273 return _v.w() != 0.0f;
278 return std::format(
"<{}, {}, {}>", rhs._v.x(), rhs._v.y(), rhs._v.z());
283 return lhs << to_string(rhs);
290[[nodiscard]]
constexpr point3 operator+(point2
const& lhs, vector3
const& rhs)
noexcept
292 return point3{f32x4{lhs} + f32x4{rhs}};
295[[nodiscard]]
constexpr point3 operator+(vector3
const& lhs, point2
const& rhs)
noexcept
297 return point3{f32x4{lhs} + f32x4{rhs}};
300[[nodiscard]]
constexpr point3 operator-(point2
const& lhs, vector3
const& rhs)
noexcept
302 return point3{f32x4{lhs} - f32x4{rhs}};
312struct std::formatter<
hi::point3, char> : std::formatter<std::string, char> {
313 auto format(hi::point3
const& t,
auto& fc)
const
315 return std::formatter<std::string, char>::format(std::format(
"<{}, {}, {}>", t.x(), t.y(), t.z()), 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
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point3.hpp:29
constexpr point3(float x, float y, float z=0.0f) noexcept
Construct a 3D point from x, y and z elements.
Definition point3.hpp:80
constexpr friend bool operator==(point3 const &lhs, point3 const &rhs) noexcept
Compare if two points are equal.
Definition point3.hpp:185
constexpr point3(point2 const &other, float z) noexcept
Construct a point from a lower dimension point.
Definition point3.hpp:52
constexpr point3(point2 const &other) noexcept
Construct a point from a lower dimension point.
Definition point3.hpp:41
friend constexpr point3 ceil(point3 const &lhs, extent3 rhs) noexcept
Round the coordinates of a point toward the top-right with the given granularity.
Definition point3.hpp:249
constexpr point3() noexcept
Construct a point at the origin of the coordinate system.
Definition point3.hpp:73
constexpr float & z() noexcept
Access the z element from the point.
Definition point3.hpp:101
constexpr friend point3 operator+(vector3 const &lhs, point3 const &rhs) noexcept
Move a point along a vector.
Definition point3.hpp:155
constexpr float y() const noexcept
Access the y element from the point.
Definition point3.hpp:117
friend constexpr point3 floor(point3 const &lhs, extent3 rhs) noexcept
Round the coordinates of a point toward the left-bottom with the given granularity.
Definition point3.hpp:257
friend constexpr point3 max(point3 const &lhs, point3 const &rhs) noexcept
Mix the two points and get the highest value of each element.
Definition point3.hpp:221
constexpr bool holds_invariant() const noexcept
Check if the point is valid.
Definition point3.hpp:271
friend constexpr point3 reflect(point3 const &lhs, point3 const &rhs) noexcept
Reflect a point.
Definition point3.hpp:201
constexpr point3(array_type const &other) noexcept
Construct a point from a array_type-simd.
Definition point3.hpp:66
constexpr float & x() noexcept
Access the x element from the point.
Definition point3.hpp:85
constexpr float z() const noexcept
Access the z element from the point.
Definition point3.hpp:125
friend constexpr point3 min(point3 const &lhs, point3 const &rhs) noexcept
Mix the two points and get the lowest value of each element.
Definition point3.hpp:211
constexpr float & y() noexcept
Access the y element from the point.
Definition point3.hpp:93
constexpr friend vector3 operator-(point3 const &lhs, point3 const &rhs) noexcept
Find the vector between two points.
Definition point3.hpp:175
friend constexpr point3 round(point3 const &rhs) noexcept
Round the coordinates of a point toward nearest integer.
Definition point3.hpp:228
constexpr friend point3 operator+(point3 const &lhs, vector3 const &rhs) noexcept
Move a point along a vector.
Definition point3.hpp:145
friend constexpr point3 ceil(point3 const &rhs) noexcept
Round the coordinates of a point toward the right-top.
Definition point3.hpp:235
constexpr float x() const noexcept
Access the x element from the point.
Definition point3.hpp:109
constexpr friend point3 operator-(point3 const &lhs, vector3 const &rhs) noexcept
Move a point backward along the vector.
Definition point3.hpp:165
friend constexpr point3 floor(point3 const &rhs) noexcept
Round the coordinates of a point toward the left-bottom.
Definition point3.hpp:242