// include/Vector.hh // This file is part of libpbe; see http://svn.chezphil.org/libpbe/ // (C) 2007 Philip Endecott // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef pbe_Vector_hh #define pbe_Vector_hh #include #include "Point.hh" namespace pbe { template struct Vector { typedef COORD_T coord_t; coord_t x; coord_t y; Vector() {} Vector(const Vector& other): x(other.x), y(other.y) {} Vector(coord_t x_, coord_t y_): x(x_), y(y_) {} bool operator<(const Vector& other) const { if (x Vector operator/=(DIV_T divisor) { x /= divisor; y /= divisor; return *this; } template Vector operator/(DIV_T divisor) const { Vector v = *this; v /= divisor; return v; } template Vector operator*=(MUL_T multiplier) { x *= multiplier; y *= multiplier; return *this; } template Vector operator*(MUL_T multiplier) const { Vector v = *this; v *= multiplier; return v; } }; template Vector operator-(const Point& a, const Point& b) { return Vector(a.x-b.x, a.y-b.y); } template Point operator+(const Point& a, const Vector& b) { return Point(a.x+b.x, a.y+b.y); } template Point operator-(const Point& a, const Vector& b) { return Point(a.x-b.x, a.y-b.y); } }; #endif