1 | /**********************************************************************
|
---|
2 | *<
|
---|
3 | FILE: ipoint2.h
|
---|
4 |
|
---|
5 | DESCRIPTION: Class definintion for IPoint2: Integer 2D point.
|
---|
6 |
|
---|
7 | CREATED BY: Dan Silva
|
---|
8 |
|
---|
9 | HISTORY:
|
---|
10 |
|
---|
11 | *> Copyright (c) 1994, All Rights Reserved.
|
---|
12 | **********************************************************************/
|
---|
13 |
|
---|
14 | #ifndef __IPOINT2__
|
---|
15 |
|
---|
16 | #define __IPOINT2__
|
---|
17 |
|
---|
18 | class ostream;
|
---|
19 |
|
---|
20 | class IPoint2 {
|
---|
21 | public:
|
---|
22 | int x,y;
|
---|
23 |
|
---|
24 | // Constructors
|
---|
25 | IPoint2(){}
|
---|
26 | IPoint2(int X, int Y) { x = X; y = Y; }
|
---|
27 | IPoint2(const IPoint2& a) { x = a.x; y = a.y; }
|
---|
28 | IPoint2(int af[2]) { x = af[0]; y = af[1]; }
|
---|
29 |
|
---|
30 | // Access operators
|
---|
31 | int& operator[](int i) { return (&x)[i]; }
|
---|
32 | const int& operator[](int i) const { return (&x)[i]; }
|
---|
33 |
|
---|
34 | // Conversion function
|
---|
35 | operator int*() { return(&x); }
|
---|
36 |
|
---|
37 | // Unary operators
|
---|
38 | IPoint2 operator-() const { return(IPoint2(-x,-y)); }
|
---|
39 | IPoint2 operator+() const { return *this; }
|
---|
40 |
|
---|
41 | // Assignment operators
|
---|
42 | IPoint2& operator-=(const IPoint2&);
|
---|
43 | IPoint2& operator+=(const IPoint2&);
|
---|
44 | DllExport IPoint2& operator*=(int);
|
---|
45 | DllExport IPoint2& operator/=(int);
|
---|
46 |
|
---|
47 | // Binary operators
|
---|
48 | DllExport IPoint2 IPoint2::operator-(const IPoint2&) const;
|
---|
49 | DllExport IPoint2 IPoint2::operator+(const IPoint2&) const;
|
---|
50 | DllExport int DotProd(const IPoint2&) const; // DOT PRODUCT
|
---|
51 | DllExport int operator*(const IPoint2&) const; // DOT PRODUCT
|
---|
52 |
|
---|
53 | // Relational operators
|
---|
54 | int operator==(const IPoint2& p) const { return (x == p.x && y == p.y); }
|
---|
55 | };
|
---|
56 |
|
---|
57 | int DllExport Length(const IPoint2&);
|
---|
58 | IPoint2 DllExport Normalize(const IPoint2&); // Return a unit vector.
|
---|
59 | IPoint2 DllExport operator*(int, const IPoint2&); // multiply by scalar
|
---|
60 | IPoint2 DllExport operator*(const IPoint2&, int); // multiply by scalar
|
---|
61 | IPoint2 DllExport operator/(const IPoint2&, int); // divide by scalar
|
---|
62 |
|
---|
63 | ostream DllExport &operator<<(ostream&, const IPoint2&);
|
---|
64 |
|
---|
65 | // Inlines:
|
---|
66 |
|
---|
67 | inline int MaxComponent(const IPoint2& p) { return(p.x>p.y?0:1); }
|
---|
68 | inline int MinComponent(const IPoint2& p) { return(p.x<p.y?0:1); }
|
---|
69 |
|
---|
70 | inline int Length(const IPoint2& v) {
|
---|
71 | return (int)sqrt(v.x*v.x+v.y*v.y);
|
---|
72 | }
|
---|
73 |
|
---|
74 | inline IPoint2& IPoint2::operator-=(const IPoint2& a) {
|
---|
75 | x -= a.x; y -= a.y;
|
---|
76 | return *this;
|
---|
77 | }
|
---|
78 |
|
---|
79 | inline IPoint2& IPoint2::operator+=(const IPoint2& a) {
|
---|
80 | x += a.x; y += a.y;
|
---|
81 | return *this;
|
---|
82 | }
|
---|
83 |
|
---|
84 | inline IPoint2& IPoint2::operator*=(int f) {
|
---|
85 | x *= f; y *= f;
|
---|
86 | return *this;
|
---|
87 | }
|
---|
88 |
|
---|
89 | inline IPoint2& IPoint2::operator/=(int f) {
|
---|
90 | x /= f; y /= f;
|
---|
91 | return *this;
|
---|
92 | }
|
---|
93 |
|
---|
94 | inline IPoint2 IPoint2::operator-(const IPoint2& b) const{
|
---|
95 | return(IPoint2(x-b.x,y-b.y));
|
---|
96 | }
|
---|
97 |
|
---|
98 | inline IPoint2 IPoint2::operator+(const IPoint2& b) const {
|
---|
99 | return(IPoint2(x+b.x,y+b.y));
|
---|
100 | }
|
---|
101 |
|
---|
102 | inline int IPoint2::DotProd(const IPoint2& b) const{
|
---|
103 | return(x*b.x+y*b.y);
|
---|
104 | }
|
---|
105 |
|
---|
106 | inline int IPoint2::operator*(const IPoint2& b)const {
|
---|
107 | return(x*b.x+y*b.y);
|
---|
108 | }
|
---|
109 |
|
---|
110 | inline IPoint2 operator*(int f, const IPoint2& a) {
|
---|
111 | return(IPoint2(a.x*f, a.y*f));
|
---|
112 | }
|
---|
113 |
|
---|
114 | inline IPoint2 operator*(const IPoint2& a, int f) {
|
---|
115 | return(IPoint2(a.x*f, a.y*f));
|
---|
116 | }
|
---|
117 |
|
---|
118 | inline IPoint2 operator/(const IPoint2& a, int f) {
|
---|
119 | return(IPoint2(a.x/f, a.y/f));
|
---|
120 | }
|
---|
121 |
|
---|
122 | #endif
|
---|
123 |
|
---|