Coin Logo http://www.sim.no/
http://www.coin3d.org/

SbVec2s.h
1 #ifndef COIN_SBVEC2S_H
2 #define COIN_SBVEC2S_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 SbVec2us;
36 class SbVec2b;
37 class SbVec2i32;
38 class SbVec2f;
39 class SbVec2d;
40 
41 class COIN_DLL_API SbVec2s {
42 public:
43  SbVec2s(void) { }
44  SbVec2s(const short v[2]) { vec[0] = v[0]; vec[1] = v[1]; }
45  SbVec2s(short x, short y) { vec[0] = x; vec[1] = y; }
46  explicit SbVec2s(const SbVec2us & v) { setValue(v); }
47  explicit SbVec2s(const SbVec2b & v) { setValue(v); }
48  explicit SbVec2s(const SbVec2i32 & v) { setValue(v); }
49  explicit SbVec2s(const SbVec2f & v) { setValue(v); }
50  explicit SbVec2s(const SbVec2d & v) { setValue(v); }
51 
52  SbVec2s & setValue(const short v[2]) { vec[0] = v[0]; vec[1] = v[1]; return *this; }
53  SbVec2s & setValue(short x, short y) { vec[0] = x; vec[1] = y; return *this; }
54  SbVec2s & setValue(const SbVec2us & v);
55  SbVec2s & setValue(const SbVec2b & v);
56  SbVec2s & setValue(const SbVec2i32 & v);
57  SbVec2s & setValue(const SbVec2f & v);
58  SbVec2s & setValue(const SbVec2d & v);
59 
60  const short * getValue(void) const { return vec; }
61  void getValue(short & x, short & y) const { x = vec[0]; y = vec[1]; }
62 
63  short & operator [] (int i) { return vec[i]; }
64  const short & operator [] (int i) const { return vec[i]; }
65 
66  int32_t dot(SbVec2s 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  SbVec2s & operator *= (int d) { vec[0] *= d; vec[1] *= d; return *this; }
70  SbVec2s & operator *= (double d);
71  SbVec2s & operator /= (int d) { SbDividerChk("SbVec2s::operator/=(int)", d); vec[0] /= d; vec[1] /= d; return *this; }
72  SbVec2s & operator /= (double d) { SbDividerChk("SbVec2s::operator/=(double)", d); return operator *= (1.0 / d); }
73  SbVec2s & operator += (SbVec2s v) { vec[0] += v[0]; vec[1] += v[1]; return *this; }
74  SbVec2s & operator -= (SbVec2s v) { vec[0] -= v[0]; vec[1] -= v[1]; return *this; }
75  SbVec2s operator - (void) const { return SbVec2s(-vec[0], -vec[1]); }
76 
77  void print(FILE * fp) const;
78 
79 protected:
80  short vec[2];
81 
82 }; // SbVec2s
83 
84 COIN_DLL_API inline SbVec2s operator * (SbVec2s v, int d) {
85  SbVec2s val(v); val *= d; return val;
86 }
87 
88 COIN_DLL_API inline SbVec2s operator * (SbVec2s v, double d) {
89  SbVec2s val(v); val *= d; return val;
90 }
91 
92 COIN_DLL_API inline SbVec2s operator * (int d, SbVec2s v) {
93  SbVec2s val(v); val *= d; return val;
94 }
95 
96 COIN_DLL_API inline SbVec2s operator * (double d, SbVec2s v) {
97  SbVec2s val(v); val *= d; return val;
98 }
99 
100 COIN_DLL_API inline SbVec2s operator / (SbVec2s v, int d) {
101  SbDividerChk("operator/(SbVec2s,int)", d);
102  SbVec2s val(v); val /= d; return val;
103 }
104 
105 COIN_DLL_API inline SbVec2s operator / (SbVec2s v, double d) {
106  SbDividerChk("operator/(SbVec2s,double)", d);
107  SbVec2s val(v); val /= d; return val;
108 }
109 
110 COIN_DLL_API inline SbVec2s operator + (SbVec2s v1, SbVec2s v2) {
111  SbVec2s v(v1); v += v2; return v;
112 }
113 
114 COIN_DLL_API inline SbVec2s operator - (SbVec2s v1, SbVec2s v2) {
115  SbVec2s v(v1); v -= v2; return v;
116 }
117 
118 COIN_DLL_API inline int operator == (SbVec2s v1, SbVec2s v2) {
119  return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
120 }
121 
122 COIN_DLL_API inline int operator != (SbVec2s v1, SbVec2s v2) {
123  return !(v1 == v2);
124 }
125 
126 #endif // !COIN_SBVEC2S_H
The SbVec2f class is a 2 dimensional vector with floating point coordinates.This vector class is used...
Definition: SbVec2f.h:39
void getValue(short &x, short &y) const
Definition: SbVec2s.h:61
a vector class for containing two byte integers.
Definition: SbVec2b.h:39
void negate(void)
Definition: SbVec2s.h:67
int operator!=(const SbBox2d &b1, const SbBox2d &b2)
Definition: SbBox2d.h:92
SbVec2s(const short v[2])
Definition: SbVec2s.h:44
int operator==(const SbBox2d &b1, const SbBox2d &b2)
Definition: SbBox2d.h:88
SbVec2s(short x, short y)
Definition: SbVec2s.h:45
SbVec2s & setValue(const short v[2])
Definition: SbVec2s.h:52
const short * getValue(void) const
Definition: SbVec2s.h:60
Definition: SbVec2us.h:37
The SbVec2d class is a 2 dimensional vector with double precision floating point coordinates.This vector class is used by many other classes in Coin. It provides storage for a vector in 2 dimensions aswell as simple floating point arithmetic operations on this vector.
Definition: SbVec2d.h:39
int32_t dot(SbVec2s v) const
Definition: SbVec2s.h:66
SbVec2d operator*(const SbVec2d &v, double d)
Definition: SbVec2d.h:82
SbVec2s(const SbVec2b &v)
Definition: SbVec2s.h:47
SbVec2d operator-(const SbVec2d &v1, const SbVec2d &v2)
Definition: SbVec2d.h:99
The SbVec2i32 class is a 2 dimensional vector with short integer coordinates.This vector class is use...
Definition: SbVec2i32.h:41
SbVec2d operator/(const SbVec2d &v, double d)
Definition: SbVec2d.h:90
SbVec2s & setValue(short x, short y)
Definition: SbVec2s.h:53
SbVec2s(const SbVec2d &v)
Definition: SbVec2s.h:50
SbVec2s(void)
Definition: SbVec2s.h:43
SbVec2d operator+(const SbVec2d &v1, const SbVec2d &v2)
Definition: SbVec2d.h:95
The SbVec2s class is a 2 dimensional vector with short integer coordinates.This vector class is used ...
Definition: SbVec2s.h:41
SbVec2s(const SbVec2f &v)
Definition: SbVec2s.h:49
SbVec2s(const SbVec2us &v)
Definition: SbVec2s.h:46
SbVec2s(const SbVec2i32 &v)
Definition: SbVec2s.h:48

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

Generated on Fri Sep 9 2016 for Coin by Doxygen 1.8.5.