Go to the
documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #pragma once
00014
00015 #include "GeomExport.h"
00016 #include "maxheap.h"
00017 #include <iosfwd>
00018 #include <math.h>
00019
00020
00029 class IPoint2 : public MaxHeapOperators {
00030 public:
00031 int x,y;
00032
00033
00035 IPoint2(){}
00037 IPoint2(int X, int Y) { x = X; y = Y; }
00039 IPoint2(const IPoint2& a) { x = a.x; y = a.y; }
00042 IPoint2(int af[2]) { x = af[0]; y = af[1]; }
00043
00044
00047 int& operator[](int i) { return (&x)[i]; }
00050 const int& operator[](int i) const { return (&x)[i]; }
00051
00052
00054 operator int*() { return(&x); }
00055
00056
00058 IPoint2 operator-() const { return(IPoint2(-x,-y)); }
00060 IPoint2 operator+() const { return *this; }
00061
00062
00064 IPoint2& operator-=(const IPoint2&);
00066 IPoint2& operator+=(const IPoint2&);
00068 GEOMEXPORT IPoint2& operator*=(int);
00070 GEOMEXPORT IPoint2& operator/=(int);
00071
00072
00074 GEOMEXPORT IPoint2 operator-(const IPoint2&) const;
00076 GEOMEXPORT IPoint2 operator+(const IPoint2&) const;
00081 GEOMEXPORT int DotProd(const IPoint2&) const;
00084 GEOMEXPORT int operator*(const IPoint2&) const;
00085
00086
00090 int operator==(const IPoint2& p) const { return (x == p.x && y == p.y); }
00091 int operator!=(const IPoint2& p) const { return (x != p.x || y != p.y); }
00092 };
00093
00096 GEOMEXPORT int Length(const IPoint2&);
00099 GEOMEXPORT IPoint2 Normalize(const IPoint2&);
00101 GEOMEXPORT IPoint2 operator*(int, const IPoint2&);
00103 GEOMEXPORT IPoint2 operator*(const IPoint2&, int);
00106 GEOMEXPORT IPoint2 operator/(const IPoint2&, int);
00107
00108 GEOMEXPORT std::ostream &operator<<(std::ostream&, const IPoint2&);
00109
00110
00111
00113 inline int MaxComponent(const IPoint2& p) { return(p.x>p.y?0:1); }
00115 inline int MinComponent(const IPoint2& p) { return(p.x<p.y?0:1); }
00116
00117 inline int Length(const IPoint2& v) {
00118 return (int)sqrt((double)(v.x*v.x+v.y*v.y));
00119 }
00120
00121 inline IPoint2& IPoint2::operator-=(const IPoint2& a) {
00122 x -= a.x; y -= a.y;
00123 return *this;
00124 }
00125
00126 inline IPoint2& IPoint2::operator+=(const IPoint2& a) {
00127 x += a.x; y += a.y;
00128 return *this;
00129 }
00130
00131 inline IPoint2& IPoint2::operator*=(int f) {
00132 x *= f; y *= f;
00133 return *this;
00134 }
00135
00136 inline IPoint2& IPoint2::operator/=(int f) {
00137 x /= f; y /= f;
00138 return *this;
00139 }
00140
00141 inline IPoint2 IPoint2::operator-(const IPoint2& b) const{
00142 return(IPoint2(x-b.x,y-b.y));
00143 }
00144
00145 inline IPoint2 IPoint2::operator+(const IPoint2& b) const {
00146 return(IPoint2(x+b.x,y+b.y));
00147 }
00148
00149 inline int IPoint2::DotProd(const IPoint2& b) const{
00150 return(x*b.x+y*b.y);
00151 }
00152
00153 inline int IPoint2::operator*(const IPoint2& b)const {
00154 return(x*b.x+y*b.y);
00155 }
00156
00157 inline IPoint2 operator*(int f, const IPoint2& a) {
00158 return(IPoint2(a.x*f, a.y*f));
00159 }
00160
00161 inline IPoint2 operator*(const IPoint2& a, int f) {
00162 return(IPoint2(a.x*f, a.y*f));
00163 }
00164
00165 inline IPoint2 operator/(const IPoint2& a, int f) {
00166 return(IPoint2(a.x/f, a.y/f));
00167 }
00168
00169