acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
pole.h
1// Created by camilo on 2022-04-26 19:06 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5//#include "acme/prototype/geometry2d/_geometry2d.h"
6
7
9{
10
11 union
12 {
13
14 struct
15 {
16
17 ::f64 x;
18 ::f64 y;
19 ::f64 z;
20
21 };
22
23 struct
24 {
25
26 ::f64 cx;
27 ::f64 cy;
28 ::f64 cz;
29
30 };
31
32 struct
33 {
34
35 ::f64 px;
36 ::f64 py;
37 ::f64 pz;
38
39 };
40
41 ::f64 da[3];
42
43 };
44
45
46};
47
48
49template < prototype_number NUMBER >
50class pole_type :
51 public sequence_type < NUMBER, 3 >
52{
53public:
54
55
56 using SIZE_TYPE = size_type < NUMBER >;
57 using POINT_TYPE = size_type < NUMBER >;
58 using UNIT_TYPE = NUMBER;
59
60
61 pole_type(nullptr_t = nullptr) : sequence_type<NUMBER, 3>() { }
62 pole_type(no_initialize_t) { }
63 template < prototype_number X, prototype_number Y, prototype_number Z >
64 pole_type(X xP, Y yP, Z zP) { this->x = xP; this->y = yP; this->z = zP; }
65
66
67 //const UNIT_TYPE& x() const { return this->x; }
68 //UNIT_TYPE& x() { return this->x; }
69 //const UNIT_TYPE& y() const { return this->y; }
70 //UNIT_TYPE& y() { return this->y; }
71 //const UNIT_TYPE& z() const { return this->c(); }
72 //UNIT_TYPE& z() { return this->c(); }
73
74
75 template < prototype_pole POLE >
76 pole_type operator +(const POLE& pole) const
77 {
78
79 pole_type p;
80
81 p.x = this->x + pole.x;
82 p.y = this->y + pole.y;
83 p.z = this->z + pole.z;
84
85 return p;
86
87 }
88
89
90 template < prototype_pole POLE >
91 pole_type& operator +=(const POLE& pole)
92 {
93
94 this->x += pole.x;
95 this->y += pole.y;
96 this->z += pole.z;
97
98 return *this;
99
100 }
101
102
103 template < prototype_pole POLE >
104 pole_type& operator -=(const POLE& pole)
105 {
106
107 this->x -= pole.x;
108 this->y -= pole.y;
109 this->z -= pole.z;
110
111 return *this;
112
113 }
114
115
116 template < prototype_pole POLE >
117 pole_type& operator = (const POLE& pole)
118 {
119
120 this->x = pole.x;
121 this->y = pole.y;
122 this->z = pole.z;
123
124 return *this;
125
126 }
127
128
129 template < prototype_number NUMBER_TYPE >
130 pole_type& operator *= (NUMBER_TYPE n)
131 {
132
133 this->x *= n;
134 this->y *= n;
135 this->z *= n;
136
137 return *this;
138
139 }
140
141
142 template < prototype_number NUMBER_TYPE >
143 pole_type operator * (NUMBER_TYPE n)
144 {
145
146 pole_type pole(*this);
147
148 pole *= n;
149
150 return pole;
151
152 }
153
154
155 SIZE_TYPE& cxy() { return (SIZE_TYPE&)*this; }
156 const SIZE_TYPE& cxy()const { return (const SIZE_TYPE&)*this; }
157
158
159 template < prototype_pole POLE >
160 pole_type& rotate(const POLE& pole)
161 {
162
163 pole_type pole1;
164 pole1.x = this->x * cos(pole.z) - this->y * sin(pole.z);
165 pole1.y = this->x * sin(pole.z) + this->y * cos(pole.z);
166 pole1.z = this->z;
167
168 pole_type pole2;
169 pole2.y = pole1.y * cos(pole.x) - pole1.z * sin(pole.x);
170 pole2.z = pole1.y * sin(pole.x) + pole1.z * cos(pole.x);
171 pole2.x = pole1.x;
172
173 this->z = pole2.z * cos(pole.y) - pole2.x * sin(pole.y);
174 this->x = pole2.z * sin(pole.y) + pole2.x * cos(pole.y);
175 this->y = pole2.y;
176
177 return *this;
178
179 }
180
181 //operator POLED *() { return this; }
182 //operator const POLED * () const { return this; }
183
184
185};
186
187
188template < prototype_pole POLE >
189inline typename POLE::POINT_TYPE & __point(POLE & pole)
190{
191
192 return (typename POLE::POINT_TYPE&)(pole);
193
194}
195
196
197template < prototype_pole POLE >
198inline ::f64_point as_f64_point(const POLE & pole)
199{
200
201 return { (::f64)pole.x, (::f64)pole.y };
202
203}
204
205
206template < prototype_pole POLE >
207inline ::i32_point as_i32_point(const POLE & pole)
208{
209
210 return {(::i32)pole.x, (::i32) pole.y };
211
212}
213
214
215using i32_pole = ::pole_type < ::i32 >;
216using i64_pole = ::pole_type < ::i64>;
217using f32_pole = ::pole_type < ::f32 >;
218using f64_pole = ::pole_type < ::f64 >;
219
220
221
222
Definition pole.h:9
Definition _tags.h:5