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

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

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

Generated on Wed Jul 17 2024 for Coin by Doxygen 1.12.0.