Coin Logo http://www.coin3d.org/
http://www.kongsberg.com/kogt/

SbVec2d.h
1 #ifndef COIN_SBVEC2D_H
2 #define COIN_SBVEC2D_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 <stdio.h>
37 
38 #include <Inventor/SbBasic.h>
39 #ifndef NDEBUG
40 #include <Inventor/errors/SoDebugError.h>
41 #endif // !NDEBUG
42 
43 class SbVec2f;
44 class SbVec2b;
45 class SbVec2s;
46 class SbVec2i32;
47 
48 class COIN_DLL_API SbVec2d {
49 public:
50  SbVec2d(void) { }
51  SbVec2d(const double v[2]) { vec[0] = v[0]; vec[1] = v[1]; }
52  SbVec2d(double x, double y) { vec[0] = x; vec[1] = y; }
53  explicit SbVec2d(const SbVec2f & v) { setValue(v); }
54  explicit SbVec2d(const SbVec2b & v) { setValue(v); }
55  explicit SbVec2d(const SbVec2s & v) { setValue(v); }
56  explicit SbVec2d(const SbVec2i32 & v) { setValue(v); }
57 
58  SbVec2d & setValue(const double v[2]) { vec[0] = v[0]; vec[1] = v[1]; return *this; }
59  SbVec2d & setValue(double x, double y) { vec[0] = x; vec[1] = y; return *this; }
60  SbVec2d & setValue(const SbVec2f & v);
61  SbVec2d & setValue(const SbVec2b & v);
62  SbVec2d & setValue(const SbVec2s & v);
63  SbVec2d & setValue(const SbVec2i32 & v);
64 
65  const double * getValue(void) const { return vec; }
66  void getValue(double & x, double & y) const { x = vec[0]; y = vec[1]; }
67 
68  double & operator [] (int i) { return vec[i]; }
69  const double & operator [] (int i) const { return vec[i]; }
70 
71  SbBool equals(const SbVec2d & v, double tolerance) const;
72  double dot(const SbVec2d & v) const { return vec[0] * v[0] + vec[1] * v[1]; }
73  double length(void) const;
74  double sqrLength(void) const { return vec[0]*vec[0] + vec[1]*vec[1]; }
75  double normalize(void);
76  void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; }
77 
78  SbVec2d & operator *= (double d) { vec[0] *= d; vec[1] *= d; return *this; }
79  SbVec2d & operator /= (double d) { SbDividerChk("SbVec2d::operator/=(double)", d); return operator *= (1.0 / d); }
80  SbVec2d & operator += (const SbVec2d & v) { vec[0] += v[0]; vec[1] += v[1]; return *this; }
81  SbVec2d & operator -= (const SbVec2d & v) { vec[0] -= v[0]; vec[1] -= v[1]; return *this; }
82  SbVec2d operator - (void) const { return SbVec2d(-vec[0], -vec[1]); }
83 
84  void print(FILE * fp) const;
85 
86 protected:
87  double vec[2];
88 
89 }; // SbVec2d
90 
91 COIN_DLL_API inline SbVec2d operator * (const SbVec2d & v, const double d) {
92  SbVec2d val(v); val *= d; return val;
93 }
94 
95 COIN_DLL_API inline SbVec2d operator * (const double d, const SbVec2d & v) {
96  SbVec2d val(v); val *= d; return val;
97 }
98 
99 COIN_DLL_API inline SbVec2d operator / (const SbVec2d & v, const double d) {
100  SbDividerChk("operator/(SbVec2d,double)", d);
101  SbVec2d val(v); val /= d; return val;
102 }
103 
104 COIN_DLL_API inline SbVec2d operator + (const SbVec2d & v1, const SbVec2d & v2) {
105  SbVec2d v(v1); v += v2; return v;
106 }
107 
108 COIN_DLL_API inline SbVec2d operator - (const SbVec2d & v1, const SbVec2d & v2) {
109  SbVec2d v(v1); v -= v2; return v;
110 }
111 
112 COIN_DLL_API inline int operator == (const SbVec2d & v1, const SbVec2d & v2) {
113  return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
114 }
115 
116 COIN_DLL_API inline int operator != (const SbVec2d & v1, const SbVec2d & v2) {
117  return !(v1 == v2);
118 }
119 
120 // *************************************************************************
121 
122 #endif // !COIN_SBVEC2D_H
The SbVec2f class is a 2 dimensional vector with floating point coordinates.This vector class is used...
Definition: SbVec2f.h:49
SbVec2d(void)
Definition: SbVec2d.h:50
a vector class for containing two byte integers.
Definition: SbVec2b.h:48
SbVec2d(const SbVec2i32 &v)
Definition: SbVec2d.h:56
SbVec2d & setValue(double x, double y)
Definition: SbVec2d.h:59
double dot(const SbVec2d &v) const
Definition: SbVec2d.h:72
const double * getValue(void) const
Definition: SbVec2d.h:65
SbVec2d & setValue(const double v[2])
Definition: SbVec2d.h:58
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:48
SbVec2d(double x, double y)
Definition: SbVec2d.h:52
The SbVec2i32 class is a 2 dimensional vector with short integer coordinates.This vector class is use...
Definition: SbVec2i32.h:50
void negate(void)
Definition: SbVec2d.h:76
SbVec2d(const SbVec2b &v)
Definition: SbVec2d.h:54
SbVec2d(const double v[2])
Definition: SbVec2d.h:51
SbVec2d(const SbVec2s &v)
Definition: SbVec2d.h:55
SbVec2d(const SbVec2f &v)
Definition: SbVec2d.h:53
The SbVec2s class is a 2 dimensional vector with short integer coordinates.This vector class is used ...
Definition: SbVec2s.h:51
void getValue(double &x, double &y) const
Definition: SbVec2d.h:66

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

Generated for Coin by Doxygen