]> Dogcows Code - chaz/yoink/blob - src/Moof/cml/mathlib/helper.h
constructors should be explicit
[chaz/yoink] / src / Moof / cml / mathlib / helper.h
1 /* -*- C++ -*- ------------------------------------------------------------
2
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
4
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
7
8 *-----------------------------------------------------------------------*/
9 /** @file
10 * @brief
11 */
12
13 #ifndef helper_h
14 #define helper_h
15
16 #include <cstddef>
17 #include <cml/constants.h>
18
19 namespace cml {
20
21 /* Helper classes for axis order, coordinate system handedness, z-clipping
22 * range and spherical coordinate type.
23 */
24
25 //////////////////////////////////////////////////////////////////////////////
26 // Euler order
27 //////////////////////////////////////////////////////////////////////////////
28
29 enum EulerOrder {
30 euler_order_xyz, // 0x00 [0000]
31 euler_order_xyx, // 0x01 [0001]
32 euler_order_xzy, // 0x02 [0010]
33 euler_order_xzx, // 0x03 [0011]
34 euler_order_yzx, // 0x04 [0100]
35 euler_order_yzy, // 0x05 [0101]
36 euler_order_yxz, // 0x06 [0110]
37 euler_order_yxy, // 0x07 [0111]
38 euler_order_zxy, // 0x08 [1000]
39 euler_order_zxz, // 0x09 [1001]
40 euler_order_zyx, // 0x0A [1010]
41 euler_order_zyz // 0x0B [1011]
42 };
43
44 namespace detail {
45
46 inline void unpack_euler_order(
47 EulerOrder order,
48 size_t& i,
49 size_t& j,
50 size_t& k,
51 bool& odd,
52 bool& repeat)
53 {
54 enum { REPEAT = 0x01, ODD = 0x02, AXIS = 0x0C };
55
56 repeat = order & REPEAT;
57 odd = ((order & ODD) == ODD);
58 size_t offset = size_t(odd);
59 i = (order & AXIS) % 3;
60 j = (i + 1 + offset) % 3;
61 k = (i + 2 - offset) % 3;
62 }
63
64 } // namespace detail
65
66 //////////////////////////////////////////////////////////////////////////////
67 // Axis order
68 //////////////////////////////////////////////////////////////////////////////
69
70 enum AxisOrder {
71 axis_order_xyz = euler_order_xyz, // 0x00 [0000]
72 axis_order_xzy = euler_order_xzy, // 0x02 [0010]
73 axis_order_yzx = euler_order_yzx, // 0x04 [0100]
74 axis_order_yxz = euler_order_yxz, // 0x06 [0110]
75 axis_order_zxy = euler_order_zxy, // 0x08 [1000]
76 axis_order_zyx = euler_order_zyx, // 0x0A [1010]
77 };
78
79 namespace detail {
80
81 inline void unpack_axis_order(
82 AxisOrder order,
83 size_t& i,
84 size_t& j,
85 size_t& k,
86 bool& odd)
87 {
88 enum { ODD = 0x02, AXIS = 0x0C };
89
90 odd = ((order & ODD) == ODD);
91 size_t offset = size_t(odd);
92 i = (order & AXIS) % 3;
93 j = (i + 1 + offset) % 3;
94 k = (i + 2 - offset) % 3;
95 }
96
97 inline AxisOrder pack_axis_order(size_t i, bool odd) {
98 return AxisOrder((i << 2) | (size_t(odd) << 1));
99 }
100
101 inline AxisOrder swap_axis_order(AxisOrder order)
102 {
103 size_t i, j, k;
104 bool odd;
105 unpack_axis_order(order, i, j, k, odd);
106 return pack_axis_order(j, !odd);
107 }
108
109 } // namespace detail
110
111 //////////////////////////////////////////////////////////////////////////////
112 // Axis order 2D
113 //////////////////////////////////////////////////////////////////////////////
114
115 enum AxisOrder2D {
116 axis_order_xy = axis_order_xyz, // 0x00 [0000]
117 axis_order_yx = axis_order_yxz, // 0x06 [0110]
118 };
119
120 namespace detail {
121
122 inline void unpack_axis_order_2D(
123 AxisOrder2D order,
124 size_t& i,
125 size_t& j,
126 bool& odd)
127 {
128 enum { ODD = 0x02, AXIS = 0x0C };
129
130 odd = ((order & ODD) == ODD);
131 size_t offset = size_t(odd);
132 i = (order & AXIS) % 3;
133 j = (i + 1 + offset) % 3;
134 }
135
136 } // namespace detail
137
138 //////////////////////////////////////////////////////////////////////////////
139 // Handedness
140 //////////////////////////////////////////////////////////////////////////////
141
142 enum Handedness { left_handed, right_handed };
143
144 //////////////////////////////////////////////////////////////////////////////
145 // Z clip
146 //////////////////////////////////////////////////////////////////////////////
147
148 enum ZClip { z_clip_neg_one, z_clip_zero };
149
150 //////////////////////////////////////////////////////////////////////////////
151 // Spherical coordinate type
152 //////////////////////////////////////////////////////////////////////////////
153
154 enum SphericalType { latitude, colatitude };
155
156 } // namespace cml
157
158 #endif
This page took 0.043527 seconds and 4 git commands to generate.