API Documentation
Loading...
Searching...
No Matches
RadialObject.hpp
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: RadialObject
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/BaseValues.h>
34#include <NDEVR/Vertex.h>
35#include <NDEVR/VectorFunctions.h>
36#include "Matrix.hpp"
37
38/**--------------------------------------------------------------------------------------------------
39Namespace: Parke
40Namespace that wraps all Logic created by Tyler Parke
41 *-----------------------------------------------------------------------------------------------**/
42
43namespace NDEVR
44{
45
46 /**--------------------------------------------------------------------------------------------------
47 Class: RadialObject
48
49 \brief A radial object.
50
51 Author: Tyler Parke
52
53 Date: 2017-11-19
54 *-----------------------------------------------------------------------------------------------**/
55 template<uint01 t_dims, class t_type, class t_vertex = Vertex<t_dims, t_type>>
57 {
58 public:
59 constexpr RadialObject(t_type r = 0)
60 : m_center(0)
61 , m_radius(r)
62 {}
63 constexpr RadialObject(const t_vertex& center, t_type radius)
64 : m_center(center)
65 , m_radius(radius)
66 {}
67 /**--------------------------------------------------------------------------------------------------
68 Fn: , RadialObject::m_center(Constant<t_type>::NaN)
69
70 Constructor.
71
72 Author: Tyler Parke
73
74 Date: 2017-11-19
75
76 Parameters:
77 parameter1 - The first parameter.
78 *-----------------------------------------------------------------------------------------------**/
79
80 constexpr RadialObject(const t_vertex& vertex_a, const t_vertex& vertex_b, const t_vertex& vertex_c)
81 : m_center(Constant<t_type>::NaN)
82 , m_radius(Constant<t_type>::NaN)
83 {
84 static_assert(t_dims == 2, "Radial Object given 3 points must be defined in 2 dimensions");
85 const t_vertex a = (vertex_a + vertex_b) / cast<t_type>(2);
86 const t_vertex b = (vertex_c + vertex_b) / cast<t_type>(2);
87
88 const t_vertex e(vertex_b[Y] - vertex_a[Y], vertex_a[X] - vertex_b[X]);
89 const t_vertex q(vertex_b[Y] - vertex_c[Y], vertex_c[X] - vertex_b[X]);
90
91 if (e[Y] * q[X] - e[X] * q[Y] != cast<t_type>(0))
92 {
93 m_center = b + q * (e[X] * (b[Y] - a[Y]) - e[Y] * (b[X] - a[X])) / (e[Y] * q[X] - e[X] * q[Y]);
94 m_radius = distance<t_type>(vertex_a, m_center);
95 }
96 }
97
98
99 /**--------------------------------------------------------------------------------------------------
100 Fn: constexpr bool RadialObject::contains(const t_vertex& vector) const
101
102 Query if this object contains the given vector.
103
104 Author: Tyler Parke
105
106 Date: 2017-11-19
107
108 Parameters:
109 vector - The const t_vertex&amp; to test for containment.
110
111 Returns: True if the object is in this collection, false if not.
112 *-----------------------------------------------------------------------------------------------**/
113 template<bool t_allow_bounds = true>
114 constexpr bool contains(const t_vertex& vector) const
115 {
116 if(t_allow_bounds)
117 return distanceSquared(m_center, vector) <= m_radius * m_radius;
118 else
119 return distanceSquared(m_center, vector) < m_radius * m_radius;
120 }
121
122 /**--------------------------------------------------------------------------------------------------
123 Fn: constexpr t_type RadialObject::radius() const
124
125 Gets the radius.
126
127 Author: Tyler Parke
128
129 Date: 2017-11-19
130
131 Returns: A t_type.
132 *-----------------------------------------------------------------------------------------------**/
133
134 constexpr t_type radius() const {return m_radius;}
135
136
137
138 /**--------------------------------------------------------------------------------------------------
139 Fn: constexpr RadialObject<t_new_dims, t_new_type> RadialObject::as() const
140
141 Gets as.
142
143 Author: Tyler Parke
144
145 Date: 2017-11-19
146
147 Returns: A RadialObject&lt;t_new_dims,t_new_type&gt;
148 *-----------------------------------------------------------------------------------------------**/
149 template<uint01 t_new_dims, class t_new_type, class t_new_vertex = Vertex<t_new_dims, t_new_type>>
151 {
152 return RadialObject<t_new_dims, t_new_type>(t_new_vertex(m_center.template as<t_new_dims, t_new_type>()), cast<t_new_type>(m_radius));
153 }
154
155 /**--------------------------------------------------------------------------------------------------
156 Fn: constexpr const t_vertex& RadialObject::center() const
157
158 Gets the center.
159
160 Author: Tyler Parke
161
162 Date: 2017-11-19
163
164 Returns: A reference to a const t_vertex.
165 *-----------------------------------------------------------------------------------------------**/
166
167 [[nodiscard]] constexpr const t_vertex& center() const {return m_center;}
168
169 bool operator==(const RadialObject& rad) const
170 {
171 return m_radius == rad.m_radius && (m_center == rad.m_center);
172 }
173 bool operator!=(const RadialObject& rad) const
174 {
175 return m_radius != rad.m_radius || m_center != rad.m_center;
176 }
177 private:
178 /** The center. */
179 t_vertex m_center;
180 /** The radius. */
181 t_type m_radius;
182 };
183
184 template<uint01 t_dims, class t_type, class t_vector>
185 struct Constant<RadialObject<t_dims, t_type, t_vector>>
186 {
188 constexpr const static RadialObject<t_dims, t_type, t_vector> Min{ t_vector(0), 0 };
190 };
191
192 /**--------------------------------------------------------------------------------------------------
193 Class: BiRadialObject
194
195 A bi radial object.
196
197 Author: Tyler Parke
198
199 Date: 2017-11-19
200 *-----------------------------------------------------------------------------------------------**/
201 template<uint01 t_dims, class t_type, class t_vertex = Vertex<t_dims, t_type>>
203 {
204 public:
205 constexpr BiRadialObject(t_type r = 0)
206 : m_axis_major(Vector<t_dims, t_type>(0.0))
207 , m_radius(r)
208 {}
209 constexpr BiRadialObject(const t_vertex& p1, const t_vertex& p2, t_type radius)
210 : m_axis_major(p1, p2)
211 , m_radius(radius)
212 {}
213
214
215 template<class t_matrix_type = fltp08>
217 {
220 Ray<3, fltp08> direction = mat * Ray<3, fltp08>(0.5, 0, 0);
221
222 object.m_axis_major[A] = center + direction;
223 object.m_axis_major[B] = center - direction;
224
226
227 object.m_radius = getMin(scale[X], scale[Y]);
228
229 return object;
230 }
231 /**--------------------------------------------------------------------------------------------------
232 Fn: constexpr bool BiRadialObject::contains(const Vector<t_dims, t_type>& vector) const
233
234 Query if this object contains the given vector.
235
236 Author: Tyler Parke
237
238 Date: 2017-11-19
239
240 Parameters:
241 vector - The const Vector&lt;t_dims,t_type&gt;&amp; to test for containment.
242
243 Returns: True if the object is in this collection, false if not.
244 *-----------------------------------------------------------------------------------------------**/
245
246 constexpr bool contains(const t_vertex& vector) const
247 {
248 fltp08 total_distance = distance<fltp08>(m_axis_major[A], vector) + distance<fltp08>(m_axis_major[B], vector);
249 return m_radius > total_distance - distance<fltp08>(m_axis_major[A], m_axis_major[B]);
250 }
251
252 /**--------------------------------------------------------------------------------------------------
253 Fn: constexpr t_type BiRadialObject::radius() const
254
255 Gets the radius.
256
257 Author: Tyler Parke
258
259 Date: 2017-11-19
260
261 Returns: A t_type.
262 *-----------------------------------------------------------------------------------------------**/
263
264 constexpr t_type radius() const { return m_radius; }
265
266
267
268 /**--------------------------------------------------------------------------------------------------
269 Fn: constexpr BiRadialObject<t_new_dims, t_new_type> BiRadialObject::as() const
270
271 Gets as.
272
273 Author: Tyler Parke
274
275 Date: 2017-11-19
276
277 Returns: A RadialObject&lt;t_new_dims,t_new_type&gt;
278 *-----------------------------------------------------------------------------------------------**/
279 template<uint01 t_new_dims, class t_new_type>
281 {
282 return BiRadialObject<t_new_dims, t_new_type>(m_axis_major[A].template as<t_new_dims, t_new_type>(), m_axis_major[B].template as<t_new_dims, t_new_type>(), cast<t_new_type>(m_radius));
283 }
284
285 /**--------------------------------------------------------------------------------------------------
286 Fn: constexpr const t_vertex& BiRadialObject::center() const
287
288 Gets the center.
289
290 Author: Tyler Parke
291
292 Date: 2017-11-19
293
294 Returns: The centerpoint of the Biradial object (Or the intersection of the major and minor axis);
295 *-----------------------------------------------------------------------------------------------**/
296
297 constexpr t_vertex center() const { return t_vertex((m_axis_major[A] + m_axis_major[B]) / cast<t_type>(2)); }
298 constexpr const t_vertex& axisPoint(uint01 vertex) const
299 {
300 return m_axis_major[vertex];
301 }
302
303 template<class t_ratio_type = fltp08>
304 t_ratio_type minorToMajorRatio() const
305 {
306 const t_ratio_type axis_distance = distance<t_ratio_type>(m_axis_major[A], m_axis_major[B]);
307 return cast<t_ratio_type>(m_radius) / (cast<t_ratio_type>(m_radius) + axis_distance / cast<t_ratio_type>(2));
308 }
309 template<class t_matrix_type = fltp08>
311 {
313 if (m_axis_major[B] - m_axis_major[A] == t_vertex(0))
314 return mat;
315 Vector<t_dims, t_type> axis = (m_axis_major[B] - m_axis_major[A]).template normalized<t_matrix_type>();
316 t_matrix_type scale = cast<t_matrix_type>(1) / minorToMajorRatio<t_matrix_type>();
317 mat = mat.scale(axis, scale);
318 return mat;
319 }
320 private:
321 /** The 1. */
322 Vector<2, t_vertex> m_axis_major;
323 /** The radius. */
324 t_type m_radius;
325 };
326};
Definition RadialObject.hpp:203
t_ratio_type minorToMajorRatio() const
Definition RadialObject.hpp:304
constexpr t_type radius() const
Definition RadialObject.hpp:264
constexpr const t_vertex & axisPoint(uint01 vertex) const
Definition RadialObject.hpp:298
Matrix< t_matrix_type > fromCircleTransform() const
Definition RadialObject.hpp:310
constexpr BiRadialObject< t_new_dims, t_new_type > as() const
Definition RadialObject.hpp:280
static BiRadialObject< t_dims, t_type, t_vertex > fromCircleTransform(const Matrix< t_matrix_type > &mat)
Definition RadialObject.hpp:216
constexpr bool contains(const t_vertex &vector) const
Definition RadialObject.hpp:246
constexpr t_vertex center() const
Definition RadialObject.hpp:297
constexpr BiRadialObject(const t_vertex &p1, const t_vertex &p2, t_type radius)
Definition RadialObject.hpp:209
constexpr BiRadialObject(t_type r=0)
Definition RadialObject.hpp:205
Definition Matrix.hpp:173
constexpr Matrix scale(t_type scale) const
Definition Matrix.hpp:579
constexpr Vector< 3, t_type > decomposeOffset() const
Definition Matrix.hpp:440
static constexpr Matrix< t_type > ScalerMatrix(t_type scale)
Definition Matrix.hpp:304
constexpr Vector< 3, t_type > decomposeScale() const
Definition Matrix.hpp:421
A radial object.
Definition RadialObject.hpp:57
constexpr RadialObject< t_new_dims, t_new_type > as() const
Definition RadialObject.hpp:150
constexpr t_type radius() const
Definition RadialObject.hpp:134
constexpr RadialObject(const t_vertex &center, t_type radius)
Definition RadialObject.hpp:63
constexpr RadialObject(const t_vertex &vertex_a, const t_vertex &vertex_b, const t_vertex &vertex_c)
Definition RadialObject.hpp:80
constexpr RadialObject(t_type r=0)
Definition RadialObject.hpp:59
bool operator!=(const RadialObject &rad) const
Definition RadialObject.hpp:173
bool operator==(const RadialObject &rad) const
Definition RadialObject.hpp:169
constexpr const t_vertex & center() const
Definition RadialObject.hpp:167
constexpr bool contains(const t_vertex &vector) const
Definition RadialObject.hpp:114
Definition Vertex.hpp:341
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
A vertex.
Definition Vertex.hpp:54
Definition ACIColor.h:37
@ vertex_a
Definition Triangle.hpp:57
@ vertex_b
Definition Triangle.hpp:58
@ vertex_c
Definition Triangle.hpp:59
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:42
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr t_type distance(const t_vertex &vertex, const LineSegment< t_dims, t_type, t_vertex > &line)
Definition Distance.hpp:250
@ B
Definition BaseValues.hpp:203
@ A
Definition BaseValues.hpp:201
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator.
Definition BaseFunctions.hpp:67
Definition BaseValues.hpp:272
static const t_type Min
Definition BaseValues.hpp:276
static const t_type Max
Definition BaseValues.hpp:278
static const t_type NaN
Definition BaseValues.hpp:274