Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
SbVec3us.h
1#ifndef COIN_SBVEC3US_H
2#define COIN_SBVEC3US_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <cstdio>
37#include <Inventor/SbBasic.h>
38#include <Inventor/system/inttypes.h>
39#include <Inventor/SbString.h>
40
41#ifndef NDEBUG
42#include <Inventor/errors/SoDebugError.h>
43#endif // !NDEBUG
44
45class SbVec3s;
46class SbVec3ub;
47class SbVec3ui32;
48
49class COIN_DLL_API SbVec3us {
50public:
51 SbVec3us(void) { }
52 SbVec3us(const unsigned short v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; }
53 SbVec3us(unsigned short x, unsigned short y, unsigned short z) { vec[0] = x; vec[1] = y; vec[2] = z; }
54 explicit SbVec3us(const SbVec3s & v) { setValue(v); }
55 explicit SbVec3us(const SbVec3ub & v) { setValue(v); }
56 explicit SbVec3us(const SbVec3ui32 & v) { setValue(v); }
57
58 SbVec3us & setValue(const unsigned short v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
59 SbVec3us & setValue(unsigned short x, unsigned short y, unsigned short z) { vec[0] = x; vec[1] = y; vec[2] = z; return *this; }
60 SbVec3us & setValue(const SbVec3s & v);
61 SbVec3us & setValue(const SbVec3ub & v);
62 SbVec3us & setValue(const SbVec3ui32 & v);
63
64 const unsigned short * getValue(void) const { return vec; }
65 void getValue(unsigned short & x, unsigned short & y, unsigned short & z) const { x = vec[0]; y = vec[1]; z = vec[2]; }
66
67 unsigned short & operator [] (int i) { return vec[i]; }
68 const unsigned short & operator [] (int i) const { return vec[i]; }
69
70 int32_t dot(const SbVec3us & v) const { return vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2]; }
71 void negate(void);
72
73 SbVec3us & operator *= (int d) { vec[0] = (unsigned short)(vec[0] * d); vec[1] = (unsigned short)(vec[1] * d); vec[2] = (unsigned short)(vec[2] * d); return *this; }
74 SbVec3us & operator *= (double d);
75 SbVec3us & operator /= (int d) { SbDividerChk("SbVec3us::operator/=(int)", d); vec[0] = (unsigned short)(vec[0] / d); vec[1] = (unsigned short)(vec[1] / d); vec[2] = (unsigned short)(vec[2] / d); return *this; }
76 SbVec3us & operator /= (double d) { SbDividerChk("SbVec3us::operator/=(double)", d); return operator *= (1.0 / d); }
77 SbVec3us & operator += (const SbVec3us & v) { vec[0] += v[0]; vec[1] += v[1]; vec[2] += v[2]; return *this; }
78 SbVec3us & operator -= (const SbVec3us & v) { vec[0] -= v[0]; vec[1] -= v[1]; vec[2] -= v[2]; return *this; }
79 SbVec3us operator - (void) const { SbVec3us v(*this); v.negate(); return v; }
80
81protected:
82 unsigned short vec[3];
83
84}; // SbVec3us
85
86COIN_DLL_API inline SbVec3us operator * (const SbVec3us & v, int d) {
87 SbVec3us val(v); val *= d; return val;
88}
89
90COIN_DLL_API inline SbVec3us operator * (const SbVec3us & v, double d) {
91 SbVec3us val(v); val *= d; return val;
92}
93
94COIN_DLL_API inline SbVec3us operator * (int d, const SbVec3us & v) {
95 SbVec3us val(v); val *= d; return val;
96}
97
98COIN_DLL_API inline SbVec3us operator * (double d, const SbVec3us & v) {
99 SbVec3us val(v); val *= d; return val;
100}
101
102COIN_DLL_API inline SbVec3us operator / (const SbVec3us & v, int d) {
103 SbDividerChk("operator/(SbVec3us,int)", d);
104 SbVec3us val(v); val /= d; return val;
105}
106
107COIN_DLL_API inline SbVec3us operator / (const SbVec3us & v, double d) {
108 SbDividerChk("operator/(SbVec3us,double)", d);
109 SbVec3us val(v); val /= d; return val;
110}
111
112COIN_DLL_API inline SbVec3us operator + (const SbVec3us & v1, const SbVec3us & v2) {
113 SbVec3us v(v1); v += v2; return v;
114}
115
116COIN_DLL_API inline SbVec3us operator - (const SbVec3us & v1, const SbVec3us & v2) {
117 SbVec3us v(v1); v -= v2; return v;
118}
119
120COIN_DLL_API inline int operator == (const SbVec3us & v1, const SbVec3us & v2) {
121 return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
122}
123
124COIN_DLL_API inline int operator != (const SbVec3us & v1, const SbVec3us & v2) {
125 return !(v1 == v2);
126}
127
128#endif // !COIN_SBVEC3US_H
int operator==(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:102
int operator!=(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:106
SbDPMatrix operator*(const SbDPMatrix &m1, const SbDPMatrix &m2)
Definition: SbDPMatrix.cpp:670
const SbString operator+(const SbString &str1, const SbString &str2)
Definition: SbString.h:187
SbTime operator/(const SbTime &tm, const double s)
Definition: SbTime.cpp:867
SbTime operator-(const SbTime &t0, const SbTime &t1)
Definition: SbTime.cpp:801
The SbVec3s class is a 3 dimensional vector with short integer coordinates.
Definition: SbVec3s.h:50
Definition: SbVec3ub.h:46
Definition: SbVec3ui32.h:46
Definition: SbVec3us.h:49