10 2 dimensional vector (plainvector) implementation
20 ///Default constructor: both coordinates become 0
23 ///Constructing the instance from coordinates
24 xy(T a, T b) : x(a), y(a) { }
27 ///Gives back the square of the norm of the vector
32 ///Increments the left hand side by u
33 xy<T>& operator +=(const xy<T>& u){
39 ///Decrements the left hand side by u
40 xy<T>& operator -=(const xy<T>& u){
46 ///Multiplying the left hand side with a scalar
47 xy<T>& operator *=(const T &u){
53 ///Dividing the left hand side by a scalar
54 xy<T>& operator /=(const T &u){
60 ///Returns the scalar product of two vectors
61 T operator *(const xy<T>& u){
65 ///Returns the sum of two vectors
66 xy<T> operator+(const xy<T> &u) const {
71 ///Returns the difference of two vectors
72 xy<T> operator-(const xy<T> &u) const {
77 ///Returns a vector multiplied by a scalar
78 xy<T> operator*(const T &u) const {
83 ///Returns a vector divided by a scalar
84 xy<T> operator/(const T &u) const {
90 bool operator==(const xy<T> &u){
91 return (x==u.x) && (y==u.y);
95 bool operator!=(xy u){
96 return (x!=u.x) || (y!=u.y);
101 ///Reading a plainvector from a stream
104 std::istream& operator>>(std::istream &is, xy<T> &z)
111 ///Outputting a plainvector to a stream
114 std::ostream& operator<<(std::ostream &os, xy<T> z)
116 os << "(" << z.x << ", " << z.y << ")";
122 Implementation of a bounding box of plainvectors.
127 xy<T> bottom_left, top_right;
131 ///Default constructor: an empty bounding box
132 BoundingBox() { _empty = true; }
134 ///Constructing the instance from one point
135 BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
137 ///Is there any point added
142 ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined)
143 xy<T> bottomLeft() const {
147 ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined)
148 xy<T> topRight() const {
152 ///Checks whether a point is inside a bounding box
153 bool inside(const xy<T>& u){
157 return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
158 (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
162 ///Increments a bounding box with a point
163 BoundingBox& operator +=(const xy<T>& u){
165 bottom_left=top_right=u;
169 if (bottom_left.x > u.x) bottom_left.x = u.x;
170 if (bottom_left.y > u.y) bottom_left.y = u.y;
171 if (top_right.x < u.x) top_right.x = u.x;
172 if (top_right.y < u.y) top_right.y = u.y;
177 ///Sums a bounding box and a point
178 BoundingBox operator +(const xy<T>& u){
179 BoundingBox b = *this;
183 ///Increments a bounding box with an other bounding box
184 BoundingBox& operator +=(const BoundingBox &u){
186 *this += u.bottomLeft();
187 *this += u.topRight();
192 ///Sums two bounding boxes
193 BoundingBox operator +(const BoundingBox& u){
194 BoundingBox b = *this;
198 };//class Boundingbox