API Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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
38namespace NDEVR
39{
40
41 /**--------------------------------------------------------------------------------------------------
42 Class: RadialObject
43
44 \brief A radial object.
45
46 Author: Tyler Parke
47
48 Date: 2017-11-19
49 **/
50 template<uint01 t_dims, class t_type, class t_vertex = Vertex<t_dims, t_type>>
52 {
53 public:
54 constexpr RadialObject(t_type r = 0)
55 : m_center(0)
56 , m_radius(r)
57 {}
58 constexpr RadialObject(const t_vertex& center, t_type radius)
59 : m_center(center)
60 , m_radius(radius)
61 {}
62 /**--------------------------------------------------------------------------------------------------
63 Constructor.
64
65 Author: Tyler Parke
66
67 Date: 2017-11-19
68
69 Parameters:
70 parameter1 - The first parameter.
71 **/
72
73 constexpr RadialObject(const t_vertex& vertex_a, const t_vertex& vertex_b, const t_vertex& vertex_c)
74 : m_center(Constant<t_type>::Invalid)
75 , m_radius(Constant<t_type>::Invalid)
76 {
77 static_assert(t_dims == 2, "Radial Object given 3 points must be defined in 2 dimensions");
78 const t_vertex a = (vertex_a + vertex_b) / cast<t_type>(2);
79 const t_vertex b = (vertex_c + vertex_b) / cast<t_type>(2);
80
81 const t_vertex e(vertex_b[Y] - vertex_a[Y], vertex_a[X] - vertex_b[X]);
82 const t_vertex q(vertex_b[Y] - vertex_c[Y], vertex_c[X] - vertex_b[X]);
83
84 if (e[Y] * q[X] - e[X] * q[Y] != cast<t_type>(0))
85 {
86 m_center = b + q * (e[X] * (b[Y] - a[Y]) - e[Y] * (b[X] - a[X])) / (e[Y] * q[X] - e[X] * q[Y]);
87 m_radius = distance<t_type>(vertex_a, m_center);
88 }
89 }
90
91
92 /**--------------------------------------------------------------------------------------------------
93 Query if this object contains the given vector.
94
95 Author: Tyler Parke
96
97 Date: 2017-11-19
98
99 Parameters:
100 vector - The const t_vertex&amp; to test for containment.
101
102 \returns True if the object is in this collection, false if not.
103 **/
104 template<bool t_allow_bounds = true>
105 constexpr bool contains(const t_vertex& vector) const
106 {
107 if(t_allow_bounds)
108 return distanceSquared(m_center, vector) <= m_radius * m_radius;
109 else
110 return distanceSquared(m_center, vector) < m_radius * m_radius;
111 }
112
113 /**--------------------------------------------------------------------------------------------------
114 Gets the radius.
115
116 Author: Tyler Parke
117
118 Date: 2017-11-19
119
120 \returns A t_type.
121 **/
122
123 constexpr t_type radius() const {return m_radius;}
124
125
126
127 /**--------------------------------------------------------------------------------------------------
128 Gets as.
129
130 Author: Tyler Parke
131
132 Date: 2017-11-19
133
134 \returns A RadialObject&lt;t_new_dims,t_new_type&gt;
135 **/
136 template<uint01 t_new_dims, class t_new_type, class t_new_vertex = Vertex<t_new_dims, t_new_type>>
138 {
139 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));
140 }
141
142 /**--------------------------------------------------------------------------------------------------
143 Gets the center.
144
145 Author: Tyler Parke
146
147 Date: 2017-11-19
148
149 \returns A reference to a const t_vertex.
150 **/
151
152 [[nodiscard]] constexpr const t_vertex& center() const {return m_center;}
153
154 bool operator==(const RadialObject& rad) const
155 {
156 return m_radius == rad.m_radius && (m_center == rad.m_center);
157 }
158 bool operator!=(const RadialObject& rad) const
159 {
160 return m_radius != rad.m_radius || m_center != rad.m_center;
161 }
162 private:
163 /** The center. */
164 t_vertex m_center;
165 /** The radius. */
166 t_type m_radius;
167 };
168
169 template<uint01 t_dims, class t_type, class t_vector>
170 struct Constant<RadialObject<t_dims, t_type, t_vector>>
171 {
172 constexpr const static RadialObject<t_dims, t_type, t_vector> Invalid{ Constant<t_vector>::Invalid, Constant<t_type>::Invalid };
173 constexpr const static RadialObject<t_dims, t_type, t_vector> Min{ t_vector(0), 0 };
174 constexpr const static RadialObject<t_dims, t_type, t_vector> Max{ t_vector(0), Constant<t_type>::Max};
175 };
176
177 /**--------------------------------------------------------------------------------------------------
178 \brief An ellipse like shape (such as an oval or egg) with two points, where all points on the shape are
179 equal distance between the two points (distanceTo(A) + distanceTo(B) = radius).
180 **/
181 template<uint01 t_dims, class t_type, class t_vertex = Vertex<t_dims, t_type>>
183 {
184 public:
185 constexpr BiRadialObject(t_type r = 0)
186 : m_axis_major(Vector<t_dims, t_type>(0.0))
187 , m_radius(r)
188 {}
189 constexpr BiRadialObject(const t_vertex& p1, const t_vertex& p2, t_type radius)
190 : m_axis_major(p1, p2)
191 , m_radius(radius)
192 {}
193
194
195 template<class t_matrix_type = fltp08>
197 {
200 Ray<3, fltp08> direction = mat * Ray<3, fltp08>(0.5, 0, 0);
201
202 object.m_axis_major[A] = center + direction;
203 object.m_axis_major[B] = center - direction;
204
206
207 object.m_radius = getMin(scale[X], scale[Y]);
208
209 return object;
210 }
211 /**--------------------------------------------------------------------------------------------------
212 Query if this object contains the given vector.
213
214 Author: Tyler Parke
215
216 Date: 2017-11-19
217
218 Parameters:
219 vector - The const Vector&lt;t_dims,t_type&gt;&amp; to test for containment.
220
221 \returns True if the object is in this collection, false if not.
222 **/
223
224 constexpr bool contains(const t_vertex& vector) const
225 {
226 fltp08 total_distance = distance<fltp08>(m_axis_major[A], vector) + distance<fltp08>(m_axis_major[B], vector);
227 return m_radius > total_distance - distance<fltp08>(m_axis_major[A], m_axis_major[B]);
228 }
229
230 /**--------------------------------------------------------------------------------------------------
231 Gets the radius.
232
233 Author: Tyler Parke
234
235 Date: 2017-11-19
236
237 \returns A t_type.
238 **/
239
240 constexpr t_type radius() const { return m_radius; }
241
242
243
244 /**--------------------------------------------------------------------------------------------------
245 Gets as.
246
247 Author: Tyler Parke
248
249 Date: 2017-11-19
250
251 \returns A RadialObject&lt;t_new_dims,t_new_type&gt;
252 **/
253 template<uint01 t_new_dims, class t_new_type>
255 {
256 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));
257 }
258
259 /**--------------------------------------------------------------------------------------------------
260 Gets the center.
261
262 Author: Tyler Parke
263
264 Date: 2017-11-19
265
266 \returns The centerpoint of the Biradial object (Or the intersection of the major and minor axis);
267 **/
268
269 constexpr t_vertex center() const { return t_vertex((m_axis_major[A] + m_axis_major[B]) / cast<t_type>(2)); }
270 constexpr const t_vertex& axisPoint(uint01 vertex) const
271 {
272 return m_axis_major[vertex];
273 }
274
275 template<class t_ratio_type = fltp08>
276 t_ratio_type minorToMajorRatio() const
277 {
278 const t_ratio_type axis_distance = distance<t_ratio_type>(m_axis_major[A], m_axis_major[B]);
279 return cast<t_ratio_type>(m_radius) / (cast<t_ratio_type>(m_radius) + axis_distance / cast<t_ratio_type>(2));
280 }
281 template<class t_matrix_type = fltp08>
283 {
285 if (m_axis_major[B] - m_axis_major[A] == t_vertex(0))
286 return mat;
287 Vector<t_dims, t_type> axis = (m_axis_major[B] - m_axis_major[A]).template normalized<t_matrix_type>();
288 t_matrix_type scale = cast<t_matrix_type>(1) / minorToMajorRatio<t_matrix_type>();
289 mat = mat.scale(axis, scale);
290 return mat;
291 }
292 private:
293 /** The 1. */
294 Vector<2, t_vertex> m_axis_major;
295 /** The radius. */
296 t_type m_radius;
297 };
298};
An ellipse like shape (such as an oval or egg) with two points, where all points on the shape are equ...
Definition RadialObject.hpp:183
t_ratio_type minorToMajorRatio() const
Definition RadialObject.hpp:276
constexpr t_type radius() const
Definition RadialObject.hpp:240
constexpr const t_vertex & axisPoint(uint01 vertex) const
Definition RadialObject.hpp:270
Matrix< t_matrix_type > fromCircleTransform() const
Definition RadialObject.hpp:282
constexpr BiRadialObject< t_new_dims, t_new_type > as() const
Definition RadialObject.hpp:254
static BiRadialObject< t_dims, t_type, t_vertex > fromCircleTransform(const Matrix< t_matrix_type > &mat)
Definition RadialObject.hpp:196
constexpr bool contains(const t_vertex &vector) const
Definition RadialObject.hpp:224
constexpr t_vertex center() const
Definition RadialObject.hpp:269
constexpr BiRadialObject(const t_vertex &p1, const t_vertex &p2, t_type radius)
Definition RadialObject.hpp:189
constexpr BiRadialObject(t_type r=0)
Definition RadialObject.hpp:185
Definition Matrix.hpp:176
constexpr Matrix scale(t_type scale) const
Definition Matrix.hpp:582
constexpr Vector< 3, t_type > decomposeOffset() const
Definition Matrix.hpp:443
static constexpr Matrix< t_type > ScalerMatrix(t_type scale)
Definition Matrix.hpp:307
constexpr Vector< 3, t_type > decomposeScale() const
Definition Matrix.hpp:424
A radial object.
Definition RadialObject.hpp:52
constexpr RadialObject< t_new_dims, t_new_type > as() const
Definition RadialObject.hpp:137
constexpr t_type radius() const
Definition RadialObject.hpp:123
constexpr RadialObject(const t_vertex &center, t_type radius)
Definition RadialObject.hpp:58
constexpr RadialObject(const t_vertex &vertex_a, const t_vertex &vertex_b, const t_vertex &vertex_c)
Definition RadialObject.hpp:73
constexpr RadialObject(t_type r=0)
Definition RadialObject.hpp:54
bool operator!=(const RadialObject &rad) const
Definition RadialObject.hpp:158
bool operator==(const RadialObject &rad) const
Definition RadialObject.hpp:154
constexpr const t_vertex & center() const
Definition RadialObject.hpp:152
constexpr bool contains(const t_vertex &vector) const
Definition RadialObject.hpp:105
Definition Vertex.hpp:317
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
A vertex or point. A specific type of Vector used primarily for spacial location information.
Definition Vertex.hpp:48
Definition ACIColor.h:37
@ vertex_a
Definition Triangle.hpp:52
@ vertex_b
Definition Triangle.hpp:53
@ vertex_c
Definition Triangle.hpp:54
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:46
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
constexpr t_type distance(const t_vertex &vertex, const LineSegment< t_dims, t_type, t_vertex > &line)
Definition Distance.hpp:171
@ B
Definition BaseValues.hpp:170
@ A
Definition BaseValues.hpp:168
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
Definition BaseFunctions.hpp:56
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
static const t_type Invalid
Definition BaseValues.hpp:234
static const t_type Min
Definition BaseValues.hpp:235
static const t_type Max
Definition BaseValues.hpp:236