1 #ifndef COIN_SBVEC2I32_H
2 #define COIN_SBVEC2I32_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 
38 #include <Inventor/SbBasic.h>
39 #include <Inventor/system/inttypes.h>
40 #ifndef NDEBUG
41 #include <Inventor/errors/SoDebugError.h>
42 #endif // !NDEBUG
43 
44 class SbVec2ui32;
45 class SbVec2b;
46 class SbVec2s;
47 class SbVec2f;
48 class SbVec2d;
49 
50 class COIN_DLL_API SbVec2i32 {
51 public:
SbVec2i32(void)52   SbVec2i32(void) { }
SbVec2i32(const int32_t v[2])53   SbVec2i32(const int32_t v[2]) { vec[0] = v[0]; vec[1] = v[1]; }
SbVec2i32(int32_t x,int32_t y)54   SbVec2i32(int32_t x, int32_t y) { vec[0] = x; vec[1] = y; }
SbVec2i32(const SbVec2ui32 & v)55   explicit SbVec2i32(const SbVec2ui32 & v) { setValue(v); }
SbVec2i32(const SbVec2b & v)56   explicit SbVec2i32(const SbVec2b & v) { setValue(v); }
SbVec2i32(const SbVec2s & v)57   explicit SbVec2i32(const SbVec2s & v) { setValue(v); }
SbVec2i32(const SbVec2f & v)58   explicit SbVec2i32(const SbVec2f & v) { setValue(v); }
SbVec2i32(const SbVec2d & v)59   explicit SbVec2i32(const SbVec2d & v) { setValue(v); }
60 
setValue(const int32_t v[2])61   SbVec2i32 & setValue(const int32_t v[2]) { vec[0] = v[0]; vec[1] = v[1]; return *this; }
setValue(int32_t x,int32_t y)62   SbVec2i32 & setValue(int32_t x, int32_t y) { vec[0] = x; vec[1] = y; return *this; }
63   SbVec2i32 & setValue(const SbVec2ui32 & v);
64   SbVec2i32 & setValue(const SbVec2b & v);
65   SbVec2i32 & setValue(const SbVec2s & v);
66   SbVec2i32 & setValue(const SbVec2f & v);
67   SbVec2i32 & setValue(const SbVec2d & v);
68 
getValue(void)69   const int32_t * getValue(void) const { return vec; }
getValue(int32_t & x,int32_t & y)70   void getValue(int32_t & x, int32_t & y) const { x = vec[0]; y = vec[1]; }
71 
72   int32_t & operator [] (const int i) { return vec[i]; }
73   const int32_t & operator [] (const int i) const { return vec[i]; }
74 
dot(const SbVec2i32 & v)75   int32_t dot(const SbVec2i32 & v) const { return vec[0] * v[0] + vec[1] * v[1]; }
negate(void)76   void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; }
77 
78   SbVec2i32 & operator *= (int d) { vec[0] *= d; vec[1] *= d; return *this; }
79   SbVec2i32 & operator *= (double d);
80   SbVec2i32 & operator /= (int d) { SbDividerChk("SbVec2i32::operator/=(int)", d); vec[0] /= d; vec[1] /= d; return *this; }
81   SbVec2i32 & operator /= (double d) { SbDividerChk("SbVec2i32::operator/=(double)", d); return operator *= (1.0 / d); }
82   SbVec2i32 & operator += (const SbVec2i32 & v) { vec[0] += v[0]; vec[1] += v[1]; return *this; }
83   SbVec2i32 & operator -= (const SbVec2i32 & v) { vec[0] -= v[0]; vec[1] -= v[1]; return *this; }
84   SbVec2i32 operator - (void) const { return SbVec2i32(-vec[0], -vec[1]); }
85 
86   void print(FILE * fp) const;
87 
88 protected:
89   int32_t vec[2];
90 
91 }; // SbVec2i32
92 
93 COIN_DLL_API inline SbVec2i32 operator * (const SbVec2i32 & v, int d) {
94   SbVec2i32 val(v); val *= d; return val;
95 }
96 
97 COIN_DLL_API inline SbVec2i32 operator * (const SbVec2i32 & v, double d) {
98   SbVec2i32 val(v); val *= d; return val;
99 }
100 
101 COIN_DLL_API inline SbVec2i32 operator * (int d, const SbVec2i32 & v) {
102   SbVec2i32 val(v); val *= d; return val;
103 }
104 
105 COIN_DLL_API inline SbVec2i32 operator * (double d, const SbVec2i32 & v) {
106   SbVec2i32 val(v); val *= d; return val;
107 }
108 
109 COIN_DLL_API inline SbVec2i32 operator / (const SbVec2i32 & v, int d) {
110   SbDividerChk("operator/(SbVec2i32,int)", d);
111   SbVec2i32 val(v); val /= d; return val;
112 }
113 
114 COIN_DLL_API inline SbVec2i32 operator / (const SbVec2i32 & v, double d) {
115   SbDividerChk("operator/(SbVec2i32,double)", d);
116   SbVec2i32 val(v); val /= d; return val;
117 }
118 
119 COIN_DLL_API inline SbVec2i32 operator + (const SbVec2i32 & v1, const SbVec2i32 & v2) {
120   SbVec2i32 v(v1); v += v2; return v;
121 }
122 
123 COIN_DLL_API inline SbVec2i32 operator - (const SbVec2i32 & v1, const SbVec2i32 & v2) {
124   SbVec2i32 v(v1); v -= v2; return v;
125 }
126 
127 COIN_DLL_API inline int operator == (const SbVec2i32 & v1, const SbVec2i32 & v2) {
128   return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
129 }
130 
131 COIN_DLL_API inline int operator != (const SbVec2i32& v1, const SbVec2i32& v2) {
132   return !(v1 == v2);
133 }
134 
135 #endif // !COIN_SBVEC2I32_H
136