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/SbVec3b.h>
34
35 #include <limits>
36
37 #include <Inventor/SbVec3ub.h>
38 #include <Inventor/SbVec3s.h>
39 #include <Inventor/SbVec3i32.h>
40 #include <Inventor/SbVec3f.h>
41 #include <Inventor/SbVec3d.h>
42
43 /*!
44 \class SbVec3b Inventor/SbVec3b.h
45
46 \since Coin 2.5
47 */
48
49 SbVec3b &
setValue(const SbVec3ub & v)50 SbVec3b::setValue(const SbVec3ub & v)
51 {
52 vec[0] = static_cast<int8_t>(v[0]);
53 vec[1] = static_cast<int8_t>(v[1]);
54 vec[2] = static_cast<int8_t>(v[2]);
55 return *this;
56 }
57
58 SbVec3b &
setValue(const SbVec3s & v)59 SbVec3b::setValue(const SbVec3s & v)
60 {
61 #if COIN_DEBUG
62 if (v[0] > std::numeric_limits<int8_t>::max() || v[0] < -std::numeric_limits<int8_t>::max() ||
63 v[1] > std::numeric_limits<int8_t>::max() || v[1] < -std::numeric_limits<int8_t>::max() ||
64 v[2] > std::numeric_limits<int8_t>::max() || v[2] < -std::numeric_limits<int8_t>::max()) {
65 SoDebugError::post("SbVec3b::setValue", "SbVec3s argument out of range for SbVec3b");
66 }
67 #endif // COIN_DEBUG
68 vec[0] = static_cast<int8_t>(v[0]);
69 vec[1] = static_cast<int8_t>(v[1]);
70 vec[2] = static_cast<int8_t>(v[2]);
71 return *this;
72 }
73
74 SbVec3b &
setValue(const SbVec3i32 & v)75 SbVec3b::setValue(const SbVec3i32 & v)
76 {
77 #if COIN_DEBUG
78 if (v[0] > std::numeric_limits<int8_t>::max() || v[0] < -std::numeric_limits<int8_t>::max() ||
79 v[1] > std::numeric_limits<int8_t>::max() || v[1] < -std::numeric_limits<int8_t>::max() ||
80 v[2] > std::numeric_limits<int8_t>::max() || v[2] < -std::numeric_limits<int8_t>::max()) {
81 SoDebugError::post("SbVec3b::setValue", "SbVec3i32 argument out of range for SbVec3b");
82 }
83 #endif // COIN_DEBUG
84 vec[0] = static_cast<int8_t>(v[0]);
85 vec[1] = static_cast<int8_t>(v[1]);
86 vec[2] = static_cast<int8_t>(v[2]);
87 return *this;
88 }
89
90 SbVec3b &
setValue(const SbVec3f & v)91 SbVec3b::setValue(const SbVec3f & v)
92 {
93 #if COIN_DEBUG
94 if (v[0] > std::numeric_limits<int8_t>::max() || v[0] < -std::numeric_limits<int8_t>::max() ||
95 v[1] > std::numeric_limits<int8_t>::max() || v[1] < -std::numeric_limits<int8_t>::max() ||
96 v[2] > std::numeric_limits<int8_t>::max() || v[2] < -std::numeric_limits<int8_t>::max()) {
97 SoDebugError::post("SbVec3b::setValue", "SbVec3f argument out of range for SbVec3b");
98 }
99 #endif // COIN_DEBUG
100 vec[0] = static_cast<int8_t>(v[0]);
101 vec[1] = static_cast<int8_t>(v[1]);
102 vec[2] = static_cast<int8_t>(v[2]);
103 return *this;
104 }
105
106 SbVec3b &
setValue(const SbVec3d & v)107 SbVec3b::setValue(const SbVec3d & v)
108 {
109 #if COIN_DEBUG
110 if (v[0] > std::numeric_limits<int8_t>::max() || v[0] < -std::numeric_limits<int8_t>::max() ||
111 v[1] > std::numeric_limits<int8_t>::max() || v[1] < -std::numeric_limits<int8_t>::max() ||
112 v[2] > std::numeric_limits<int8_t>::max() || v[2] < -std::numeric_limits<int8_t>::max()) {
113 SoDebugError::post("SbVec3b::setValue", "SbVec3d argument out of range for SbVec3b");
114 }
115 #endif // COIN_DEBUG
116 vec[0] = static_cast<int8_t>(v[0]);
117 vec[1] = static_cast<int8_t>(v[1]);
118 vec[2] = static_cast<int8_t>(v[2]);
119 return *this;
120 }
121
122 SbVec3b &
operator *=(double d)123 SbVec3b::operator *= (double d)
124 {
125 vec[0] = static_cast<int8_t>(vec[0] * d);
126 vec[1] = static_cast<int8_t>(vec[1] * d);
127 vec[2] = static_cast<int8_t>(vec[2] * d);
128 return *this;
129 }
130