/* * Copyright (C) 2009 * Robert Bosch LLC * Research and Technology Center North America * Palo Alto, California * * All rights reserved. * *------------------------------------------------------------------------------ * project ....: Autonomous Technologies * file .......: rtcVec2.h * authors ....: Benjamin Pitzer * organization: Robert Bosch LLC * creation ...: 08/16/2006 * modified ...: $Date: 2009-01-21 18:19:16 -0800 (Wed, 21 Jan 2009) $ * changed by .: $Author: benjaminpitzer $ * revision ...: $Revision: 14 $ */ #ifndef RTC_VEC2_H #define RTC_VEC2_H //== INCLUDES ================================================================== #include "rtcMath.h" #include "rtcVec.h" //== NAMESPACES ================================================================ namespace rtc { // Forward declarations template class Vec; // M-d vector template class Vec2; // 2d Vector /** * A 2-D vector. */ template class Vec2: public Vec { public: // Constructors Vec2(); Vec2(const T* d); Vec2(const T a); Vec2(const T x0, const T x1); Vec2(const Vec& v); // Cast Operation template Vec2(const Vec& v); // Mutators void set(const T x0, const T x1); // Perp Operator Vec2 perp() const; // inherit member data and functions of parent using Vec::x; using Vec::set; }; // Declare a few common typdefs typedef Vec2 Vec2b; typedef Vec2 Vec2c; typedef Vec2 Vec2uc; typedef Vec2 Vec2i; typedef Vec2 Vec2f; typedef Vec2 Vec2d; //============================================================================== // Vec2 //============================================================================== // Constructors /** Ctor that doesn't initialize. */ template inline Vec2::Vec2() { } /** Ctor that intalizes from array. */ template inline Vec2::Vec2(const T* d) : Vec(d) {} /** Ctor that intalizes all elements from a scalar. */ template inline Vec2::Vec2(const T a) : Vec(a) {} /** Ctor that initializes vector with given values. */ template inline Vec2::Vec2(const T x0, const T x1) { set(x0,x1); } /** Ctor that initializes an Vec2 with a Vec. */ template inline Vec2::Vec2(const Vec& v) : Vec(v) {} // Casting Operation /** Casting Ctor that initializes an Vec2 with a Vec. */ template template inline Vec2::Vec2(const Vec& v) : Vec(v) {} // Mutators /** Set vector. */ template inline void Vec2::set(const T x0, const T x1) { x[0] = x0; x[1] = x1; } /** Perp Operator */ template inline Vec2 Vec2::perp() const { return Vec2(-x[1],x[0]); } //============================================================================== } // NAMESPACE rtc //============================================================================== #endif // RTC_VEC2_H defined //==============================================================================