MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vector.h
1 #ifndef VECTOR_H /* -*- C++ -*- */
2 #define VECTOR_H
3 
4 #include "FXP.h"
5 #include "Point.h"
6 
7 namespace MFM {
8  class Vector {
9  FXP16 x;
10  FXP16 y;
11  public:
12 
13  Vector() : x(0), y(0) { }
14  Vector(FXP16 x, FXP16 y) : x(x), y(y) { }
15  Vector(const SPoint p) : x(p.GetX()), y(p.GetY()) { }
16  Vector(const UPoint p) : x(p.GetX()), y(p.GetY()) { }
17 
18  FXP16 GetX() const { return x; }
19 
20  FXP16 GetY() const { return y; }
21 
22  void Print(ByteSink & f) {
23  f.Printf("(%06x,%06x)",x.asInt(),y.asInt());
24  }
25 
26  friend FXP16 GetDistSq(const Vector & v1, const Vector & v2) {
27  return (v1.x-v2.x)*(v1.x-v2.x)+(v1.y-v2.y)*(v1.y-v2.y);
28  }
29 
30  friend Vector operator+(const Vector & v1, const Vector & v2) {
31  return Vector(v1.x+v2.x,v1.y+v2.y);
32  }
33  friend Vector operator-(const Vector & v1) {
34  return Vector(-v1.x,-v1.y);
35  }
36  friend Vector operator-(const Vector & v1, const Vector & v2) {
37  return v1+-v2;
38  }
39  friend FXP16 operator*(const Vector & v1,const Vector v2) {
40  return v1.x*v2.x+v1.y*v2.y;
41  }
42  friend Vector operator*(const FXP16 num, const Vector & v1) {
43  return Vector(v1.x*num,v1.y*num);
44  }
45  friend Vector operator*(const Vector & v1,const FXP16 num) {
46  return num*v1;
47  }
48  friend Vector operator/(const Vector & v1,const FXP16 num) {
49  return 1.0/num*v1;
50  }
51 
52  Vector & operator=(const Vector & v1) {
53  this->x = v1.x;
54  this->y = v1.y;
55  return *this;
56  }
57 
58  Vector & operator+=(const Vector & v1) {
59  *this = *this + v1;
60  return *this;
61  }
62 
63  Vector & operator-=(const Vector & v1) {
64  *this = *this - v1;
65  return *this;
66  }
67 
68  Vector & operator*=(const FXP16 num) {
69  *this = *this * num;
70  return *this;
71  }
72 
73  Vector & operator/=(const FXP16 num) {
74  *this = *this / num;
75  return *this;
76  }
77 
78  };
79 }
80 #endif /* VECTOR_H */
T GetY() const
Definition: Point.tcc:40
Definition: ByteSink.h:47
Definition: Vector.h:8
T GetX() const
Definition: Point.tcc:34