00001 #ifndef Vector2_H 00002 #define Vector2_H 00003 /*######################################################################## 00004 File: Vector2.h 00005 Creation date: 25th May 2002 00006 00007 Copyright 2002 Mark Williams, all rights reserved. 00008 Contact: mark@extrabit.com 00009 http://www.extrabit.com 00010 00011 This program is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU General Public License 00013 as published by the Free Software Foundation; either version 2 00014 of the License, or (at your option) any later version. 00015 00016 This program is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU General Public License for more details. 00020 00021 ########################################################################*/ 00022 00023 /*######################################################################## 00024 Headers 00025 ########################################################################*/ 00026 00027 /*######################################################################## 00028 Declarations 00029 ########################################################################*/ 00030 00031 /*######################################################################## 00032 Class Definition 00033 ########################################################################*/ 00034 00037 class Vector2 00038 { 00039 public: 00040 Vector2 (void) { m_x = m_y = 0.0 ; } 00041 Vector2 (double x, double y) { m_x = x ; m_y = y ; } 00042 00043 const double& x (void) const { return m_x ; } 00044 const double& y (void) const { return m_y ; } 00045 double& x (void) { return m_x ; } 00046 double& y (void) { return m_y ; } 00047 00048 double distance_to (const Vector2&) const ; 00049 00050 const Vector2& operator+= (const Vector2&) ; 00051 Vector2 operator+ (const Vector2&) const ; 00052 Vector2 operator- (const Vector2&) const ; 00053 Vector2 operator* (double) const ; 00054 Vector2 operator/ (double) const ; 00055 00056 private: 00057 double m_x ; 00058 double m_y ; 00059 } ; 00060 00061 00064 inline const Vector2& Vector2::operator+= (const Vector2& v) 00065 { 00066 m_x += v.m_x ; 00067 m_y += v.m_y ; 00068 return *this ; 00069 } 00070 00071 00074 inline Vector2 Vector2::operator+ (const Vector2& v) const 00075 { 00076 return Vector2 (m_x + v.m_x, m_y + v.m_y) ; 00077 } 00078 00079 00082 inline Vector2 Vector2::operator- (const Vector2& v) const 00083 { 00084 return Vector2 (m_x - v.m_x, m_y - v.m_y) ; 00085 } 00086 00087 00088 /*######################################################################## 00089 End 00090 ########################################################################*/ 00091 #endif
1.2.16