- Move template.h to doc/.
- Insert the license terms into the documentation.
- template.h now appears under the coding style documentation.
2 * src/lemon/xy.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
24 ///\brief A simple two dimensional vector and a bounding box implementation
26 /// The class \ref lemon::xy "xy" implements
27 ///a two dimensional vector with the usual
30 /// The class \ref lemon::BoundingBox "BoundingBox" can be used to determine
31 /// the rectangular bounding box a set of \ref lemon::xy "xy"'s.
33 ///\author Attila Bernath
41 /// A two dimensional vector (plainvector) implementation
43 /// A two dimensional vector (plainvector) implementation
44 ///with the usual vector
47 ///\author Attila Bernath
57 ///Default constructor: both coordinates become 0
60 ///Constructing the instance from coordinates
61 xy(T a, T b) : x(a), y(b) { }
64 ///Gives back the square of the norm of the vector
69 ///Increments the left hand side by u
70 xy<T>& operator +=(const xy<T>& u){
76 ///Decrements the left hand side by u
77 xy<T>& operator -=(const xy<T>& u){
83 ///Multiplying the left hand side with a scalar
84 xy<T>& operator *=(const T &u){
90 ///Dividing the left hand side by a scalar
91 xy<T>& operator /=(const T &u){
97 ///Returns the scalar product of two vectors
98 T operator *(const xy<T>& u){
102 ///Returns the sum of two vectors
103 xy<T> operator+(const xy<T> &u) const {
108 ///Returns the difference of two vectors
109 xy<T> operator-(const xy<T> &u) const {
114 ///Returns a vector multiplied by a scalar
115 xy<T> operator*(const T &u) const {
120 ///Returns a vector divided by a scalar
121 xy<T> operator/(const T &u) const {
127 bool operator==(const xy<T> &u){
128 return (x==u.x) && (y==u.y);
131 ///Testing inequality
132 bool operator!=(xy u){
133 return (x!=u.x) || (y!=u.y);
138 ///Read a plainvector from a stream
140 ///Read a plainvector from a stream
145 std::istream& operator>>(std::istream &is, xy<T> &z)
152 ///Write a plainvector to a stream
154 ///Write a plainvector to a stream
159 std::ostream& operator<<(std::ostream &os, xy<T> z)
161 os << "(" << z.x << ", " << z.y << ")";
166 /// A class to calculate or store the bounding box of plainvectors.
168 /// A class to calculate or store the bounding box of plainvectors.
170 ///\author Attila Bernath
173 xy<T> bottom_left, top_right;
177 ///Default constructor: an empty bounding box
178 BoundingBox() { _empty = true; }
180 ///Constructing the instance from one point
181 BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
183 ///Is there any point added
188 ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined)
189 xy<T> bottomLeft() const {
193 ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined)
194 xy<T> topRight() const {
198 ///Checks whether a point is inside a bounding box
199 bool inside(const xy<T>& u){
203 return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
204 (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
208 ///Increments a bounding box with a point
209 BoundingBox& operator +=(const xy<T>& u){
211 bottom_left=top_right=u;
215 if (bottom_left.x > u.x) bottom_left.x = u.x;
216 if (bottom_left.y > u.y) bottom_left.y = u.y;
217 if (top_right.x < u.x) top_right.x = u.x;
218 if (top_right.y < u.y) top_right.y = u.y;
223 ///Sums a bounding box and a point
224 BoundingBox operator +(const xy<T>& u){
225 BoundingBox b = *this;
229 ///Increments a bounding box with an other bounding box
230 BoundingBox& operator +=(const BoundingBox &u){
232 *this += u.bottomLeft();
233 *this += u.topRight();
238 ///Sums two bounding boxes
239 BoundingBox operator +(const BoundingBox& u){
240 BoundingBox b = *this;
244 };//class Boundingbox