# Changes in /[13:83c84df7a956:20:9244aa9ec12e] in lemon

Ignore:
Files:
5 edited

Unmodified
Removed
• ## lemon/dim2.h

 r8 /// the rectangular bounding box of a set of /// \ref lemon::dim2::Point "dim2::Point"'s. /// ///\author Attila Bernath namespace lemon { typedef T Value; ///First co-ordinate ///First coordinate T x; ///Second co-ordinate ///Second coordinate T y; ///The dimension of the vector. ///This class give back always 2. /// ///The dimension of the vector. ///This function always returns 2. int size() const { return 2; } } ///Return the neg of the vectors ///Return the negative of the vector Point operator-() const { Point b=*this; }; ///Return an Point ///Return an Point ///Return a Point ///Return a Point. ///\relates Point template ///Return a vector multiplied by a scalar ///Return a vector multiplied by a scalar ///Return a vector multiplied by a scalar. ///\relates Point template Point operator*(const T &u,const Point &x) { ///Read a plainvector from a stream ///Read a plainvector from a stream ///Read a plainvector from a stream. ///\relates Point /// ///Write a plainvector to a stream ///Write a plainvector to a stream ///Write a plainvector to a stream. ///\relates Point /// ///Rotate by 90 degrees ///Returns its parameter rotated by 90 degrees in positive direction. ///Returns the parameter rotated by 90 degrees in positive direction. ///\relates Point /// ///Rotate by 180 degrees ///Returns its parameter rotated by 180 degrees. ///Returns the parameter rotated by 180 degrees. ///\relates Point /// ///Rotate by 270 degrees ///Returns its parameter rotated by 90 degrees in negative direction. ///Returns the parameter rotated by 90 degrees in negative direction. ///\relates Point /// /// A class to calculate or store the bounding box of plainvectors. /// ///\author Attila Bernath template class BoundingBox { ///Construct an instance from two points ///Construct an instance from two points ///\warning The coordinates of the bottom-left corner must be no more ///than those of the top-right one ///Construct an instance from two points. ///\param a The bottom left corner. ///\param b The top right corner. ///\warning The coordinates of the bottom left corner must be no more ///than those of the top right one. BoundingBox(Point a,Point b) { ///Construct an instance from four numbers ///Construct an instance from four numbers ///\warning The coordinates of the bottom-left corner must be no more ///than those of the top-right one ///Construct an instance from four numbers. ///\param l The left side of the box. ///\param b The bottom of the box. ///\param r The right side of the box. ///\param t The top of the box. ///\warning The left side must be no more than the right side and ///bottom must be no more than the top. BoundingBox(T l,T b,T r,T t) { } ///Were any points added? ///Return \c true if the bounding box is empty. ///Return \c true if the bounding box is empty (i.e. return \c false ///if at least one point was added to the box or the coordinates of ///the box were set). ///The coordinates of an empty bounding box are not defined. bool empty() const { return _empty; ///Set the bottom left corner. ///It should only bee used for non-empty box. ///It should only be used for non-empty box. void bottomLeft(Point p) { bottom_left = p; ///Set the top right corner. ///It should only bee used for non-empty box. ///It should only be used for non-empty box. void topRight(Point p) { top_right = p; ///Set the bottom right corner. ///It should only bee used for non-empty box. ///It should only be used for non-empty box. void bottomRight(Point p) { top_right.x = p.x; ///Set the top left corner. ///It should only bee used for non-empty box. ///It should only be used for non-empty box. void topLeft(Point p) { top_right.y = p.y; ///Set the bottom of the box. ///It should only bee used for non-empty box. ///It should only be used for non-empty box. void bottom(T t) { bottom_left.y = t; ///Set the top of the box. ///It should only bee used for non-empty box. ///It should only be used for non-empty box. void top(T t) { top_right.y = t; ///Set the left side of the box. ///It should only bee used for non-empty box ///It should only be used for non-empty box. void left(T t) { bottom_left.x = t; ///Set the right side of the box. ///It should only bee used for non-empty box ///It should only be used for non-empty box. void right(T t) { top_right.x = t; ///Checks whether a point is inside a bounding box bool inside(const Point& u){ bool inside(const Point& u) const { if (_empty) return false; ///Increments a bounding box with a point ///Increments a bounding box with a point. /// BoundingBox& add(const Point& u){ if (_empty){ } ///Increments a bounding to contain another bounding box ///Increments a bounding box to contain another bounding box ///Increments a bounding box to contain another bounding box. /// BoundingBox& add(const BoundingBox &u){ if ( !u.empty() ){ ///Intersection of two bounding boxes BoundingBox operator &(const BoundingBox& u){ ///Intersection of two bounding boxes. /// BoundingBox operator&(const BoundingBox& u) const { BoundingBox b; b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x); b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y); b.top_right.x=std::min(this->top_right.x,u.top_right.x); b.top_right.y=std::min(this->top_right.y,u.top_right.y); b._empty = this->_empty || u._empty || b.bottom_left.x>top_right.x && b.bottom_left.y>top_right.y; if (this->_empty || u._empty) { b._empty = true; } else { b.bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x); b.bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y); b.top_right.x = std::min(this->top_right.x,u.top_right.x); b.top_right.y = std::min(this->top_right.y,u.top_right.y); b._empty = b.bottom_left.x > b.top_right.x || b.bottom_left.y > b.top_right.y; } return b; } ///Map of x-coordinates of a dim2::Point<>-map ///\ingroup maps ///Map of x-coordinates of a dim2::Point<>-map ///Map of x-coordinates of a \ref Point "Point"-map ///\ingroup maps ///Map of x-coordinates of a \ref Point "Point"-map. /// template ///Returns a \ref ConstXMap class ///This function just returns an \ref ConstXMap class. ///This function just returns a \ref ConstXMap class. /// ///\ingroup maps } ///Map of y-coordinates of a dim2::Point<>-map ///Map of y-coordinates of a \ref Point "Point"-map ///\ingroup maps ///Map of y-coordinates of a dim2::Point<>-map ///Map of y-coordinates of a \ref Point "Point"-map. /// template }; ///Returns an \ref YMap class ///This function just returns an \ref YMap class. ///Returns a \ref YMap class ///This function just returns a \ref YMap class. /// ///\ingroup maps ///Returns a \ref ConstYMap class ///This function just returns an \ref ConstYMap class. ///This function just returns a \ref ConstYMap class. /// ///\ingroup maps ///\brief Map of the \ref Point::normSquare() "normSquare()" ///of an \ref Point "Point"-map ///of a \ref Point "Point"-map /// ///Map of the \ref Point::normSquare() "normSquare()" ///of an \ref Point "Point"-map ///of a \ref Point "Point"-map. ///\ingroup maps /// ///Returns a \ref NormSquareMap class ///This function just returns an \ref NormSquareMap class. ///This function just returns a \ref NormSquareMap class. /// ///\ingroup maps
• ## lemon/random.cc

 r10 /// \brief Global random number generator instance /// /// A global mersenne twister random number generator instance /// A global Mersenne Twister random number generator instance. Random rnd; }
• ## lemon/random.h

 r12 ///\file ///\brief Mersenne Twister random number generator /// ///\author Balazs Dezso namespace lemon { /// good programming convenience to use this global generator to get /// random numbers. /// /// \author Balazs Dezso class Random { private: // architecture word // Architecture word typedef unsigned long Word; /// Gauss distribution with given mean and standard deviation /// Gauss distribution with given mean and standard deviation /// \sa gauss() /// double gauss(double mean,double std_dev) { /// Uniform distribution on the full unit circle. /// Uniform distribution on the full unit circle. /// dim2::Point disc() {
• ## lemon/tolerance.h

 r7 ///\sa Tolerance ///\sa Tolerance #if defined __GNUC__ && !defined __STRICT_ANSI__ ///\sa Tolerance #endif ///\sa Tolerance #if defined __GNUC__ && !defined __STRICT_ANSI__ ///\sa Tolerance #endif template bool negative(Value a) const { return -_epsilon>a; } ///Returns \c true if \c a is \e surely non-zero bool nonZero(Value a) const { return positive(a)||negative(a); }; bool nonZero(Value a) const { return positive(a)||negative(a); } ///@} bool negative(Value a) const { return -_epsilon>a; } ///Returns \c true if \c a is \e surely non-zero bool nonZero(Value a) const { return positive(a)||negative(a); }; bool nonZero(Value a) const { return positive(a)||negative(a); } ///@} bool negative(Value a) const { return -_epsilon>a; } ///Returns \c true if \c a is \e surely non-zero bool nonZero(Value a) const { return positive(a)||negative(a); }; bool nonZero(Value a) const { return positive(a)||negative(a); } ///@} static bool negative(Value a) { return 0>a; } ///Returns \c true if \c a is \e surely non-zero static bool nonZero(Value a) { return a!=0; }; static bool nonZero(Value a) { return a!=0; } ///@} static bool negative(Value) { return false; } ///Returns \c true if \c a is \e surely non-zero static bool nonZero(Value a) { return a!=0; }; static bool nonZero(Value a) { return a!=0; } ///@} static bool negative(Value a) { return 0>a; } ///Returns \c true if \c a is \e surely non-zero static bool nonZero(Value a) { return a!=0;}; static bool nonZero(Value a) { return a!=0;} ///@} static bool negative(Value) { return false; } ///Returns \c true if \c a is \e surely non-zero static bool nonZero(Value a) { return a!=0;}; static bool nonZero(Value a) { return a!=0;} ///@} static bool negative(Value a) { return 0>a; } ///Returns \c true if \c a is \e surely non-zero static bool nonZero(Value a) { return a!=0;}; static bool nonZero(Value a) { return a!=0;} ///@} static bool negative(Value) { return false; } ///Returns \c true if \c a is \e surely non-zero static bool nonZero(Value a) { return a!=0;}; static bool nonZero(Value a) { return a!=0;} ///@}
• ## test/dim_test.cc

 r8 using namespace std; using namespace lemon; int main() { cout << "Testing classes dim2::Point' and dim2::BoundingBox'." << endl; cout << "Testing classes 'dim2::Point' and 'dim2::BoundingBox'." << endl; typedef dim2::Point Point; Point seged; check(seged.size()==2, "Wrong vector addition"); Point p; check(p.size()==2, "Wrong vector initialization."); Point a(1,2); Point b(3,4); check(a[0]==1 && a[1]==2, "Wrong vector initialization."); check(a[0]==1 && a[1]==2, "Wrong vector addition"); p = a+b; check(p.x==4 && p.y==6, "Wrong vector addition."); seged = a+b; check(seged.x==4 && seged.y==6, "Wrong vector addition"); p = a-b; check(p.x==-2 && p.y==-2, "Wrong vector subtraction."); seged = a-b; check(seged.x==-2 && seged.y==-2, "a-b"); check(a.normSquare()==5,"Wrong norm calculation"); check(a*b==11, "a*b"); check(a.normSquare()==5,"Wrong vector norm calculation."); check(a*b==11, "Wrong vector scalar product."); int l=2; seged = a*l; check(seged.x==2 && seged.y==4, "a*l"); p = a*l; check(p.x==2 && p.y==4, "Wrong vector multiplication by a scalar."); seged = b/l; check(seged.x==1 && seged.y==2, "b/l"); p = b/l; check(p.x==1 && p.y==2, "Wrong vector division by a scalar."); typedef dim2::BoundingBox BB; BB doboz1; check(doboz1.empty(), "It should be empty."); doboz1.add(a); check(!doboz1.empty(), "It should not be empty."); doboz1.add(b); BB box1; check(box1.empty(), "It should be empty."); check(doboz1.bottomLeft().x==1 && doboz1.bottomLeft().y==2 && doboz1.topRight().x==3 && doboz1.topRight().y==4, "added points to box"); box1.add(a); check(!box1.empty(), "It should not be empty."); box1.add(b); seged.x=2;seged.y=3; check(doboz1.inside(seged),"It should be inside."); check(box1.bottomLeft().x==1 && box1.bottomLeft().y==2 && box1.topRight().x==3 && box1.topRight().y==4, "Wrong addition of points to box."); seged.x=1;seged.y=3; check(doboz1.inside(seged),"It should be inside."); p.x=2; p.y=3; check(box1.inside(p), "It should be inside."); seged.x=0;seged.y=3; check(!doboz1.inside(seged),"It should not be inside."); p.x=1; p.y=3; check(box1.inside(p), "It should be inside."); BB doboz2(seged); check(!doboz2.empty(), p.x=0; p.y=3; check(!box1.inside(p), "It should not be inside."); BB box2(p); check(!box2.empty(), "It should not be empty. Constructed from 1 point."); doboz2.add(doboz1); check(doboz2.inside(seged), box2.add(box1); check(box2.inside(p), "It should be inside. Incremented a box with another one."); return 0; }
Note: See TracChangeset for help on using the changeset viewer.