Changeset 2207:75a29ac69c19 in lemon0.x for lemon/dim2.h
 Timestamp:
 09/07/06 15:27:16 (13 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@2933
 File:

 1 moved
Legend:
 Unmodified
 Added
 Removed

lemon/dim2.h
r2157 r2207 17 17 */ 18 18 19 #ifndef LEMON_ XY_H20 #define LEMON_ XY_H19 #ifndef LEMON_DIM2_H 20 #define LEMON_DIM2_H 21 21 22 22 #include <iostream> … … 27 27 ///\brief A simple two dimensional vector and a bounding box implementation 28 28 /// 29 /// The class \ref lemon:: xy "xy" implements29 /// The class \ref lemon::dim2::Point "dim2::Point" implements 30 30 ///a two dimensional vector with the usual 31 31 /// operations. 32 32 /// 33 /// The class \ref lemon::BoundingBox "BoundingBox" can be used to determine 34 /// the rectangular bounding box of a set of \ref lemon::xy "xy"'s. 33 /// The class \ref lemon::dim2::BoundingBox "dim2::BoundingBox" 34 /// can be used to determine 35 /// the rectangular bounding box of a set of 36 /// \ref lemon::dim2::Point "dim2::Point"'s. 35 37 /// 36 38 ///\author Attila Bernath … … 38 40 39 41 namespace lemon { 42 43 ///Tools for handling two dimensional coordinates 44 45 ///This namespace is a storage of several 46 ///tools for handling two dimensional coordinates 47 namespace dim2 { 40 48 41 49 /// \addtogroup misc … … 48 56 /// operators. 49 57 /// 50 ///\note As you might have noticed, this class does not follow the51 ///\ref naming_conv "LEMON Coding Style" (it should be called \c Xy52 ///according to it). There is a stupid Hungarian proverb, "A kivétel53 ///erõsíti a szabályt" ("An exception54 ///reinforces a rule", which is55 ///actually a mistranslation of the Latin proverb "Exceptio probat regulam").56 ///This class is an example for that.57 ///\author Attila Bernath58 58 template<typename T> 59 class xy{59 class Point { 60 60 61 61 public: … … 69 69 70 70 ///Default constructor 71 xy() {}71 Point() {} 72 72 73 73 ///Construct an instance from coordinates 74 xy(T a, T b) : x(a), y(b) { }74 Point(T a, T b) : x(a), y(b) { } 75 75 76 76 77 77 ///Conversion constructor 78 template<class TT> xy(const xy<TT> &p) : x(p.x), y(p.y) {}78 template<class TT> Point(const Point<TT> &p) : x(p.x), y(p.y) {} 79 79 80 80 ///Give back the square of the norm of the vector … … 84 84 85 85 ///Increment the left hand side by u 86 xy<T>& operator +=(const xy<T>& u) {86 Point<T>& operator +=(const Point<T>& u) { 87 87 x += u.x; 88 88 y += u.y; … … 91 91 92 92 ///Decrement the left hand side by u 93 xy<T>& operator =(const xy<T>& u) {93 Point<T>& operator =(const Point<T>& u) { 94 94 x = u.x; 95 95 y = u.y; … … 98 98 99 99 ///Multiply the left hand side with a scalar 100 xy<T>& operator *=(const T &u) {100 Point<T>& operator *=(const T &u) { 101 101 x *= u; 102 102 y *= u; … … 105 105 106 106 ///Divide the left hand side by a scalar 107 xy<T>& operator /=(const T &u) {107 Point<T>& operator /=(const T &u) { 108 108 x /= u; 109 109 y /= u; … … 112 112 113 113 ///Return the scalar product of two vectors 114 T operator *(const xy<T>& u) const {114 T operator *(const Point<T>& u) const { 115 115 return x*u.x+y*u.y; 116 116 } 117 117 118 118 ///Return the sum of two vectors 119 xy<T> operator+(const xy<T> &u) const {120 xy<T> b=*this;119 Point<T> operator+(const Point<T> &u) const { 120 Point<T> b=*this; 121 121 return b+=u; 122 122 } 123 123 124 124 ///Return the neg of the vectors 125 xy<T> operator() const {126 xy<T> b=*this;125 Point<T> operator() const { 126 Point<T> b=*this; 127 127 b.x=b.x; b.y=b.y; 128 128 return b; … … 130 130 131 131 ///Return the difference of two vectors 132 xy<T> operator(const xy<T> &u) const {133 xy<T> b=*this;132 Point<T> operator(const Point<T> &u) const { 133 Point<T> b=*this; 134 134 return b=u; 135 135 } 136 136 137 137 ///Return a vector multiplied by a scalar 138 xy<T> operator*(const T &u) const {139 xy<T> b=*this;138 Point<T> operator*(const T &u) const { 139 Point<T> b=*this; 140 140 return b*=u; 141 141 } 142 142 143 143 ///Return a vector divided by a scalar 144 xy<T> operator/(const T &u) const {145 xy<T> b=*this;144 Point<T> operator/(const T &u) const { 145 Point<T> b=*this; 146 146 return b/=u; 147 147 } 148 148 149 149 ///Test equality 150 bool operator==(const xy<T> &u) const {150 bool operator==(const Point<T> &u) const { 151 151 return (x==u.x) && (y==u.y); 152 152 } 153 153 154 154 ///Test inequality 155 bool operator!=( xyu) const {155 bool operator!=(Point u) const { 156 156 return (x!=u.x)  (y!=u.y); 157 157 } … … 159 159 }; 160 160 161 ///Return an xy162 163 ///Return an xy164 ///\relates xy161 ///Return an Point 162 163 ///Return an Point 164 ///\relates Point 165 165 template <typename T> 166 inline xy<T> make_xy(const T& x, const T& y) {167 return xy<T>(x, y);166 inline Point<T> make_Point(const T& x, const T& y) { 167 return Point<T>(x, y); 168 168 } 169 169 … … 171 171 172 172 ///Return a vector multiplied by a scalar 173 ///\relates xy174 template<typename T> xy<T> operator*(const T &u,const xy<T> &x) {173 ///\relates Point 174 template<typename T> Point<T> operator*(const T &u,const Point<T> &x) { 175 175 return x*u; 176 176 } … … 179 179 180 180 ///Read a plainvector from a stream 181 ///\relates xy181 ///\relates Point 182 182 /// 183 183 template<typename T> 184 inline std::istream& operator>>(std::istream &is, xy<T> &z) {184 inline std::istream& operator>>(std::istream &is, Point<T> &z) { 185 185 char c; 186 186 if (is >> c) { … … 207 207 208 208 ///Write a plainvector to a stream 209 ///\relates xy209 ///\relates Point 210 210 /// 211 211 template<typename T> 212 inline std::ostream& operator<<(std::ostream &os, const xy<T>& z)212 inline std::ostream& operator<<(std::ostream &os, const Point<T>& z) 213 213 { 214 214 os << "(" << z.x << ", " << z.y << ")"; … … 219 219 220 220 ///Returns its parameter rotated by 90 degrees in positive direction. 221 ///\relates xy221 ///\relates Point 222 222 /// 223 223 template<typename T> 224 inline xy<T> rot90(const xy<T> &z)225 { 226 return xy<T>(z.y,z.x);224 inline Point<T> rot90(const Point<T> &z) 225 { 226 return Point<T>(z.y,z.x); 227 227 } 228 228 … … 230 230 231 231 ///Returns its parameter rotated by 180 degrees. 232 ///\relates xy232 ///\relates Point 233 233 /// 234 234 template<typename T> 235 inline xy<T> rot180(const xy<T> &z)236 { 237 return xy<T>(z.x,z.y);235 inline Point<T> rot180(const Point<T> &z) 236 { 237 return Point<T>(z.x,z.y); 238 238 } 239 239 … … 241 241 242 242 ///Returns its parameter rotated by 90 degrees in negative direction. 243 ///\relates xy243 ///\relates Point 244 244 /// 245 245 template<typename T> 246 inline xy<T> rot270(const xy<T> &z)247 { 248 return xy<T>(z.y,z.x);246 inline Point<T> rot270(const Point<T> &z) 247 { 248 return Point<T>(z.y,z.x); 249 249 } 250 250 … … 258 258 template<typename T> 259 259 class BoundingBox { 260 xy<T> bottom_left, top_right;260 Point<T> bottom_left, top_right; 261 261 bool _empty; 262 262 public: … … 266 266 267 267 ///Construct an instance from one point 268 BoundingBox( xy<T> a) { bottom_left=top_right=a; _empty = false; }268 BoundingBox(Point<T> a) { bottom_left=top_right=a; _empty = false; } 269 269 270 270 ///Were any points added? … … 282 282 ///Give back the bottom left corner. 283 283 ///If the bounding box is empty, then the return value is not defined. 284 xy<T> bottomLeft() const {284 Point<T> bottomLeft() const { 285 285 return bottom_left; 286 286 } … … 290 290 ///Set the bottom left corner. 291 291 ///It should only bee used for nonempty box. 292 void bottomLeft( xy<T> p) {292 void bottomLeft(Point<T> p) { 293 293 bottom_left = p; 294 294 } … … 298 298 ///Give back the top right corner. 299 299 ///If the bounding box is empty, then the return value is not defined. 300 xy<T> topRight() const {300 Point<T> topRight() const { 301 301 return top_right; 302 302 } … … 306 306 ///Set the top right corner. 307 307 ///It should only bee used for nonempty box. 308 void topRight( xy<T> p) {308 void topRight(Point<T> p) { 309 309 top_right = p; 310 310 } … … 314 314 ///Give back the bottom right corner. 315 315 ///If the bounding box is empty, then the return value is not defined. 316 xy<T> bottomRight() const {317 return xy<T>(top_right.x,bottom_left.y);316 Point<T> bottomRight() const { 317 return Point<T>(top_right.x,bottom_left.y); 318 318 } 319 319 … … 322 322 ///Set the bottom right corner. 323 323 ///It should only bee used for nonempty box. 324 void bottomRight( xy<T> p) {324 void bottomRight(Point<T> p) { 325 325 top_right.x = p.x; 326 326 bottom_left.y = p.y; … … 331 331 ///Give back the top left corner. 332 332 ///If the bounding box is empty, then the return value is not defined. 333 xy<T> topLeft() const {334 return xy<T>(bottom_left.x,top_right.y);333 Point<T> topLeft() const { 334 return Point<T>(bottom_left.x,top_right.y); 335 335 } 336 336 … … 339 339 ///Set the top left corner. 340 340 ///It should only bee used for nonempty box. 341 void topLeft( xy<T> p) {341 void topLeft(Point<T> p) { 342 342 top_right.y = p.y; 343 343 bottom_left.x = p.x; … … 425 425 426 426 ///Checks whether a point is inside a bounding box 427 bool inside(const xy<T>& u){427 bool inside(const Point<T>& u){ 428 428 if (_empty) 429 429 return false; … … 435 435 436 436 ///Increments a bounding box with a point 437 BoundingBox& add(const xy<T>& u){437 BoundingBox& add(const Point<T>& u){ 438 438 if (_empty){ 439 439 bottom_left=top_right=u; … … 450 450 451 451 // ///Sums a bounding box and a point 452 // BoundingBox operator +(const xy<T>& u){452 // BoundingBox operator +(const Point<T>& u){ 453 453 // BoundingBox b = *this; 454 454 // return b += u; … … 486 486 487 487 488 ///Map of xcoordinates of a n xy<>map488 ///Map of xcoordinates of a dim2::Point<>map 489 489 490 490 ///\ingroup maps … … 551 551 } 552 552 553 ///Map of ycoordinates of a n xy<>map553 ///Map of ycoordinates of a dim2::Point<>map 554 554 555 555 ///\ingroup maps … … 617 617 618 618 619 ///Map of the \ref xy::normSquare() "normSquare()" of an \ref xy "xy"map620 621 ///Map of the \ref xy::normSquare() "normSquare()" of an \ref xy "xy"map619 ///Map of the \ref Point::normSquare() "normSquare()" of an \ref Point "Point"map 620 621 ///Map of the \ref Point::normSquare() "normSquare()" of an \ref Point "Point"map 622 622 ///\ingroup maps 623 623 /// … … 649 649 /// @} 650 650 651 651 } //namespce dim2 652 652 653 } //namespace lemon 653 654 654 #endif //LEMON_ XY_H655 #endif //LEMON_DIM2_H
Note: See TracChangeset
for help on using the changeset viewer.