45 #ifndef _VRENDER_VECTOR2_H
46 #define _VRENDER_VECTOR2_H
77 inline double x()
const {
return _xyz[0]; }
78 inline double y()
const {
return _xyz[1]; }
79 inline void setX(
double r) { _xyz[0] = r; }
80 inline void setY(
double r) { _xyz[1] = r; }
81 inline void setXY (
double x,
double y) { _xyz[0] = x; _xyz[1] = y; }
87 inline Vector2& operator= (
const Vector2& u) { _xyz[0] = u._xyz[0]; _xyz[1] = u._xyz[1];
return *
this; }
102 _xyz[0] += v._xyz[0];
103 _xyz[1] += v._xyz[1];
109 _xyz[0] -= v._xyz[0];
110 _xyz[1] -= v._xyz[1];
114 inline Vector2& operator*= (
double f) { _xyz[0] *= f; _xyz[1] *= f;
return *
this;}
115 inline Vector2& operator/= (
double f) { _xyz[0] /= f; _xyz[1] /= f;
return *
this;}
123 return Vector2(_xyz[0]+u._xyz[0],_xyz[1]+u._xyz[1]);
127 return Vector2(_xyz[0]-u._xyz[0],_xyz[1]-u._xyz[1]);
130 inline double operator*(
const Vector2& u)
const
132 return _xyz[0]*u._xyz[0] + _xyz[1]*u._xyz[1] ;
135 inline double operator^(
const Vector2& v)
const
137 return _xyz[0]*v._xyz[1] - _xyz[1]*v._xyz[0] ;
140 Vector2 operator/ (
double v) {
return Vector2(_xyz[0]/v,_xyz[1]/v); }
141 Vector2 operator* (
double v) {
return Vector2(_xyz[0]*v,_xyz[1]*v); }
149 double norm ()
const;
159 double operator[] (
int i)
const
162 throw std::runtime_error(
"Out of bounds in Vector2::operator[]") ;
167 double& operator[] (
int i)
170 throw std::runtime_error(
"Out of bounds in Vector2::operator[]") ;
double squareNorm() const
Square norm (self dot product)
Vector2()
Default constructor.
~Vector2()
Default destructor.
double norm() const
Norm.
double infNorm() const
Infinite norm.
friend std::ostream & operator<<(std::ostream &, const Vector2 &)
Out stream override: prints the 3 vector components.