Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
structs.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_MATH_STRUCTS_HPP_
2#define IV_SRC_MATH_STRUCTS_HPP_
3
4#include "core/defines.hpp"
6
7#include <vector>
8
9namespace iv::math
10{
11
12namespace geometry
13{
14
15struct Point2d
16{
17 Point2d();
19 Point2d(const Point2d &rhs);
20 Point2d(Point2d &&rhs) noexcept;
21
22 Point2d operator-() const;
23 Point2d operator+(const Point2d &rhs) const;
24 Point2d operator-(const Point2d &rhs) const;
25 Point2d operator*(const Point2d &rhs) const;
26 Point2d operator/(const Point2d &rhs) const;
28 Point2d operator/(iv::types::coord divisor) const;
29
30 Point2d &operator=(const Point2d &rhs);
31 Point2d &operator+=(const Point2d &rhs);
32 Point2d &operator-=(const Point2d &rhs);
33 Point2d &operator*=(const Point2d &rhs);
34 Point2d &operator/=(const Point2d &rhs);
35
36 bool operator==(const Point2d &rhs) const;
37 bool operator!=(const Point2d &rhs) const;
38 bool operator<(const Point2d &rhs) const;
39 bool operator>(const Point2d &rhs) const;
40 bool operator<=(const Point2d &rhs) const;
41 bool operator>=(const Point2d &rhs) const;
42
43 [[nodiscard]] iv::types::coord distance() const;
44 [[nodiscard]] iv::types::coord distance(const Point2d &rhs) const;
45
46 friend std::ostream &operator<<(std::ostream &os, const Point2d &point);
47
48 bool load(const iv::file::xml::node &nodePoint);
49 bool save(iv::file::xml::node &nodePoint) const;
50
53
54private:
55 struct Keys
56 {
57 static constexpr std::string_view x {"x"};
58 static constexpr std::string_view y {"y"};
59 };
61 {
62 static constexpr iv::types::coord x {0};
63 static constexpr iv::types::coord y {0};
64 };
65};
66
67struct Point3d
68{
69 Point3d();
71 Point3d(const Point3d &rhs);
72 Point3d(Point3d &&rhs) noexcept;
73
74 Point3d operator-() const;
75 Point3d operator+(const Point3d &rhs) const;
76 Point3d operator-(const Point3d &rhs) const;
77 Point3d operator*(const Point3d &rhs) const;
78 Point3d operator/(const Point3d &rhs) const;
80 Point3d operator/(iv::types::coord divisor) const;
81
82 Point3d &operator=(const Point3d &rhs);
83 Point3d &operator+=(const Point3d &rhs);
84 Point3d &operator-=(const Point3d &rhs);
85 Point3d &operator*=(const Point3d &rhs);
86 Point3d &operator/=(const Point3d &rhs);
87
88 bool operator==(const Point3d &rhs) const;
89 bool operator!=(const Point3d &rhs) const;
90 bool operator<(const Point3d &rhs) const;
91 bool operator>(const Point3d &rhs) const;
92 bool operator<=(const Point3d &rhs) const;
93 bool operator>=(const Point3d &rhs) const;
94
95 [[nodiscard]] iv::types::coord distance() const;
96 [[nodiscard]] iv::types::coord distance(const Point3d &rhs) const;
97
98 friend std::ostream &operator<<(std::ostream &os, const Point3d &point);
99
100 bool load(const iv::file::xml::node &nodePoint);
101 bool save(iv::file::xml::node &nodePoint) const;
102
106
107private:
108 struct Keys
109 {
110 static constexpr std::string_view x {"x"};
111 static constexpr std::string_view y {"y"};
112 static constexpr std::string_view z {"z"};
113 };
115 {
116 static constexpr iv::types::coord x {0};
117 static constexpr iv::types::coord y {0};
118 static constexpr iv::types::coord z {0};
119 };
120};
121
122struct Area
123{
124 Area &operator=(const Area &rhs);
125 bool operator==(const Area &rhs) const;
126 bool operator!=(const Area &rhs) const;
127 bool operator<(const Area &rhs) const;
128 bool operator>(const Area &rhs) const;
129 bool operator<=(const Area &rhs) const;
130 bool operator>=(const Area &rhs) const;
131
134};
135
136template<typename T>
137 requires std::is_same_v<T, iv::math::geometry::Point2d> || std::is_same_v<T, iv::math::geometry::Point3d>
138float *toArrayOfFloats(const std::vector<T> &v)
139{
140 auto *array = static_cast<float *>(calloc(v.size() * sizeof(T) / sizeof(iv::types::coord), sizeof(float)));
141
142 for (size_t i = 0; i < v.size(); ++i)
143 {
144 array[i * sizeof(T) / sizeof(iv::types::coord)] = static_cast<float>(v[i].x);
145 array[i * sizeof(T) / sizeof(iv::types::coord) + 1] = static_cast<float>(v[i].y);
146
147 if constexpr (std::is_same_v<T, iv::math::geometry::Point3d>)
148 {
149 array[i * sizeof(T) / sizeof(iv::types::coord) + 2] = static_cast<float>(v[i].z);
150 }
151 }
152
153 return array;
154}
155
156}// namespace geometry
157
158}// namespace iv::math
159
160#endif//IV_SRC_MATH_STRUCTS_HPP_
Definition xmlFile.hpp:15
float * toArrayOfFloats(const std::vector< T > &v)
Definition structs.hpp:138
Definition utils.hpp:267
double height
Definition types.hpp:14
double width
Definition types.hpp:23
double coord
Definition types.hpp:13
Definition structs.hpp:123
iv::types::width width
Definition structs.hpp:133
bool operator>(const Area &rhs) const
Definition structs.cpp:366
bool operator>=(const Area &rhs) const
Definition structs.cpp:376
Area & operator=(const Area &rhs)
Definition structs.cpp:340
bool operator<(const Area &rhs) const
Definition structs.cpp:361
bool operator==(const Area &rhs) const
Definition structs.cpp:351
bool operator!=(const Area &rhs) const
Definition structs.cpp:356
iv::types::height height
Definition structs.hpp:132
bool operator<=(const Area &rhs) const
Definition structs.cpp:371
static constexpr iv::types::coord y
Definition structs.hpp:63
static constexpr iv::types::coord x
Definition structs.hpp:62
Definition structs.hpp:56
static constexpr std::string_view x
Definition structs.hpp:57
static constexpr std::string_view y
Definition structs.hpp:58
Definition structs.hpp:16
Point2d operator*(const Point2d &rhs) const
Definition structs.cpp:27
Point2d & operator-=(const Point2d &rhs)
Definition structs.cpp:66
bool operator>=(const Point2d &rhs) const
Definition structs.cpp:124
Point2d & operator/=(const Point2d &rhs)
Definition structs.cpp:82
Point2d & operator=(const Point2d &rhs)
Definition structs.cpp:47
Point2d operator/(const Point2d &rhs) const
Definition structs.cpp:32
bool operator<(const Point2d &rhs) const
Definition structs.cpp:109
bool operator>(const Point2d &rhs) const
Definition structs.cpp:114
iv::types::coord y
Definition structs.hpp:52
Point2d & operator+=(const Point2d &rhs)
Definition structs.cpp:58
Point2d()
Definition structs.cpp:90
friend std::ostream & operator<<(std::ostream &os, const Point2d &point)
Definition structs.cpp:139
bool operator==(const Point2d &rhs) const
Definition structs.cpp:99
Point2d & operator*=(const Point2d &rhs)
Definition structs.cpp:74
Point2d operator+(const Point2d &rhs) const
Definition structs.cpp:17
Point2d operator-() const
Definition structs.cpp:12
iv::types::coord x
Definition structs.hpp:51
iv::types::coord distance() const
Definition structs.cpp:129
bool load(const iv::file::xml::node &nodePoint)
Definition structs.cpp:145
bool operator<=(const Point2d &rhs) const
Definition structs.cpp:119
bool operator!=(const Point2d &rhs) const
Definition structs.cpp:104
bool save(iv::file::xml::node &nodePoint) const
Definition structs.cpp:152
static constexpr iv::types::coord y
Definition structs.hpp:117
static constexpr iv::types::coord z
Definition structs.hpp:118
static constexpr iv::types::coord x
Definition structs.hpp:116
Definition structs.hpp:109
static constexpr std::string_view z
Definition structs.hpp:112
static constexpr std::string_view x
Definition structs.hpp:110
static constexpr std::string_view y
Definition structs.hpp:111
Definition structs.hpp:68
bool operator<=(const Point3d &rhs) const
Definition structs.cpp:281
Point3d()
Definition structs.cpp:170
Point3d operator/(const Point3d &rhs) const
Definition structs.cpp:198
bool operator>=(const Point3d &rhs) const
Definition structs.cpp:286
bool load(const iv::file::xml::node &nodePoint)
Definition structs.cpp:308
iv::types::coord x
Definition structs.hpp:103
Point3d & operator=(const Point3d &rhs)
Definition structs.cpp:213
bool operator>(const Point3d &rhs) const
Definition structs.cpp:276
bool operator<(const Point3d &rhs) const
Definition structs.cpp:271
iv::types::coord distance() const
Definition structs.cpp:291
Point3d operator-() const
Definition structs.cpp:178
Point3d operator*(const Point3d &rhs) const
Definition structs.cpp:193
Point3d & operator+=(const Point3d &rhs)
Definition structs.cpp:225
Point3d & operator/=(const Point3d &rhs)
Definition structs.cpp:252
friend std::ostream & operator<<(std::ostream &os, const Point3d &point)
Definition structs.cpp:301
iv::types::coord z
Definition structs.hpp:105
Point3d & operator-=(const Point3d &rhs)
Definition structs.cpp:234
bool save(iv::file::xml::node &nodePoint) const
Definition structs.cpp:317
Point3d operator+(const Point3d &rhs) const
Definition structs.cpp:183
iv::types::coord y
Definition structs.hpp:104
bool operator==(const Point3d &rhs) const
Definition structs.cpp:261
Point3d & operator*=(const Point3d &rhs)
Definition structs.cpp:243
bool operator!=(const Point3d &rhs) const
Definition structs.cpp:266