[Lemon-commits] kpeter: r3444 - lemon/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Tue Feb 5 12:23:24 CET 2008
Author: kpeter
Date: Tue Feb 5 12:23:23 2008
New Revision: 3444
Modified:
lemon/trunk/lemon/dim2.h
Log:
Improvements and fixes in dim2.h.
- Several doc improvements.
- Fix BoundingBox::operator& implementation.
Modified: lemon/trunk/lemon/dim2.h
==============================================================================
--- lemon/trunk/lemon/dim2.h (original)
+++ lemon/trunk/lemon/dim2.h Tue Feb 5 12:23:23 2008
@@ -52,9 +52,7 @@
/// A simple two dimensional vector (plainvector) implementation
/// A simple two dimensional vector (plainvector) implementation
- ///with the usual vector
- /// operators.
- ///
+ /// with the usual vector operations.
template<typename T>
class Point {
@@ -62,9 +60,9 @@
typedef T Value;
- ///First co-ordinate
+ ///First coordinate
T x;
- ///Second co-ordinate
+ ///Second coordinate
T y;
///Default constructor
@@ -75,7 +73,7 @@
///The dimension of the vector.
- ///This class give back always 2.
+ ///This function always returns 2.
///
int size() const { return 2; }
@@ -99,14 +97,14 @@
return x*x+y*y;
}
- ///Increment the left hand side by u
+ ///Increment the left hand side by \c u
Point<T>& operator +=(const Point<T>& u) {
x += u.x;
y += u.y;
return *this;
}
- ///Decrement the left hand side by u
+ ///Decrement the left hand side by \c u
Point<T>& operator -=(const Point<T>& u) {
x -= u.x;
y -= u.y;
@@ -138,7 +136,7 @@
return b+=u;
}
- ///Return the neg of the vectors
+ ///Return the negative of the vector
Point<T> operator-() const {
Point<T> b=*this;
b.x=-b.x; b.y=-b.y;
@@ -175,9 +173,9 @@
};
- ///Return an Point
+ ///Return a Point
- ///Return an Point
+ ///Return a Point.
///\relates Point
template <typename T>
inline Point<T> makePoint(const T& x, const T& y) {
@@ -286,9 +284,11 @@
///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<T> a,Point<T> b)
{
bottom_left=a;
@@ -298,9 +298,13 @@
///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)
{
bottom_left=Point<T>(l,b);
@@ -308,7 +312,13 @@
_empty = false;
}
- ///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;
}
@@ -318,67 +328,67 @@
_empty=1;
}
- ///Give back the bottom left corner
+ ///Give back the bottom left corner of the box
- ///Give back the bottom left corner.
+ ///Give back the bottom left corner of the box.
///If the bounding box is empty, then the return value is not defined.
Point<T> bottomLeft() const {
return bottom_left;
}
- ///Set the bottom left corner
+ ///Set the bottom left corner of the box
- ///Set the bottom left corner.
- ///It should only bee used for non-empty box.
+ ///Set the bottom left corner of the box.
+ ///It should only be used for non-empty box.
void bottomLeft(Point<T> p) {
bottom_left = p;
}
- ///Give back the top right corner
+ ///Give back the top right corner of the box
- ///Give back the top right corner.
+ ///Give back the top right corner of the box.
///If the bounding box is empty, then the return value is not defined.
Point<T> topRight() const {
return top_right;
}
- ///Set the top right corner
+ ///Set the top right corner of the box
- ///Set the top right corner.
- ///It should only bee used for non-empty box.
+ ///Set the top right corner of the box.
+ ///It should only be used for non-empty box.
void topRight(Point<T> p) {
top_right = p;
}
- ///Give back the bottom right corner
+ ///Give back the bottom right corner of the box
- ///Give back the bottom right corner.
+ ///Give back the bottom right corner of the box.
///If the bounding box is empty, then the return value is not defined.
Point<T> bottomRight() const {
return Point<T>(top_right.x,bottom_left.y);
}
- ///Set the bottom right corner
+ ///Set the bottom right corner of the box
- ///Set the bottom right corner.
- ///It should only bee used for non-empty box.
+ ///Set the bottom right corner of the box.
+ ///It should only be used for non-empty box.
void bottomRight(Point<T> p) {
top_right.x = p.x;
bottom_left.y = p.y;
}
- ///Give back the top left corner
+ ///Give back the top left corner of the box
- ///Give back the top left corner.
+ ///Give back the top left corner of the box.
///If the bounding box is empty, then the return value is not defined.
Point<T> topLeft() const {
return Point<T>(bottom_left.x,top_right.y);
}
- ///Set the top left corner
+ ///Set the top left corner of the box
- ///Set the top left corner.
- ///It should only bee used for non-empty box.
+ ///Set the top left corner of the box.
+ ///It should only be used for non-empty box.
void topLeft(Point<T> p) {
top_right.y = p.y;
bottom_left.x = p.x;
@@ -395,7 +405,7 @@
///Set the bottom of the box
///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;
}
@@ -411,7 +421,7 @@
///Set the top of the box
///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;
}
@@ -427,7 +437,7 @@
///Set the left side of the box
///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;
}
@@ -443,7 +453,7 @@
///Set the right side of the box
///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;
}
@@ -465,7 +475,7 @@
}
///Checks whether a point is inside a bounding box
- bool inside(const Point<T>& u){
+ bool inside(const Point<T>& u) const {
if (_empty)
return false;
else{
@@ -475,6 +485,9 @@
}
///Increments a bounding box with a point
+
+ ///Increments a bounding box with a point.
+ ///
BoundingBox& add(const Point<T>& u){
if (_empty){
bottom_left=top_right=u;
@@ -489,7 +502,10 @@
return *this;
}
- ///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() ){
this->add(u.bottomLeft());
@@ -499,24 +515,31 @@
}
///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;
}
};//class Boundingbox
- ///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 dim2::Point<>-map
+ ///Map of x-coordinates of a \ref Point "Point"-map.
///
template<class M>
class XMap
@@ -570,7 +593,7 @@
///Returns a \ref ConstXMap class
- ///This function just returns an \ref ConstXMap class.
+ ///This function just returns a \ref ConstXMap class.
///
///\ingroup maps
///\relates ConstXMap
@@ -580,10 +603,10 @@
return ConstXMap<M>(m);
}
- ///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<class M>
class YMap
@@ -599,9 +622,9 @@
void set(Key k,Value v) {_map.set(k,typename M::Value(_map[k].x,v));}
};
- ///Returns an \ref YMap class
+ ///Returns a \ref YMap class
- ///This function just returns an \ref YMap class.
+ ///This function just returns a \ref YMap class.
///
///\ingroup maps
///\relates YMap
@@ -637,7 +660,7 @@
///Returns a \ref ConstYMap class
- ///This function just returns an \ref ConstYMap class.
+ ///This function just returns a \ref ConstYMap class.
///
///\ingroup maps
///\relates ConstYMap
@@ -648,12 +671,12 @@
}
- ///\brief Map of the \ref Point::normSquare() "normSquare()"
- ///of an \ref Point "Point"-map
- ///
- ///Map of the \ref Point::normSquare() "normSquare()"
- ///of an \ref Point "Point"-map
- ///\ingroup maps
+ ///\brief Map of the \ref Point::normSquare() "normSquare()"
+ ///of a \ref Point "Point"-map
+ ///
+ ///Map of the \ref Point::normSquare() "normSquare()"
+ ///of a \ref Point "Point"-map.
+ ///\ingroup maps
///
template<class M>
class NormSquareMap
@@ -670,7 +693,7 @@
///Returns a \ref NormSquareMap class
- ///This function just returns an \ref NormSquareMap class.
+ ///This function just returns a \ref NormSquareMap class.
///
///\ingroup maps
///\relates NormSquareMap
More information about the Lemon-commits
mailing list