10#include "../SIMD/module.hpp"
11#include "../utility/utility.hpp"
12#include "../macros.hpp"
29 using array_type = simd<float, 4>;
30 using value_type = array_type::value_type;
34 constexpr point3& operator=(
point3 const&)
noexcept =
default;
35 constexpr point3& operator=(
point3&&)
noexcept =
default;
39 [[nodiscard]]
constexpr point3(
point2 const& other) noexcept : _v(
static_cast<array_type
>(other)) {}
41 [[nodiscard]]
constexpr explicit operator point2() const noexcept
50 [[nodiscard]]
constexpr point3(
point2 const& other,
float z) noexcept : _v(
static_cast<array_type
>(other))
57 [[nodiscard]]
constexpr explicit operator array_type() const noexcept
64 [[nodiscard]]
constexpr explicit point3(array_type
const& other) noexcept : _v(other)
66 hi_axiom(holds_invariant());
71 [[nodiscard]]
constexpr point3() noexcept : _v(0.0f, 0.0f, 0.0f, 1.0f) {}
78 [[nodiscard]]
constexpr point3(
float x,
float y,
float z = 0.0f) noexcept : _v(x, y, z, 1.0f) {}
83 [[nodiscard]]
constexpr float&
x() noexcept
91 [[nodiscard]]
constexpr float&
y() noexcept
99 [[nodiscard]]
constexpr float&
z() noexcept
107 [[nodiscard]]
constexpr float x() const noexcept
115 [[nodiscard]]
constexpr float y() const noexcept
123 [[nodiscard]]
constexpr float z() const noexcept
128 constexpr point3& operator+=(vector3
const& rhs)
noexcept
130 return *
this = *
this + rhs;
133 constexpr point3& operator-=(vector3
const& rhs)
noexcept
135 return *
this = *
this - rhs;
145 return point3{lhs._v + array_type{rhs}};
155 return point3{array_type{lhs} + rhs._v};
165 return point3{lhs._v - array_type{rhs}};
175 return vector3{lhs._v - rhs._v};
185 return equal(lhs._v, rhs._v);
188 [[nodiscard]]
friend constexpr point3 midpoint(
point3 const& lhs,
point3 const& rhs)
noexcept
190 return point3{midpoint(lhs._v, rhs._v)};
193 [[nodiscard]]
friend constexpr point3 reflect(point3
const& lhs, point3
const& rhs)
noexcept
195 return point3{reflect_point(lhs._v, rhs._v)};
205 return point3{min(lhs._v, rhs._v)};
215 return point3{max(lhs._v, rhs._v)};
222 return point3{round(rhs._v)};
229 return point3{ceil(rhs._v)};
236 return point3{floor(rhs._v)};
243 hilet rhs_ = array_type{rhs}.xyz1();
244 return point3{ceil(lhs._v / rhs_) * rhs_};
251 hilet rhs_ = array_type{rhs}.xyz1();
252 return point3{floor(lhs._v / rhs_) * rhs_};
255 [[nodiscard]]
friend float distance(
point3 const& lhs,
point3 const& rhs)
noexcept
257 return hypot(rhs - lhs);
265 return _v.w() != 0.0f;
270 return std::format(
"<{}, {}, {}>", rhs._v.x(), rhs._v.y(), rhs._v.z());
275 return lhs << to_string(rhs);
282[[
nodiscard]]
constexpr point3 operator+(point2
const& lhs, vector3
const& rhs)
noexcept
287[[
nodiscard]]
constexpr point3 operator+(vector3
const& lhs, point2
const& rhs)
noexcept
292[[
nodiscard]]
constexpr point3 operator-(point2
const& lhs, vector3
const& rhs)
noexcept
302template<
typename CharT>
303struct std::formatter<
hi::point3, CharT> {
309 auto format(hi::point3
const& t,
auto& fc)
const
311 return std::vformat_to(fc.out(),
"<{}, {}, {}>", std::make_format_args(t.x(), t.y(), t.z()));
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
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point3.hpp:27
constexpr point3(float x, float y, float z=0.0f) noexcept
Construct a 3D point from x, y and z elements.
Definition point3.hpp:78
constexpr friend bool operator==(point3 const &lhs, point3 const &rhs) noexcept
Compare if two points are equal.
Definition point3.hpp:183
constexpr point3(point2 const &other, float z) noexcept
Construct a point from a lower dimension point.
Definition point3.hpp:50
constexpr point3(point2 const &other) noexcept
Construct a point from a lower dimension point.
Definition point3.hpp:39
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:241
constexpr point3() noexcept
Construct a point at the origin of the coordinate system.
Definition point3.hpp:71
constexpr float & z() noexcept
Access the z element from the point.
Definition point3.hpp:99
constexpr friend point3 operator+(vector3 const &lhs, point3 const &rhs) noexcept
Move a point along a vector.
Definition point3.hpp:153
constexpr float y() const noexcept
Access the y element from the point.
Definition point3.hpp:115
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:249
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:213
constexpr bool holds_invariant() const noexcept
Check if the point is valid.
Definition point3.hpp:263
constexpr point3(array_type const &other) noexcept
Construct a point from a array_type-simd.
Definition point3.hpp:64
constexpr float & x() noexcept
Access the x element from the point.
Definition point3.hpp:83
constexpr float z() const noexcept
Access the z element from the point.
Definition point3.hpp:123
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:203
constexpr float & y() noexcept
Access the y element from the point.
Definition point3.hpp:91
constexpr friend vector3 operator-(point3 const &lhs, point3 const &rhs) noexcept
Find the vector between two points.
Definition point3.hpp:173
friend constexpr point3 round(point3 const &rhs) noexcept
Round the coordinates of a point toward nearest integer.
Definition point3.hpp:220
constexpr friend point3 operator+(point3 const &lhs, vector3 const &rhs) noexcept
Move a point along a vector.
Definition point3.hpp:143
friend constexpr point3 ceil(point3 const &rhs) noexcept
Round the coordinates of a point toward the right-top.
Definition point3.hpp:227
constexpr float x() const noexcept
Access the x element from the point.
Definition point3.hpp:107
constexpr friend point3 operator-(point3 const &lhs, vector3 const &rhs) noexcept
Move a point backward along the vector.
Definition point3.hpp:163
friend constexpr point3 floor(point3 const &rhs) noexcept
Round the coordinates of a point toward the left-bottom.
Definition point3.hpp:234