Naming and coding style fixes and various other changes.
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
55 ///Default constructor: both coordinates become 0
58 ///Constructing the instance from coordinates
59 xy(T a, T b) : x(a), y(b) { }
62 ///Gives back the square of the norm of the vector
67 ///Increments the left hand side by u
68 xy<T>& operator +=(const xy<T>& u){
74 ///Decrements the left hand side by u
75 xy<T>& operator -=(const xy<T>& u){
81 ///Multiplying the left hand side with a scalar
82 xy<T>& operator *=(const T &u){
88 ///Dividing the left hand side by a scalar
89 xy<T>& operator /=(const T &u){
95 ///Returns the scalar product of two vectors
96 T operator *(const xy<T>& u){
100 ///Returns the sum of two vectors
101 xy<T> operator+(const xy<T> &u) const {
106 ///Returns the difference of two vectors
107 xy<T> operator-(const xy<T> &u) const {
112 ///Returns a vector multiplied by a scalar
113 xy<T> operator*(const T &u) const {
118 ///Returns a vector divided by a scalar
119 xy<T> operator/(const T &u) const {
125 bool operator==(const xy<T> &u){
126 return (x==u.x) && (y==u.y);
129 ///Testing inequality
130 bool operator!=(xy u){
131 return (x!=u.x) || (y!=u.y);
136 ///Read a plainvector from a stream
142 std::istream& operator>>(std::istream &is, xy<T> &z)
149 ///Write a plainvector to a stream
155 std::ostream& operator<<(std::ostream &os, xy<T> z)
157 os << "(" << z.x << ", " << z.y << ")";
162 /// A class to calculate or store the bounding box of plainvectors.
164 /// A class to calculate or store the bounding box of plainvectors.
166 ///\author Attila Bernath
169 xy<T> bottom_left, top_right;
173 ///Default constructor: an empty bounding box
174 BoundingBox() { _empty = true; }
176 ///Constructing the instance from one point
177 BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
179 ///Is there any point added
184 ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined)
185 xy<T> bottomLeft() const {
189 ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined)
190 xy<T> topRight() const {
194 ///Checks whether a point is inside a bounding box
195 bool inside(const xy<T>& u){
199 return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
200 (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
204 ///Increments a bounding box with a point
205 BoundingBox& operator +=(const xy<T>& u){
207 bottom_left=top_right=u;
211 if (bottom_left.x > u.x) bottom_left.x = u.x;
212 if (bottom_left.y > u.y) bottom_left.y = u.y;
213 if (top_right.x < u.x) top_right.x = u.x;
214 if (top_right.y < u.y) top_right.y = u.y;
219 ///Sums a bounding box and a point
220 BoundingBox operator +(const xy<T>& u){
221 BoundingBox b = *this;
225 ///Increments a bounding box with an other bounding box
226 BoundingBox& operator +=(const BoundingBox &u){
228 *this += u.bottomLeft();
229 *this += u.topRight();
234 ///Sums two bounding boxes
235 BoundingBox operator +(const BoundingBox& u){
236 BoundingBox b = *this;
240 };//class Boundingbox