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

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

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