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

SbVec2ub.h

00001 #ifndef COIN_SBVEC2UB_H
00002 #define COIN_SBVEC2UB_H
00003 
00004 /**************************************************************************\
00005  *
00006  *  This file is part of the Coin 3D visualization library.
00007  *  Copyright (C) 1998-2007 by Systems in Motion.  All rights reserved.
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 Systems in Motion about acquiring
00018  *  a Coin Professional Edition License.
00019  *
00020  *  See http://www.coin3d.org/ for more information.
00021  *
00022  *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
00023  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
00024  *
00025 \**************************************************************************/
00026 
00027 #include <Inventor/SbBasic.h>
00028 #include <Inventor/system/inttypes.h>
00029 #ifndef NDEBUG
00030 #include <Inventor/errors/SoDebugError.h>
00031 #endif // !NDEBUG
00032 
00033 class SbVec2b;
00034 class SbVec2us;
00035 class SbVec2ui32;
00036 
00037 class COIN_DLL_API SbVec2ub {
00038 public:
00039   SbVec2ub(void) { }
00040   SbVec2ub(const uint8_t v[2]) { vec[0] = v[0]; vec[1] = v[1]; }
00041   SbVec2ub(uint8_t x, uint8_t y) { vec[0] = x; vec[1] = y; }
00042   explicit SbVec2ub(const SbVec2b & v) { setValue(v); }
00043   explicit SbVec2ub(const SbVec2us & v) { setValue(v); }
00044   explicit SbVec2ub(const SbVec2ui32 & v) { setValue(v); }
00045 
00046   SbVec2ub & setValue(const uint8_t v[2]) { vec[0] = v[0]; vec[1] = v[1]; return *this; }
00047   SbVec2ub & setValue(uint8_t x, uint8_t y) { vec[0] = x; vec[1] = y; return *this; }
00048   SbVec2ub & setValue(const SbVec2b & v);
00049   SbVec2ub & setValue(const SbVec2us & v);
00050   SbVec2ub & setValue(const SbVec2ui32 & v);
00051 
00052   const uint8_t * getValue(void) const { return vec; }
00053   void getValue(uint8_t & x, uint8_t & y) const { x = vec[0]; y = vec[1]; }
00054 
00055   uint8_t & operator [] (int i) { return vec[i]; }
00056   const uint8_t & operator [] (int i) const { return vec[i]; }
00057 
00058   int32_t dot(SbVec2ub v) const { return vec[0] * v[0] + vec[1] * v[1]; }
00059   void negate(void);
00060 
00061   SbVec2ub & operator *= (int d) { vec[0] *= d; vec[1] *= d; return *this; }
00062   SbVec2ub & operator *= (double d);
00063   SbVec2ub & operator /= (int d) { SbDividerChk("SbVec2ub::operator/=(int)", d); vec[0] /= d; vec[1] /= d; return *this; }
00064   SbVec2ub & operator /= (double d) { SbDividerChk("SbVec2ub::operator/=(double)", d); return operator *= (1.0 / d); }
00065   SbVec2ub & operator += (SbVec2ub v) { vec[0] += v[0]; vec[1] += v[1]; return *this; }
00066   SbVec2ub & operator -= (SbVec2ub v) { vec[0] -= v[0]; vec[1] -= v[1]; return *this; }
00067   SbVec2ub operator - (void) const { SbVec2ub v(*this); v.negate(); return v; }
00068 
00069 protected:
00070   uint8_t vec[2];
00071 
00072 }; // SbVec2ub
00073 
00074 COIN_DLL_API inline SbVec2ub operator * (SbVec2ub v, int d) {
00075   SbVec2ub val(v); val *= d; return val;
00076 }
00077 
00078 COIN_DLL_API inline SbVec2ub operator * (SbVec2ub v, double d) {
00079   SbVec2ub val(v); val *= d; return val;
00080 }
00081 
00082 COIN_DLL_API inline SbVec2ub operator * (int d, SbVec2ub v) {
00083   SbVec2ub val(v); val *= d; return val;
00084 }
00085 
00086 COIN_DLL_API inline SbVec2ub operator * (double d, SbVec2ub v) {
00087   SbVec2ub val(v); val *= d; return val;
00088 }
00089 
00090 COIN_DLL_API inline SbVec2ub operator / (SbVec2ub v, int d) {
00091   SbDividerChk("operator/(SbVec2ub,int)", d);
00092   SbVec2ub val(v); val /= d; return val;
00093 }
00094 
00095 COIN_DLL_API inline SbVec2ub operator / (SbVec2ub v, double d) {
00096   SbDividerChk("operator/(SbVec2ub,double)", d);
00097   SbVec2ub val(v); val /= d; return val;
00098 }
00099 
00100 COIN_DLL_API inline SbVec2ub operator + (SbVec2ub v1, SbVec2ub v2) {
00101   SbVec2ub v(v1); v += v2; return v;
00102 }
00103 
00104 COIN_DLL_API inline SbVec2ub operator - (SbVec2ub v1, SbVec2ub v2) {
00105   SbVec2ub v(v1); v -= v2; return v;
00106 }
00107 
00108 COIN_DLL_API inline int operator == (SbVec2ub v1, SbVec2ub v2) {
00109   return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
00110 }
00111 
00112 COIN_DLL_API inline int operator != (SbVec2ub v1, SbVec2ub v2) {
00113   return !(v1 == v2);
00114 }
00115 
00116 #endif // !COIN_SBVEC2UB_H

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Mon Feb 23 16:33:10 2009 for Coin by Doxygen. 1.5.8