API Documentation
Loading...
Searching...
No Matches
BaseValues.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: BaseValues
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/LibAssert.h>
34#include <limits>
35#include <cinttypes>
36/**--------------------------------------------------------------------------------------------------
37Namespace: Parke
38Namespace that wraps all Logic created by Tyler Parke
39 *-----------------------------------------------------------------------------------------------**/
40
41namespace NDEVR
42{
43 /**--------------------------------------------------------------------------------------------------
44 Class: BaseValues
45 \brief Dummy class to ensure creation of an include file around core root values
46 *-----------------------------------------------------------------------------------------------**/
48 {};
49 /**--------------------------------------------------------------------------------------------------
50 Typedef: int8_t sint01
51
52 \brief -Defines an alias representing a 1 byte, signed integer.
53 -Can represent exact integer values -127 through 127.
54 -Byte value 0XFF (integer value: -128) is considered invalid and reserved.
55 *-----------------------------------------------------------------------------------------------**/
56 typedef int8_t sint01;
57
58 /**--------------------------------------------------------------------------------------------------
59 Typedef: int16_t sint02
60
61 \brief -Defines an alias representing a 2 byte, signed integer.
62 -Can represent exact integer values -32767 through 32767.
63 -Byte value 0XFFFF (integer value: -32768) is considered invalid and reserved.
64 *-----------------------------------------------------------------------------------------------**/
65
66 typedef int16_t sint02;
67
68 /**--------------------------------------------------------------------------------------------------
69 Typedef: int32_t sint04
70
71 \brief -Defines an alias representing a 4 byte, signed integer.
72 -Can represent exact integer values -2147483647 through 2147483647.
73 -Byte value 0XFFFFFFFF (integer value: -2147483648) is considered invalid and reserved.
74 *-----------------------------------------------------------------------------------------------**/
75
76 typedef int32_t sint04;
77
78 /**--------------------------------------------------------------------------------------------------
79 Typedef: int64_t sint08
80
81 \brief -Defines an alias representing an 8 byte, signed integer
82 -Can represent exact integer values -9223372036854775807 through 9223372036854775807.
83 -Byte value 0XFFFFFFFFFFFFFFFF (integer value: -9223372036854775808) is considered invalid and reserved.
84 *-----------------------------------------------------------------------------------------------**/
85
86 typedef int64_t sint08;
87
88 /**--------------------------------------------------------------------------------------------------
89 Typedef: uint8_t uint01
90
91 \brief -Defines an alias representing a 1 byte, unsigned integer
92 -Can represent exact integer values 0 through 254.
93 -Byte value 0XFF (integer value: 255) is considered invalid and should normally be reserved. Note that
94 it can be used with caution.
95 -Note that subtracting 1 from 0 will result in 0xFF, the reserved invalid value.
96 *-----------------------------------------------------------------------------------------------**/
97
98 typedef uint8_t uint01;
99
100 /**--------------------------------------------------------------------------------------------------
101 Typedef: uint16_t uint02
102
103 \brief -Defines an alias representing a 2 byte, unsigned integer
104 -Can represent exact integer values 0 through 65534.
105 -Byte value 0xFFFF (integer value: 65535) is considered invalid and reserved.
106 -Note that subtracting 1 from 0 will result in 0xFFFF, the reserved invalid value.
107 *-----------------------------------------------------------------------------------------------**/
108
109 typedef uint16_t uint02;
110
111 /**--------------------------------------------------------------------------------------------------
112 Typedef: uint32_t uint04
113
114 \brief -Defines an alias representing a 4 byte, unsigned integer
115 -Can represent exact integer values 0 through 4294967294.
116 -Byte value 0xFFFFFFFF (integer value: 4294967295) is considered invalid and reserved.
117 -Note that subtracting 1 from 0 will result in 0xFFFFFFFF, the reserved invalid value.
118 *-----------------------------------------------------------------------------------------------**/
119
120 typedef uint32_t uint04;
121
122 /**--------------------------------------------------------------------------------------------------
123 Typedef: uint64_t uint08
124
125 \brief -Defines an alias representing an 8 byte, unsigned integer
126 -Can represent exact integer values 0 through 18446744073709551614.
127 -Byte value 0XFFFFFFFFFFFFFFFF (integer value: 18446744073709551615) is considered invalid and
128 reserved.
129 -Note that subtracting 1 from 0 will result in 0XFFFFFFFFFFFFFFFF, the reserved invalid value.
130 *-----------------------------------------------------------------------------------------------**/
131
132 typedef uint64_t uint08;
133
134
135 /**--------------------------------------------------------------------------------------------------
136 Typedef: float fltp04
137
138 \brief Defines an alias representing a 4 byte floating-point number
139
140 -Bit layout is as follows:
141 -Sign: 1 bit at position 31 determines whether or not the value is positive or negative.
142 0 denotes a positive number, and 1 denotes a negative number
143 -Exponent: 8 bits stored in position 30–23 The exponent field needs to represent both positive
144 and negative exponents. To do this, a bias is added to the actual exponent in order to get
145 the stored exponent. This value is 127.
146 Thus, an exponent of zero means that 127 is stored in the exponent field.
147 A stored value of 200 indicates an exponent of (200–127), or 73. For reasons
148 exponents of −127 (all 0s) and +128 (all 1s) are reserved for special numbers.
149 -Fraction: 23 bits stored in positions 22–00. The mantissa, also known as the significand,
150 represents the precision bits of the number. It is composed of an implicit leading bit
151 (left of the radix point) and the fraction bits (to the right of the radix point).
152 -Note that positive and negative infinity are reserved as max and min. However precision changes
153 for large and small numbers. Precision is greatest around 0.
154 - Note that NaN is reserved as invalid values. Using == will not work for these values.
155 *-----------------------------------------------------------------------------------------------**/
156
157 typedef float fltp04;
158
159 /**--------------------------------------------------------------------------------------------------
160 Typedef: double fltp08
161
162 \brief Defines an alias representing an 8 byte floating-point number
163
164 -Bit layout is as follows:
165 -Sign: 1 bit at position 63 determines whether or not the value is positive or negative.
166 0 denotes a positive number, and 1 denotes a negative number
167 -Exponent: 11 bits stored in position 62–52. The exponent field needs to represent both positive
168 and negative exponents. To do this, a bias is added to the actual exponent in order to get
169 the stored exponent. This value is 1023.
170 Thus, an exponent of zero means that 1023 is stored in the exponent field.
171 A stored value of 200 indicates an exponent of (200–1023), or -823. For reasons
172 exponents of all 0s and all 1s are reserved for special numbers.
173 -Fraction: 52 bits stored in positions 51–00. The mantissa, also known as the significand,
174 represents the precision bits of the number. It is composed of an implicit leading bit
175 (left of the radix point) and the fraction bits (to the right of the radix point).
176 -Note that positive and negative infinity are reserved as max and min. However precision changes
177 for large and small numbers. Precision is greatest around 0.
178 - Note that NaN is reserved as invalid values. Using == will not work for these values.
179 *-----------------------------------------------------------------------------------------------**/
180
181 typedef double fltp08;
182
183
184 typedef wchar_t wchar;
185
186
187 /**--------------------------------------------------------------------------------------------------
188 Enum: DimensionValues
189
190 \brief Values that represent dimension values.
191
192 -Note these are used throughout the code to make things more readable. For example, for a vertex
193 we can access it via vertex[Z] instead of vertex[2] which overall contributes to total readability.
194 Typically for shapes (Triangles, LineSegments, etc) we access the nodes via A, B, C. triangle.vertex(A)
195 for example. For points we typically use X, Y, Z triangle.vertex(A)[X] = triangle.vertex(B)[X]
196 *-----------------------------------------------------------------------------------------------**/
197
199 {
200 X = 0
201 , A = 0
202 , Y = 1
203 , B = 1
204 , Z = 2
205 , C = 2
206 , W = 3
207 , D = 3
208 };
209
211 {
212 LAT = 0,
213 LON = 1,
214 ALT = 2
215 };
216 /**--------------------------------------------------------------------------------------------------
217 Enum: LocationValues
218
219 \brief Values that represent location values.
220 -Note these are used throughout the code to make things more readable as above. For example, for example
221 in point pairs with a max and a min, or in a bounds object.
222 *-----------------------------------------------------------------------------------------------**/
223
225 {
226 MIN = 0
227 , MAX = 1
228 };
229
230 /**--------------------------------------------------------------------------------------------------
231 Enum: AreaValues
232
233 \brief Used for classifying shape intersections.
234 - Outside means completely outside the other shape.
235 - Inside means entirely inside (or touching the boundary) of the shape.
236 - Mixed means the shape is neither completely inside or outside the shape. This is used heavily
237 in the intersection class.
238 *-----------------------------------------------------------------------------------------------**/
239
246
247 /**--------------------------------------------------------------------------------------------------
248 Enum: InterpolationValues
249
250 \brief Values that represent interpolation functions. Useful in large or complicated geological or time
251 based data sets.
252 *-----------------------------------------------------------------------------------------------**/
253
260
261 /**--------------------------------------------------------------------------------------------------
262 Struct: Constant
263
264 A constant.
265
266 Author: Tyler Parke
267
268 Date: 2017-11-05
269 *-----------------------------------------------------------------------------------------------**/
270 template<class t_type>
271 struct Constant
272 {
273 /** The NaN. */
274 static const t_type NaN;
275 /** The minimum. */
276 static const t_type Min;
277 /** The maximum. */
278 static const t_type Max;
279 };
280
281 /** . */
282 template<> constexpr const bool Constant<bool>::NaN = false;
283 /** . */
284 template<> constexpr const bool Constant<bool>::Max = true;
285 /** . */
286 template<> constexpr const bool Constant<bool>::Min = false;
287
288 /** . */
289 template<> constexpr const sint01 Constant<sint01>::NaN = -128;
290 /** . */
291 template<> constexpr const sint01 Constant<sint01>::Max = 127;
292 /** . */
293 template<> constexpr const sint01 Constant<sint01>::Min = -127;
294
295 /** . */
296 template<> constexpr const uint01 Constant<uint01>::NaN = 255;
297 /** . */
298 template<> constexpr const uint01 Constant<uint01>::Max = 254;
299 /** . */
300 template<> constexpr const uint01 Constant<uint01>::Min = 0;
301
302 /** . */
303 template<> constexpr const sint02 Constant<sint02>::NaN = -32768;
304 /** . */
305 template<> constexpr const sint02 Constant<sint02>::Max = 32767;
306 /** . */
307 template<> constexpr const sint02 Constant<sint02>::Min = -32767;
308
309 /** . */
310 template<> constexpr const uint02 Constant<uint02>::NaN = 65535;
311 /** . */
312 template<> constexpr const uint02 Constant<uint02>::Max = 65534;
313 /** . */
314 template<> constexpr const uint02 Constant<uint02>::Min = 0;
315
316
317 /** . */
318 template<> constexpr const sint04 Constant<sint04>::NaN = 0x80000000;
319 /** . */
320 template<> constexpr const sint04 Constant<sint04>::Max = 2147483647;
321 /** . */
322 template<> constexpr const sint04 Constant<sint04>::Min = -2147483647;
323
324
325 /** . */
326 template<> constexpr const uint04 Constant<uint04>::NaN = 4294967295UL;
327 /** . */
328 template<> constexpr const uint04 Constant<uint04>::Max = 4294967294UL;
329 /** . */
330 template<> constexpr const uint04 Constant<uint04>::Min = 0;
331
332
333 /** . */
334 template<> constexpr const sint08 Constant<sint08>::NaN = 0x8000000000000000;
335 /** . */
336 template<> constexpr const sint08 Constant<sint08>::Max = 9223372036854775807LL;
337 /** . */
338 template<> constexpr const sint08 Constant<sint08>::Min = -9223372036854775807LL;
339
340 /** . */
341 template<> constexpr const uint08 Constant<uint08>::NaN = 18446744073709551615ULL;
342 /** . */
343 template<> constexpr const uint08 Constant<uint08>::Max = 18446744073709551614ULL;
344 /** . */
345 template<> constexpr const uint08 Constant<uint08>::Min = 0;
346
347 /** . */
348 template<> constexpr const fltp04 Constant<fltp04>::NaN = std::numeric_limits<fltp04>::quiet_NaN();
349 /** . */
350 template<> constexpr const fltp04 Constant<fltp04>::Max = std::numeric_limits<fltp04>::infinity();
351 /** . */
352 template<> constexpr const fltp04 Constant<fltp04>::Min = -std::numeric_limits<fltp04>::infinity();
353 /** . */
354 template<> constexpr const fltp08 Constant<fltp08>::NaN = std::numeric_limits<fltp08>::quiet_NaN();
355 /** . */
356 template<> constexpr const fltp08 Constant<fltp08>::Max = std::numeric_limits<fltp08>::infinity();
357 /** . */
358 template<> constexpr const fltp08 Constant<fltp08>::Min = -std::numeric_limits<fltp08>::infinity();
359
360 /**--------------------------------------------------------------------------------------------------
361 Fn: constexpr t_to cast(t_from value)
362
363 Casts the given value. Is equivalent to static_cast except allows for the option of special cases by
364 specializing the template
365 static_cast is used for cases where you basically want to reverse an implicit conversion,
366 with a few restrictions and additions. static_cast performs no runtime checks.
367 This should be used if you know that you refer to an object of a specific type,
368 and thus a check would be unnecessary.
369
370 Author: Tyler Parke
371
372 Date: 2017-09-04
373
374 Param:
375 value - The value to cast.
376
377 Returns: The value cast to the specified type.
378 *-----------------------------------------------------------------------------------------------**/
379
380 template<class t_to, class t_from>
381 constexpr t_to cast(t_from value)
382 {
383 return static_cast<t_to>(value);
384 }
385 template<>
386 constexpr uint04 cast(fltp04 value)
387 {
388 lib_assert(value >= 0, "Bad value");
389 return static_cast<uint04>(value);
390 }
391 template<>
392 constexpr uint04 cast(fltp08 value)
393 {
394 lib_assert(value >= 0, "Bad value");
395 return static_cast<uint04>(value);
396 }
397 template<>
398 constexpr uint04 cast(sint04 value)
399 {
400 lib_assert(value >= 0, "Bad value");
401 return static_cast<uint04>(value);
402 }
403 template<>
404 constexpr uint04 cast(sint08 value)
405 {
406 lib_assert(value >= 0, "Bad value");
407 return static_cast<uint04>(value);
408 }
409 /**--------------------------------------------------------------------------------------------------
410 Fn: constexpr t_to rcast(t_from value)
411
412 Casts the given value. Is equivalent to reinterpret_cast except allows for the option of special cases by
413 specializing the template
414 Allows any pointer to be converted into any other pointer type. Also allows any integral type to be
415 converted into any pointer type and vice versa.
416
417 Author: Tyler Parke
418
419 Date: 2017-09-04
420
421 Param:
422 value - The value to cast.
423
424 Returns: The value cast to the specified type.
425 *-----------------------------------------------------------------------------------------------**/
426 template<class t_to, class t_from>
427 constexpr t_to rcast(t_from value)
428 {
429 static_assert(sizeof(t_to) <= sizeof(t_from), "Bad rcast conversion");
430 return *((t_to*)(&value));
431 }
432
433 #define UNUSED(expr) do { (void)(expr); } while (0)
434
435
436 static_assert(sizeof(bool) == 1, "Bad bool size");
437 static_assert(sizeof(char) == 1, "Bad char size");
438 //static_assert(sizeof(wchar) == 4, "Bad bool size");
439 static_assert(sizeof(float) == 4, "Bad float size");
440 static_assert(sizeof(double) == 8, "Bad double size");
441
442 static_assert(sizeof(fltp04) == 4, "Bad fltp04 size");
443 static_assert(sizeof(fltp08) == 8, "Bad fltp08 size");
444
445 static_assert(sizeof(uint01) == 1, "Bad int size");
446 static_assert(sizeof(uint02) == 2, "Bad int size");
447 static_assert(sizeof(uint04) == 4, "Bad int size");
448 static_assert(sizeof(uint08) == 8, "Bad int size");
449
450 static_assert(sizeof(sint01) == 1, "Bad int size");
451 static_assert(sizeof(sint02) == 2, "Bad int size");
452 static_assert(sizeof(sint04) == 4, "Bad int size");
453 static_assert(sizeof(sint08) == 8, "Bad int size");
454};
455
456#include "BaseFunctions.hpp"
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
Dummy class to ensure creation of an include file around core root values.
Definition BaseValues.hpp:48
Definition ACIColor.h:37
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:76
GeodeticValues
Definition BaseValues.hpp:211
@ LAT
Definition BaseValues.hpp:212
@ LON
Definition BaseValues.hpp:213
@ ALT
Definition BaseValues.hpp:214
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:86
LocationValues
Values that represent location values. -Note these are used throughout the code to make things more r...
Definition BaseValues.hpp:225
@ MIN
Definition BaseValues.hpp:226
@ MAX
Definition BaseValues.hpp:227
wchar_t wchar
Definition BaseValues.hpp:184
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
InterpolationValues
Values that represent interpolation functions. Useful in large or complicated geological or time.
Definition BaseValues.hpp:255
@ nearest_neighbor
Definition BaseValues.hpp:256
@ bicubic
Definition BaseValues.hpp:258
@ e_linear
Definition BaseValues.hpp:257
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
int8_t sint01
-Defines an alias representing a 1 byte, signed integer. -Can represent exact integer values -127 thr...
Definition BaseValues.hpp:56
constexpr t_to rcast(t_from value)
Definition BaseValues.hpp:427
IntersectionTypes
Used for classifying shape intersections.
Definition BaseValues.hpp:241
@ inside
Definition BaseValues.hpp:243
@ mixed
Definition BaseValues.hpp:244
@ outside
Definition BaseValues.hpp:242
int16_t sint02
-Defines an alias representing a 2 byte, signed integer. -Can represent exact integer values -32767 t...
Definition BaseValues.hpp:66
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer -Can represent exact integer values 0 thro...
Definition BaseValues.hpp:132
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:109
DimensionValues
Values that represent dimension values.
Definition BaseValues.hpp:199
@ B
Definition BaseValues.hpp:203
@ A
Definition BaseValues.hpp:201
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
@ C
Definition BaseValues.hpp:205
@ D
Definition BaseValues.hpp:207
@ Z
Definition BaseValues.hpp:204
@ W
Definition BaseValues.hpp:206
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
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