1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
11
// * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
// * Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
17
// * Neither the name of Industrial Light & Magic nor the names of
18
// its contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission.
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
///////////////////////////////////////////////////////////////////////////
37
//----------------------------------------------------------------------------
39
// Specializations of the Vec2<T> and Vec3<T> templates.
41
//----------------------------------------------------------------------------
45
#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
46
// suppress exception specification warnings
47
#pragma warning(disable:4290)
58
normalizeOrThrow(Vec2<T> &v)
61
for (int i = 0; i < 2; i ++)
67
throw IntVecNormalizeExc ("Cannot normalize an integer "
68
"vector unless it is parallel "
69
"to a principal axis");
74
v[axis] = (v[axis] > 0) ? 1 : -1;
81
normalizeOrThrow(Vec3<T> &v)
84
for (int i = 0; i < 3; i ++)
90
throw IntVecNormalizeExc ("Cannot normalize an integer "
91
"vector unless it is parallel "
92
"to a principal axis");
97
v[axis] = (v[axis] > 0) ? 1 : -1;
108
Vec2<short>::length () const
110
float lenF = Math<float>::sqrt (dot (*this));
111
short lenS = (short) (lenF + 0.5f);
117
Vec2<short>::normalize ()
119
normalizeOrThrow<short>(*this);
125
Vec2<short>::normalizeExc () throw (Iex::MathExc)
127
if ((x == 0) && (y == 0))
128
throw NullVecExc ("Cannot normalize null vector.");
130
normalizeOrThrow<short>(*this);
136
Vec2<short>::normalizeNonNull ()
138
normalizeOrThrow<short>(*this);
144
Vec2<short>::normalized () const
146
Vec2<short> v(*this);
147
normalizeOrThrow<short>(v);
153
Vec2<short>::normalizedExc () const throw (Iex::MathExc)
155
if ((x == 0) && (y == 0))
156
throw NullVecExc ("Cannot normalize null vector.");
158
Vec2<short> v(*this);
159
normalizeOrThrow<short>(v);
165
Vec2<short>::normalizedNonNull () const
167
Vec2<short> v(*this);
168
normalizeOrThrow<short>(v);
177
Vec2<int>::length () const
179
float lenF = Math<float>::sqrt (dot (*this));
180
int lenI = (int) (lenF + 0.5f);
186
Vec2<int>::normalize ()
188
normalizeOrThrow<int>(*this);
194
Vec2<int>::normalizeExc () throw (Iex::MathExc)
196
if ((x == 0) && (y == 0))
197
throw NullVecExc ("Cannot normalize null vector.");
199
normalizeOrThrow<int>(*this);
205
Vec2<int>::normalizeNonNull ()
207
normalizeOrThrow<int>(*this);
213
Vec2<int>::normalized () const
216
normalizeOrThrow<int>(v);
222
Vec2<int>::normalizedExc () const throw (Iex::MathExc)
224
if ((x == 0) && (y == 0))
225
throw NullVecExc ("Cannot normalize null vector.");
228
normalizeOrThrow<int>(v);
234
Vec2<int>::normalizedNonNull () const
237
normalizeOrThrow<int>(v);
246
Vec3<short>::length () const
248
float lenF = Math<float>::sqrt (dot (*this));
249
short lenS = (short) (lenF + 0.5f);
255
Vec3<short>::normalize ()
257
normalizeOrThrow<short>(*this);
263
Vec3<short>::normalizeExc () throw (Iex::MathExc)
265
if ((x == 0) && (y == 0) && (z == 0))
266
throw NullVecExc ("Cannot normalize null vector.");
268
normalizeOrThrow<short>(*this);
274
Vec3<short>::normalizeNonNull ()
276
normalizeOrThrow<short>(*this);
282
Vec3<short>::normalized () const
284
Vec3<short> v(*this);
285
normalizeOrThrow<short>(v);
291
Vec3<short>::normalizedExc () const throw (Iex::MathExc)
293
if ((x == 0) && (y == 0) && (z == 0))
294
throw NullVecExc ("Cannot normalize null vector.");
296
Vec3<short> v(*this);
297
normalizeOrThrow<short>(v);
303
Vec3<short>::normalizedNonNull () const
305
Vec3<short> v(*this);
306
normalizeOrThrow<short>(v);
315
Vec3<int>::length () const
317
float lenF = Math<float>::sqrt (dot (*this));
318
int lenI = (int) (lenF + 0.5f);
324
Vec3<int>::normalize ()
326
normalizeOrThrow<int>(*this);
332
Vec3<int>::normalizeExc () throw (Iex::MathExc)
334
if ((x == 0) && (y == 0) && (z == 0))
335
throw NullVecExc ("Cannot normalize null vector.");
337
normalizeOrThrow<int>(*this);
343
Vec3<int>::normalizeNonNull ()
345
normalizeOrThrow<int>(*this);
351
Vec3<int>::normalized () const
354
normalizeOrThrow<int>(v);
360
Vec3<int>::normalizedExc () const throw (Iex::MathExc)
362
if ((x == 0) && (y == 0) && (z == 0))
363
throw NullVecExc ("Cannot normalize null vector.");
366
normalizeOrThrow<int>(v);
372
Vec3<int>::normalizedNonNull () const
375
normalizeOrThrow<int>(v);
1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
11
// * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
// * Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
17
// * Neither the name of Industrial Light & Magic nor the names of
18
// its contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission.
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
///////////////////////////////////////////////////////////////////////////
37
//----------------------------------------------------------------------------
39
// Specializations of the Vec2<T> and Vec3<T> templates.
41
//----------------------------------------------------------------------------
45
#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
46
// suppress exception specification warnings
47
#pragma warning(disable:4290)
58
normalizeOrThrow(Vec2<T> &v)
61
for (int i = 0; i < 2; i ++)
67
throw IntVecNormalizeExc ("Cannot normalize an integer "
68
"vector unless it is parallel "
69
"to a principal axis");
74
v[axis] = (v[axis] > 0) ? 1 : -1;
81
normalizeOrThrow(Vec3<T> &v)
84
for (int i = 0; i < 3; i ++)
90
throw IntVecNormalizeExc ("Cannot normalize an integer "
91
"vector unless it is parallel "
92
"to a principal axis");
97
v[axis] = (v[axis] > 0) ? 1 : -1;
108
Vec2<short>::length () const
110
float lenF = Math<float>::sqrt (dot (*this));
111
short lenS = (short) (lenF + 0.5f);
117
Vec2<short>::normalize ()
119
normalizeOrThrow<short>(*this);
125
Vec2<short>::normalizeExc () throw (Iex::MathExc)
127
if ((x == 0) && (y == 0))
128
throw NullVecExc ("Cannot normalize null vector.");
130
normalizeOrThrow<short>(*this);
136
Vec2<short>::normalizeNonNull ()
138
normalizeOrThrow<short>(*this);
144
Vec2<short>::normalized () const
146
Vec2<short> v(*this);
147
normalizeOrThrow<short>(v);
153
Vec2<short>::normalizedExc () const throw (Iex::MathExc)
155
if ((x == 0) && (y == 0))
156
throw NullVecExc ("Cannot normalize null vector.");
158
Vec2<short> v(*this);
159
normalizeOrThrow<short>(v);
165
Vec2<short>::normalizedNonNull () const
167
Vec2<short> v(*this);
168
normalizeOrThrow<short>(v);
177
Vec2<int>::length () const
179
float lenF = Math<float>::sqrt (dot (*this));
180
int lenI = (int) (lenF + 0.5f);
186
Vec2<int>::normalize ()
188
normalizeOrThrow<int>(*this);
194
Vec2<int>::normalizeExc () throw (Iex::MathExc)
196
if ((x == 0) && (y == 0))
197
throw NullVecExc ("Cannot normalize null vector.");
199
normalizeOrThrow<int>(*this);
205
Vec2<int>::normalizeNonNull ()
207
normalizeOrThrow<int>(*this);
213
Vec2<int>::normalized () const
216
normalizeOrThrow<int>(v);
222
Vec2<int>::normalizedExc () const throw (Iex::MathExc)
224
if ((x == 0) && (y == 0))
225
throw NullVecExc ("Cannot normalize null vector.");
228
normalizeOrThrow<int>(v);
234
Vec2<int>::normalizedNonNull () const
237
normalizeOrThrow<int>(v);
246
Vec3<short>::length () const
248
float lenF = Math<float>::sqrt (dot (*this));
249
short lenS = (short) (lenF + 0.5f);
255
Vec3<short>::normalize ()
257
normalizeOrThrow<short>(*this);
263
Vec3<short>::normalizeExc () throw (Iex::MathExc)
265
if ((x == 0) && (y == 0) && (z == 0))
266
throw NullVecExc ("Cannot normalize null vector.");
268
normalizeOrThrow<short>(*this);
274
Vec3<short>::normalizeNonNull ()
276
normalizeOrThrow<short>(*this);
282
Vec3<short>::normalized () const
284
Vec3<short> v(*this);
285
normalizeOrThrow<short>(v);
291
Vec3<short>::normalizedExc () const throw (Iex::MathExc)
293
if ((x == 0) && (y == 0) && (z == 0))
294
throw NullVecExc ("Cannot normalize null vector.");
296
Vec3<short> v(*this);
297
normalizeOrThrow<short>(v);
303
Vec3<short>::normalizedNonNull () const
305
Vec3<short> v(*this);
306
normalizeOrThrow<short>(v);
315
Vec3<int>::length () const
317
float lenF = Math<float>::sqrt (dot (*this));
318
int lenI = (int) (lenF + 0.5f);
324
Vec3<int>::normalize ()
326
normalizeOrThrow<int>(*this);
332
Vec3<int>::normalizeExc () throw (Iex::MathExc)
334
if ((x == 0) && (y == 0) && (z == 0))
335
throw NullVecExc ("Cannot normalize null vector.");
337
normalizeOrThrow<int>(*this);
343
Vec3<int>::normalizeNonNull ()
345
normalizeOrThrow<int>(*this);
351
Vec3<int>::normalized () const
354
normalizeOrThrow<int>(v);
360
Vec3<int>::normalizedExc () const throw (Iex::MathExc)
362
if ((x == 0) && (y == 0) && (z == 0))
363
throw NullVecExc ("Cannot normalize null vector.");
366
normalizeOrThrow<int>(v);
372
Vec3<int>::normalizedNonNull () const
375
normalizeOrThrow<int>(v);