| http://www.sim.no/ http://www.coin3d.org/

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

SbVec2i32.h
1 #ifndef COIN_SBVEC2I32_H
2 #define COIN_SBVEC2I32_H
3
4 /**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) by Kongsberg Oil & Gas Technologies.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * ("GPL") version 2 as published by the Free Software Foundation.
12 * See the file LICENSE.GPL at the root directory of this source
13 * distribution for additional information about the GNU GPL.
14 *
15 * For using Coin with software that can not be combined with the GNU
16 * GPL, and for taking advantage of the additional benefits of our
17 * support services, please contact Kongsberg Oil & Gas Technologies
18 * about acquiring a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25 \**************************************************************************/
26
27 #include <stdio.h>
28
29 #include <Inventor/SbBasic.h>
30 #include <Inventor/system/inttypes.h>
31 #ifndef NDEBUG
32 #include <Inventor/errors/SoDebugError.h>
33 #endif // !NDEBUG
34
35 class SbVec2ui32;
36 class SbVec2b;
37 class SbVec2s;
38 class SbVec2f;
39 class SbVec2d;
40
41 class COIN_DLL_API SbVec2i32 {
42 public:
43 SbVec2i32(void) { }
44 SbVec2i32(const int32_t v[2]) { vec[0] = v[0]; vec[1] = v[1]; }
45 SbVec2i32(int32_t x, int32_t y) { vec[0] = x; vec[1] = y; }
46 explicit SbVec2i32(const SbVec2ui32 & v) { setValue(v); }
47 explicit SbVec2i32(const SbVec2b & v) { setValue(v); }
48 explicit SbVec2i32(const SbVec2s & v) { setValue(v); }
49 explicit SbVec2i32(const SbVec2f & v) { setValue(v); }
50 explicit SbVec2i32(const SbVec2d & v) { setValue(v); }
51
52 SbVec2i32 & setValue(const int32_t v[2]) { vec[0] = v[0]; vec[1] = v[1]; return *this; }
53 SbVec2i32 & setValue(int32_t x, int32_t y) { vec[0] = x; vec[1] = y; return *this; }
54 SbVec2i32 & setValue(const SbVec2ui32 & v);
55 SbVec2i32 & setValue(const SbVec2b & v);
56 SbVec2i32 & setValue(const SbVec2s & v);
57 SbVec2i32 & setValue(const SbVec2f & v);
58 SbVec2i32 & setValue(const SbVec2d & v);
59
60 const int32_t * getValue(void) const { return vec; }
61 void getValue(int32_t & x, int32_t & y) const { x = vec[0]; y = vec[1]; }
62
63 int32_t & operator [] (const int i) { return vec[i]; }
64 const int32_t & operator [] (const int i) const { return vec[i]; }
65
66 int32_t dot(const SbVec2i32 & v) const { return vec[0] * v[0] + vec[1] * v[1]; }
67 void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; }
68
69 SbVec2i32 & operator *= (int d) { vec[0] *= d; vec[1] *= d; return *this; }
70 SbVec2i32 & operator *= (double d);
71 SbVec2i32 & operator /= (int d) { SbDividerChk("SbVec2i32::operator/=(int)", d); vec[0] /= d; vec[1] /= d; return *this; }
72 SbVec2i32 & operator /= (double d) { SbDividerChk("SbVec2i32::operator/=(double)", d); return operator *= (1.0 / d); }
73 SbVec2i32 & operator += (const SbVec2i32 & v) { vec[0] += v[0]; vec[1] += v[1]; return *this; }
74 SbVec2i32 & operator -= (const SbVec2i32 & v) { vec[0] -= v[0]; vec[1] -= v[1]; return *this; }
75 SbVec2i32 operator - (void) const { return SbVec2i32(-vec[0], -vec[1]); }
76
77 void print(FILE * fp) const;
78
79 protected:
80 int32_t vec[2];
81
82 }; // SbVec2i32
83
84 COIN_DLL_API inline SbVec2i32 operator * (const SbVec2i32 & v, int d) {
85 SbVec2i32 val(v); val *= d; return val;
86 }
87
88 COIN_DLL_API inline SbVec2i32 operator * (const SbVec2i32 & v, double d) {
89 SbVec2i32 val(v); val *= d; return val;
90 }
91
92 COIN_DLL_API inline SbVec2i32 operator * (int d, const SbVec2i32 & v) {
93 SbVec2i32 val(v); val *= d; return val;
94 }
95
96 COIN_DLL_API inline SbVec2i32 operator * (double d, const SbVec2i32 & v) {
97 SbVec2i32 val(v); val *= d; return val;
98 }
99
100 COIN_DLL_API inline SbVec2i32 operator / (const SbVec2i32 & v, int d) {
101 SbDividerChk("operator/(SbVec2i32,int)", d);
102 SbVec2i32 val(v); val /= d; return val;
103 }
104
105 COIN_DLL_API inline SbVec2i32 operator / (const SbVec2i32 & v, double d) {
106 SbDividerChk("operator/(SbVec2i32,double)", d);
107 SbVec2i32 val(v); val /= d; return val;
108 }
109
110 COIN_DLL_API inline SbVec2i32 operator + (const SbVec2i32 & v1, const SbVec2i32 & v2) {
111 SbVec2i32 v(v1); v += v2; return v;
112 }
113
114 COIN_DLL_API inline SbVec2i32 operator - (const SbVec2i32 & v1, const SbVec2i32 & v2) {
115 SbVec2i32 v(v1); v -= v2; return v;
116 }
117
118 COIN_DLL_API inline int operator == (const SbVec2i32 & v1, const SbVec2i32 & v2) {
119 return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
120 }
121
122 COIN_DLL_API inline int operator != (const SbVec2i32& v1, const SbVec2i32& v2) {
123 return !(v1 == v2);
124 }
125
126 #endif // !COIN_SBVEC2I32_H

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.