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