Skeleton for paths.
9 ///\brief A simple two dimensional vector and a bounding box implementation
11 /// The class \ref hugo::xy "xy" implements
12 ///a two dimensional vector with the usual
15 /// The class \ref hugo::BoundingBox "BoundingBox" can be used to determine
16 /// the rectangular bounding box a set of \ref hugo::xy "xy"'s.
18 ///\author Attila Bernath
26 /// A two dimensional vector (plainvector) implementation
28 /// A two dimensional vector (plainvector) implementation
29 ///with the usual vector
32 ///\author Attila Bernath
40 ///Default constructor: both coordinates become 0
43 ///Constructing the instance from coordinates
44 xy(T a, T b) : x(a), y(b) { }
47 ///Gives back the square of the norm of the vector
52 ///Increments the left hand side by u
53 xy<T>& operator +=(const xy<T>& u){
59 ///Decrements the left hand side by u
60 xy<T>& operator -=(const xy<T>& u){
66 ///Multiplying the left hand side with a scalar
67 xy<T>& operator *=(const T &u){
73 ///Dividing the left hand side by a scalar
74 xy<T>& operator /=(const T &u){
80 ///Returns the scalar product of two vectors
81 T operator *(const xy<T>& u){
85 ///Returns the sum of two vectors
86 xy<T> operator+(const xy<T> &u) const {
91 ///Returns the difference of two vectors
92 xy<T> operator-(const xy<T> &u) const {
97 ///Returns a vector multiplied by a scalar
98 xy<T> operator*(const T &u) const {
103 ///Returns a vector divided by a scalar
104 xy<T> operator/(const T &u) const {
110 bool operator==(const xy<T> &u){
111 return (x==u.x) && (y==u.y);
114 ///Testing inequality
115 bool operator!=(xy u){
116 return (x!=u.x) || (y!=u.y);
121 ///Reading a plainvector from a stream
124 std::istream& operator>>(std::istream &is, xy<T> &z)
131 ///Outputting a plainvector to a stream
134 std::ostream& operator<<(std::ostream &os, xy<T> z)
136 os << "(" << z.x << ", " << z.y << ")";
141 /// A class to calculate or store the bounding box of plainvectors.
143 /// A class to calculate or store the bounding box of plainvectors.
145 ///\author Attila Bernath
148 xy<T> bottom_left, top_right;
152 ///Default constructor: an empty bounding box
153 BoundingBox() { _empty = true; }
155 ///Constructing the instance from one point
156 BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
158 ///Is there any point added
163 ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined)
164 xy<T> bottomLeft() const {
168 ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined)
169 xy<T> topRight() const {
173 ///Checks whether a point is inside a bounding box
174 bool inside(const xy<T>& u){
178 return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
179 (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
183 ///Increments a bounding box with a point
184 BoundingBox& operator +=(const xy<T>& u){
186 bottom_left=top_right=u;
190 if (bottom_left.x > u.x) bottom_left.x = u.x;
191 if (bottom_left.y > u.y) bottom_left.y = u.y;
192 if (top_right.x < u.x) top_right.x = u.x;
193 if (top_right.y < u.y) top_right.y = u.y;
198 ///Sums a bounding box and a point
199 BoundingBox operator +(const xy<T>& u){
200 BoundingBox b = *this;
204 ///Increments a bounding box with an other bounding box
205 BoundingBox& operator +=(const BoundingBox &u){
207 *this += u.bottomLeft();
208 *this += u.topRight();
213 ///Sums two bounding boxes
214 BoundingBox operator +(const BoundingBox& u){
215 BoundingBox b = *this;
219 };//class Boundingbox