OverSim
Vector2D.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef __VECTOR2D_H_
25 #define __VECTOR2D_H_
26 
27 #include <math.h>
28 #include <omnetpp.h>
29 #include <iostream>
30 
31 class Vector2D
32 {
33  public:
34  Vector2D();
35  Vector2D(double x, double y);
36 
37  double x, y;
38 
39  void normalize();
40  double distanceSqr(const Vector2D v) const;
41  double xyMaxDistance(const Vector2D v) const;
42  double cosAngle(const Vector2D& v) const;
43  int getQuadrant(const Vector2D& v) const;
44 
45  Vector2D& operator=(const Vector2D& v);
46  Vector2D& operator+=(const Vector2D& v);
47  Vector2D& operator-=(const Vector2D& v);
48  Vector2D& operator*=(const double s);
49  Vector2D& operator/=(const double s);
50  Vector2D operator+(const Vector2D& v) const;
51  Vector2D operator-(const Vector2D& v) const;
52  Vector2D operator*(const double s) const;
53  Vector2D operator/(const double s) const;
54  bool operator==(const Vector2D& v) const;
55  bool operator!=(const Vector2D& v) const;
56 
57  friend bool operator<(const Vector2D& a, const Vector2D& b);
58  friend std::ostream& operator<<(std::ostream& Stream, const Vector2D& v);
59 
60  void netPack(cCommBuffer *b);
61  void netUnpack(cCommBuffer *b);
62 };
63 
70 inline void doPacking(cCommBuffer *b, Vector2D& obj) {obj.netPack(b);}
71 
78 inline void doUnpacking(cCommBuffer *b, Vector2D& obj) {obj.netUnpack(b);}
79 
80 #endif