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

SbVec2d.h

00001 #ifndef COIN_SBVEC2D_H
00002 #define COIN_SBVEC2D_H
00003 
00004 /**************************************************************************\
00005  *
00006  *  This file is part of the Coin 3D visualization library.
00007  *  Copyright (C) by Kongsberg Oil & Gas Technologies.
00008  *
00009  *  This library is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU General Public License
00011  *  ("GPL") version 2 as published by the Free Software Foundation.
00012  *  See the file LICENSE.GPL at the root directory of this source
00013  *  distribution for additional information about the GNU GPL.
00014  *
00015  *  For using Coin with software that can not be combined with the GNU
00016  *  GPL, and for taking advantage of the additional benefits of our
00017  *  support services, please contact Kongsberg Oil & Gas Technologies
00018  *  about acquiring a Coin Professional Edition License.
00019  *
00020  *  See http://www.coin3d.org/ for more information.
00021  *
00022  *  Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
00023  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
00024  *
00025 \**************************************************************************/
00026 
00027 #include <stdio.h>
00028 
00029 #include <Inventor/SbBasic.h>
00030 #ifndef NDEBUG
00031 #include <Inventor/errors/SoDebugError.h>
00032 #endif // !NDEBUG
00033 
00034 class SbVec2f;
00035 class SbVec2b;
00036 class SbVec2s;
00037 class SbVec2i32;
00038 
00039 class COIN_DLL_API SbVec2d {
00040 public:
00041   SbVec2d(void) { }
00042   SbVec2d(const double v[2]) { vec[0] = v[0]; vec[1] = v[1]; }
00043   SbVec2d(double x, double y) { vec[0] = x; vec[1] = y; }
00044   explicit SbVec2d(const SbVec2f & v) { setValue(v); }
00045   explicit SbVec2d(const SbVec2b & v) { setValue(v); }
00046   explicit SbVec2d(const SbVec2s & v) { setValue(v); }
00047   explicit SbVec2d(const SbVec2i32 & v) { setValue(v); }
00048 
00049   SbVec2d & setValue(const double v[2]) { vec[0] = v[0]; vec[1] = v[1]; return *this; }
00050   SbVec2d & setValue(double x, double y) { vec[0] = x; vec[1] = y; return *this; }
00051   SbVec2d & setValue(const SbVec2f & v);
00052   SbVec2d & setValue(const SbVec2b & v);
00053   SbVec2d & setValue(const SbVec2s & v);
00054   SbVec2d & setValue(const SbVec2i32 & v);
00055 
00056   const double * getValue(void) const { return vec; }
00057   void getValue(double & x, double & y) const { x = vec[0]; y = vec[1]; }
00058 
00059   double & operator [] (int i) { return vec[i]; } 
00060   const double & operator [] (int i) const { return vec[i]; }
00061 
00062   SbBool equals(const SbVec2d & v, double tolerance) const;
00063   double dot(const SbVec2d & v) const { return vec[0] * v[0] + vec[1] * v[1]; }
00064   double length(void) const;
00065   double sqrLength(void) const { return vec[0]*vec[0] + vec[1]*vec[1]; }
00066   double normalize(void);
00067   void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; }
00068 
00069   SbVec2d & operator *= (double d) { vec[0] *= d; vec[1] *= d; return *this; }
00070   SbVec2d & operator /= (double d) { SbDividerChk("SbVec2d::operator/=(double)", d); return operator *= (1.0 / d); }
00071   SbVec2d & operator += (const SbVec2d & v) { vec[0] += v[0]; vec[1] += v[1]; return *this; }
00072   SbVec2d & operator -= (const SbVec2d & v) { vec[0] -= v[0]; vec[1] -= v[1]; return *this; }
00073   SbVec2d operator - (void) const { return SbVec2d(-vec[0], -vec[1]); }
00074 
00075   void print(FILE * fp) const;
00076 
00077 protected:
00078   double vec[2];
00079 
00080 }; // SbVec2d
00081 
00082 COIN_DLL_API inline SbVec2d operator * (const SbVec2d & v, const double d) {
00083   SbVec2d val(v); val *= d; return val;
00084 }
00085 
00086 COIN_DLL_API inline SbVec2d operator * (const double d, const SbVec2d & v) {
00087   SbVec2d val(v); val *= d; return val;
00088 }
00089 
00090 COIN_DLL_API inline SbVec2d operator / (const SbVec2d & v, const double d) {
00091   SbDividerChk("operator/(SbVec2d,double)", d);
00092   SbVec2d val(v); val /= d; return val;
00093 }
00094 
00095 COIN_DLL_API inline SbVec2d operator + (const SbVec2d & v1, const SbVec2d & v2) {
00096   SbVec2d v(v1); v += v2; return v;
00097 }
00098 
00099 COIN_DLL_API inline SbVec2d operator - (const SbVec2d & v1, const SbVec2d & v2) {
00100   SbVec2d v(v1); v -= v2; return v;
00101 }
00102 
00103 COIN_DLL_API inline int operator == (const SbVec2d & v1, const SbVec2d & v2) {
00104   return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
00105 }
00106 
00107 COIN_DLL_API inline int operator != (const SbVec2d & v1, const SbVec2d & v2) {
00108   return !(v1 == v2);
00109 }
00110 
00111 // *************************************************************************
00112 
00113 #endif // !COIN_SBVEC2D_H

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

Generated on Sun May 1 2011 02:58:20 for Coin by Doxygen 1.7.3.