# HG changeset patch # User athos # Date 1080062927 0 # Node ID 4a1d2e642552d45fd438c0d9f8f487b39aa65d3d # Parent 3f76d1aa9d370a843193374fa540316be0d5949f Elk?sz?lt a boundingbox oszt?ly (boundingbox.h) ?s hozz? a tesztprogi. diff -r 3f76d1aa9d37 -r 4a1d2e642552 src/work/athos/xy/boundingbox.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/athos/xy/boundingbox.cc Tue Mar 23 17:28:47 2004 +0000 @@ -0,0 +1,61 @@ +#include + +#include +using namespace std; +using namespace hugo; +int main() +{ + xy z; + cout << "A teszt a következő: először beolvasunk 2 síkvektort, elkészítjük hozzá a határoló dobozt. Azután további síkvektorokat olvasunk be, amiket egy másik bounding boxhoz adogatunk hozzá. Mindig kiírjuk, hogy a megadott új pont benne volt e, majd hozzáadás után a doboz aktuális állapotát. Ezt a második beolvasást CTRL-D-vel lehet megszakítani: ezután a két dobozt összeadjuk." << endl; + + cout << "Kerek először 2 sikvektort (az első dobozhoz)." << endl; + BoundingBox doboz1; + cin >> z; + doboz1 += z; + cin >> z; + doboz1 += z; + cout << "Az első határoló doboz aktualisan: " << endl; + cout << "Bal alsó sarok: " << doboz1.bottomLeft() << endl; + cout << "Jobb felső sarok: " << doboz1.topRight() << endl; + + + + cout << "Kerek sok sikvektort." << endl; + + BoundingBox doboz; + + vector< xy > v; + + while(cin >> z) { + v.push_back(z); + if (doboz.inside(z)){ + cout << "Ez most belül van." << endl; + } + else{ + cout << "Ez most kívül van." << endl; + } + + doboz += z; + cout << "A második határoló doboz aktualisan: " << endl; + cout << "Bal alsó sarok: " << doboz.bottomLeft() << endl; + cout << "Jobb felső sarok: " << doboz.topRight() << endl; + } + + doboz += doboz1; + cout << "A két doboz összege: " << endl; + cout << "Bal alsó sarok: " << doboz.bottomLeft() << endl; + cout << "Jobb felső sarok: " << doboz.topRight() << endl; + + /* + cout << "A kovetkezo szamokat szoroztam ossze:" << endl; + for(unsigned int i=0; i1){ + cout << "Az elsö kettö szorzata: " << v[0]*v[1] << endl; + } + */ + cout << "Eleg nehez volt." << endl; +} diff -r 3f76d1aa9d37 -r 4a1d2e642552 src/work/athos/xy/boundingbox.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/athos/xy/boundingbox.h Tue Mar 23 17:28:47 2004 +0000 @@ -0,0 +1,92 @@ +// -*- c++ -*- +/** +Implementation of a bounding box of plainvectors. + +*/ +#ifndef HUGO_BOUNDINGBOX_H +#define HUGO_BOUNDINGBOX_H + + +#include + +namespace hugo { + + template + class BoundingBox { + xy bottomleft, topright; + bool _empty; + public: + + ///Default constructor: an empty bounding box + BoundingBox() { _empty = true; } + + ///Constructing the instance from one point + BoundingBox(xy a) { bottomleft=topright=a; _empty = false; } + + ///Is there any point added + bool empty() const { + return _empty; + } + + ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined) + xy bottomLeft() const { + return bottomleft; + }; + + ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined) + xy topRight() const { + return topright; + }; + + ///Checks whether a point is inside a bounding box + bool inside(const xy& u){ + if (_empty) + return false; + else{ + return ((u.x-bottomleft.x)*(topright.x-u.x) >= 0 && + (u.y-bottomleft.y)*(topright.y-u.y) >= 0 ); + } + } + + ///Increments a bounding box with a point + BoundingBox& operator +=(const xy& u){ + if (_empty){ + bottomleft=topright=u; + _empty = false; + } + else{ + if (bottomleft.x > u.x) bottomleft.x = u.x; + if (bottomleft.y > u.y) bottomleft.y = u.y; + if (topright.x < u.x) topright.x = u.x; + if (topright.y < u.y) topright.y = u.y; + } + return *this; + }; + + ///Sums a bounding box and a point + BoundingBox operator +(const xy& u){ + BoundingBox b = *this; + return b += u; + }; + + ///Increments a bounding box with an other bounding box + BoundingBox& operator +=(const BoundingBox &u){ + if ( !u.empty() ){ + *this += u.bottomLeft(); + *this += u.topRight(); + } + return *this; + }; + + ///Sums two bounding boxes + BoundingBox operator +(const BoundingBox& u){ + BoundingBox b = *this; + return b += u; + }; + + };//class BoundingBox + + +} //namespace hugo + +#endif //HUGO_BOUNDINGBOX_H diff -r 3f76d1aa9d37 -r 4a1d2e642552 src/work/athos/xy/xy.cc --- a/src/work/athos/xy/xy.cc Tue Mar 23 13:47:31 2004 +0000 +++ b/src/work/athos/xy/xy.cc Tue Mar 23 17:28:47 2004 +0000 @@ -5,7 +5,7 @@ int main() { - cout << "Még egy skalárt is kérek (szépen)!" << endl; + cout << "Kérek szépen egy egész számot!" << endl; int s; cin >> s; diff -r 3f76d1aa9d37 -r 4a1d2e642552 src/work/athos/xy/xy.h --- a/src/work/athos/xy/xy.h Tue Mar 23 13:47:31 2004 +0000 +++ b/src/work/athos/xy/xy.h Tue Mar 23 17:28:47 2004 +0000 @@ -12,62 +12,54 @@ template class xy { - T _x,_y; public: + + T x,y; ///Default constructor: both coordinates become 0 - xy() : _x(0), _y(0 ){ /*_x=_y=0;*/ } + xy() : x(0), y(0) {} - ///Constructing from coordinates - xy(T a, T b) : _x(a), _x(b) { /*_x=a; _y=b;*/ } + ///Constructing the instance from coordinates + xy(T a, T b) : x(a), y(a) { } - ///Gives back the x coordinate - T x(){ - return _x; - }; - - ///Gives back the y coordinate - T y(){ - return _y; - }; ///Gives back the square of the norm of the vector T normSquare(){ - return _x*_x+_y*_y; + return x*x+y*y; }; ///Increments the left hand side by u xy& operator +=(const xy& u){ - _x += u._x; - _y += u._y; + x += u.x; + y += u.y; return *this; }; ///Decrements the left hand side by u xy& operator -=(const xy& u){ - _x -= u._x; - _y -= u._y; + x -= u.x; + y -= u.y; return *this; }; ///Multiplying the left hand side with a scalar xy& operator *=(const T &u){ - _x *= u; - _y *= u; + x *= u; + y *= u; return *this; }; ///Dividing the left hand side by a scalar xy& operator /=(const T &u){ - _x /= u; - _y /= u; + x /= u; + y /= u; return *this; }; ///Returns the scalar product of two vectors T operator *(const xy& u){ - return _x*u._x+_y*u._y; + return x*u.x+y*u.y; }; ///Returns the sum of two vectors @@ -96,12 +88,12 @@ ///Testing equality bool operator==(const xy &u){ - return (_x==u._x) && (_y==u._y); + return (x==u.x) && (y==u.y); }; ///Testing inequality bool operator!=(xy u){ - return (_x!=u._x) || (_y!=u._y); + return (x!=u.x) || (y!=u.y); }; }; @@ -111,11 +103,8 @@ inline std::istream& operator>>(std::istream &is, xy &z) { - ///This is not the best solution here: I didn't know how to solve this with friend functions - T a,b; - is >> a >> b; - xy buf(a,b); - z=buf; + + is >> z.x >> z.y; return is; } @@ -124,7 +113,7 @@ inline std::ostream& operator<<(std::ostream &os, xy z) { - os << "(" << z.x() << ", " << z.y() << ")"; + os << "(" << z.x << ", " << z.y << ")"; return os; }