1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 #include <Inventor/SbVec3i32.h>
34
35 #include <limits>
36
37 #include <Inventor/SbVec3ui32.h>
38 #include <Inventor/SbVec3b.h>
39 #include <Inventor/SbVec3s.h>
40 #include <Inventor/SbVec3f.h>
41 #include <Inventor/SbVec3d.h>
42 #if COIN_DEBUG
43 #include <Inventor/errors/SoDebugError.h>
44 #endif // COIN_DEBUG
45
46 /*!
47 \class SbVec3i32 Inventor/SbVec3i32.h
48
49 \since Coin 2.5
50 */
51
52 SbVec3i32 &
setValue(const SbVec3ui32 & v)53 SbVec3i32::setValue(const SbVec3ui32 & v)
54 {
55 vec[0] = static_cast<int32_t>(v[0]);
56 vec[1] = static_cast<int32_t>(v[1]);
57 vec[2] = static_cast<int32_t>(v[2]);
58 return *this;
59 }
60
61 SbVec3i32 &
setValue(const SbVec3b & v)62 SbVec3i32::setValue(const SbVec3b & v)
63 {
64 vec[0] = static_cast<int32_t>(v[0]);
65 vec[1] = static_cast<int32_t>(v[1]);
66 vec[2] = static_cast<int32_t>(v[2]);
67 return *this;
68 }
69
70 SbVec3i32 &
setValue(const SbVec3s & v)71 SbVec3i32::setValue(const SbVec3s & v)
72 {
73 vec[0] = static_cast<int32_t>(v[0]);
74 vec[1] = static_cast<int32_t>(v[1]);
75 vec[2] = static_cast<int32_t>(v[2]);
76 return *this;
77 }
78
79 SbVec3i32 &
setValue(const SbVec3f & v)80 SbVec3i32::setValue(const SbVec3f & v)
81 {
82 #if COIN_DEBUG
83 if (v[0] > std::numeric_limits<int32_t>::max() || v[0] < -std::numeric_limits<int32_t>::max() ||
84 v[1] > std::numeric_limits<int32_t>::max() || v[1] < -std::numeric_limits<int32_t>::max() ||
85 v[2] > std::numeric_limits<int32_t>::max() || v[2] < -std::numeric_limits<int32_t>::max()) {
86 SoDebugError::post("SbVec3i32::setValue", "SbVec3f argument out of range for SbVec3i32");
87 }
88 #endif // COIN_DEBUG
89 vec[0] = static_cast<int32_t>(v[0]);
90 vec[1] = static_cast<int32_t>(v[1]);
91 vec[2] = static_cast<int32_t>(v[2]);
92 return *this;
93 }
94
95 SbVec3i32 &
setValue(const SbVec3d & v)96 SbVec3i32::setValue(const SbVec3d & v)
97 {
98 #if COIN_DEBUG
99 if (v[0] > std::numeric_limits<int32_t>::max() || v[0] < -std::numeric_limits<int32_t>::max() ||
100 v[1] > std::numeric_limits<int32_t>::max() || v[1] < -std::numeric_limits<int32_t>::max() ||
101 v[2] > std::numeric_limits<int32_t>::max() || v[2] < -std::numeric_limits<int32_t>::max()) {
102 SoDebugError::post("SbVec3i32::setValue", "SbVec3d argument out of range for SbVec3i32");
103 }
104 #endif // COIN_DEBUG
105 vec[0] = static_cast<int32_t>(v[0]);
106 vec[1] = static_cast<int32_t>(v[1]);
107 vec[2] = static_cast<int32_t>(v[2]);
108 return *this;
109 }
110
111 SbVec3i32 &
operator *=(double d)112 SbVec3i32::operator *= (double d)
113 {
114 vec[0] = static_cast<int32_t>(vec[0] * d);
115 vec[1] = static_cast<int32_t>(vec[1] * d);
116 vec[2] = static_cast<int32_t>(vec[2] * d);
117 return *this;
118 }
119