Move Vectormath main
C++20 game and graphics mathematics
Loading...
Searching...
No Matches
Point3.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <type_traits>
5
6#include <mv/math/Vec3.hpp>
7
8namespace mv::math
9{
10 template <typename T>
11 requires std::is_arithmetic_v<T>
12 class Point3
13 {
14 public:
15 using Component = T;
16
18
19 Point3(T x, T y, T z) noexcept : Value_(x, y, z)
20 {
21 }
22
24 {
25 return Point3();
26 }
27
28 [[nodiscard]] static Point3 FromVector(const Vec3<T>& value) noexcept
29 {
30 return Point3(value);
31 }
32
34 {
35 return Value_;
36 }
37
39 {
40 return Value_.X();
41 }
42
44 {
45 return Value_.Y();
46 }
47
49 {
50 return Value_.Z();
51 }
52
54 const Vec3<T>& displacement) const noexcept
55 {
56 return Point3(Value_ + displacement);
57 }
58
60 const Vec3<T>& displacement) const noexcept
61 {
62 return Point3(Value_ - displacement);
63 }
64
65 [[nodiscard]] Vec3<T> operator-(const Point3& other) const noexcept
66 {
67 return Value_ - other.Value_;
68 }
69
71 {
72 Value_ += displacement;
73 return *this;
74 }
75
77 {
78 Value_ -= displacement;
79 return *this;
80 }
81
82 [[nodiscard]] friend bool operator==(const Point3& left,
83 const Point3& right) noexcept
84 {
85 return left.Value_ == right.Value_;
86 }
87
88 private:
89 explicit Point3(const Vec3<T>& value) noexcept : Value_(value)
90 {
91 }
92
93 Vec3<T> Value_;
94 };
95
108} // namespace mv::math
109
110static_assert(sizeof(mv::math::Point3f) == sizeof(mv::math::Vec3f));
111static_assert(alignof(mv::math::Point3f) == alignof(mv::math::Vec3f));
112static_assert(std::is_trivially_copyable_v<mv::math::Point3f>);
113static_assert(std::is_standard_layout_v<mv::math::Point3f>);
114static_assert(sizeof(mv::math::Point3d) == sizeof(mv::math::Vec3d));
115static_assert(alignof(mv::math::Point3d) == alignof(mv::math::Vec3d));
116static_assert(std::is_trivially_copyable_v<mv::math::Point3d>);
117static_assert(std::is_standard_layout_v<mv::math::Point3d>);
Point3() noexcept=default
T Y() const noexcept
Definition Point3.hpp:43
Point3 operator+(const Vec3< T > &displacement) const noexcept
Definition Point3.hpp:53
static Point3 Origin() noexcept
Definition Point3.hpp:23
const Vec3< T > & Vector() const noexcept
Definition Point3.hpp:33
Vec3< T > operator-(const Point3 &other) const noexcept
Definition Point3.hpp:65
Point3 & operator-=(const Vec3< T > &displacement) noexcept
Definition Point3.hpp:76
friend bool operator==(const Point3 &left, const Point3 &right) noexcept
Definition Point3.hpp:82
static Point3 FromVector(const Vec3< T > &value) noexcept
Definition Point3.hpp:28
T Z() const noexcept
Definition Point3.hpp:48
T X() const noexcept
Definition Point3.hpp:38
Point3 & operator+=(const Vec3< T > &displacement) noexcept
Definition Point3.hpp:70
Point3 operator-(const Vec3< T > &displacement) const noexcept
Definition Point3.hpp:59
Point3< std::uint32_t > Point3u32
Definition Point3.hpp:103
Point3< std::int32_t > Point3i32
Definition Point3.hpp:102
Point3< float > Point3f
Definition Point3.hpp:96
Point3< double > Point3d
Definition Point3.hpp:97