7 #define ABS(x) ( x>0 ? x : -x )
14 ePoint( int xpos, int ypos );
23 int manhattanLength() const;
28 ePoint &operator+=( const ePoint &p );
29 ePoint &operator-=( const ePoint &p );
30 ePoint &operator*=( int c );
31 ePoint &operator*=( double c );
32 ePoint &operator/=( int c );
33 ePoint &operator/=( double c );
35 friend inline bool operator==( const ePoint &, const ePoint & );
36 friend inline bool operator!=( const ePoint &, const ePoint & );
37 friend inline ePoint operator+( const ePoint &, const ePoint & );
38 friend inline ePoint operator-( const ePoint &, const ePoint & );
39 friend inline ePoint operator*( const ePoint &, int );
40 friend inline ePoint operator*( int, const ePoint & );
41 friend inline ePoint operator*( const ePoint &, double );
42 friend inline ePoint operator*( double, const ePoint & );
43 friend inline ePoint operator-( const ePoint & );
44 friend inline ePoint operator/( const ePoint &, int );
45 friend inline ePoint operator/( const ePoint &, double );
52 inline int ePoint::manhattanLength() const
54 return ABS(x())+ABS(y());
58 /*****************************************************************************
59 ePoint stream functions
60 *****************************************************************************/
63 inline ostream &operator<<( ostream & s, const ePoint & p )
69 inline istream &operator>>( istream & s, ePoint & p )
71 s >> p.rx() >> p.ry();
77 /*****************************************************************************
78 ePoint inline functions
79 *****************************************************************************/
81 inline ePoint::ePoint()
84 inline ePoint::ePoint( int xpos, int ypos )
85 { xp=(int)xpos; yp=(int)ypos; }
87 inline bool ePoint::isNull() const
88 { return xp == 0 && yp == 0; }
90 inline int ePoint::x() const
93 inline int ePoint::y() const
96 inline void ePoint::setX( int x )
99 inline void ePoint::setY( int y )
102 inline int &ePoint::rx()
105 inline int &ePoint::ry()
108 inline ePoint &ePoint::operator+=( const ePoint &p )
109 { xp+=p.xp; yp+=p.yp; return *this; }
111 inline ePoint &ePoint::operator-=( const ePoint &p )
112 { xp-=p.xp; yp-=p.yp; return *this; }
114 inline ePoint &ePoint::operator*=( int c )
115 { xp*=(int)c; yp*=(int)c; return *this; }
117 inline ePoint &ePoint::operator*=( double c )
118 { xp=(int)(xp*c); yp=(int)(yp*c); return *this; }
120 inline bool operator==( const ePoint &p1, const ePoint &p2 )
121 { return p1.xp == p2.xp && p1.yp == p2.yp; }
123 inline bool operator!=( const ePoint &p1, const ePoint &p2 )
124 { return p1.xp != p2.xp || p1.yp != p2.yp; }
126 inline ePoint operator+( const ePoint &p1, const ePoint &p2 )
127 { return ePoint(p1.xp+p2.xp, p1.yp+p2.yp); }
129 inline ePoint operator-( const ePoint &p1, const ePoint &p2 )
130 { return ePoint(p1.xp-p2.xp, p1.yp-p2.yp); }
132 inline ePoint operator*( const ePoint &p, int c )
133 { return ePoint(p.xp*c, p.yp*c); }
135 inline ePoint operator*( int c, const ePoint &p )
136 { return ePoint(p.xp*c, p.yp*c); }
138 inline ePoint operator*( const ePoint &p, double c )
139 { return ePoint((int)(p.xp*c), (int)(p.yp*c)); }
141 inline ePoint operator*( double c, const ePoint &p )
142 { return ePoint((int)(p.xp*c), (int)(p.yp*c)); }
144 inline ePoint operator-( const ePoint &p )
145 { return ePoint(-p.xp, -p.yp); }
147 inline ePoint &ePoint::operator/=( int c )
154 inline ePoint &ePoint::operator/=( double c )
161 inline ePoint operator/( const ePoint &p, int c )
163 return ePoint(p.xp/c, p.yp/c);
166 inline ePoint operator/( const ePoint &p, double c )
168 return ePoint((int)(p.xp/c), (int)(p.yp/c));