Elk?sz?lt a boundingbox oszt?ly (boundingbox.h) ?s hozz? a tesztprogi.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/athos/xy/boundingbox.cc Tue Mar 23 17:28:47 2004 +0000
1.3 @@ -0,0 +1,61 @@
1.4 +#include <boundingbox.h>
1.5 +
1.6 +#include <iostream>
1.7 +using namespace std;
1.8 +using namespace hugo;
1.9 +int main()
1.10 +{
1.11 + xy<int> z;
1.12 + 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;
1.13 +
1.14 + cout << "Kerek először 2 sikvektort (az első dobozhoz)." << endl;
1.15 + BoundingBox<int> doboz1;
1.16 + cin >> z;
1.17 + doboz1 += z;
1.18 + cin >> z;
1.19 + doboz1 += z;
1.20 + cout << "Az első határoló doboz aktualisan: " << endl;
1.21 + cout << "Bal alsó sarok: " << doboz1.bottomLeft() << endl;
1.22 + cout << "Jobb felső sarok: " << doboz1.topRight() << endl;
1.23 +
1.24 +
1.25 +
1.26 + cout << "Kerek sok sikvektort." << endl;
1.27 +
1.28 + BoundingBox<int> doboz;
1.29 +
1.30 + vector< xy<int> > v;
1.31 +
1.32 + while(cin >> z) {
1.33 + v.push_back(z);
1.34 + if (doboz.inside(z)){
1.35 + cout << "Ez most belül van." << endl;
1.36 + }
1.37 + else{
1.38 + cout << "Ez most kívül van." << endl;
1.39 + }
1.40 +
1.41 + doboz += z;
1.42 + cout << "A második határoló doboz aktualisan: " << endl;
1.43 + cout << "Bal alsó sarok: " << doboz.bottomLeft() << endl;
1.44 + cout << "Jobb felső sarok: " << doboz.topRight() << endl;
1.45 + }
1.46 +
1.47 + doboz += doboz1;
1.48 + cout << "A két doboz összege: " << endl;
1.49 + cout << "Bal alsó sarok: " << doboz.bottomLeft() << endl;
1.50 + cout << "Jobb felső sarok: " << doboz.topRight() << endl;
1.51 +
1.52 + /*
1.53 + cout << "A kovetkezo szamokat szoroztam ossze:" << endl;
1.54 + for(unsigned int i=0; i<v.size(); ++i) {
1.55 + cout << v[i] << ", A normanégyzete: " << v[i].normSquare() <<endl;
1.56 + cout << v[i] << " " << s << " szorosa " << v[i]*s <<endl;
1.57 + cout << v[i] << " " << s << " edrésze " << v[i]/s <<endl;
1.58 + }
1.59 + if (v.size()>1){
1.60 + cout << "Az elsö kettö szorzata: " << v[0]*v[1] << endl;
1.61 + }
1.62 + */
1.63 + cout << "Eleg nehez volt." << endl;
1.64 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/work/athos/xy/boundingbox.h Tue Mar 23 17:28:47 2004 +0000
2.3 @@ -0,0 +1,92 @@
2.4 +// -*- c++ -*-
2.5 +/**
2.6 +Implementation of a bounding box of plainvectors.
2.7 +
2.8 +*/
2.9 +#ifndef HUGO_BOUNDINGBOX_H
2.10 +#define HUGO_BOUNDINGBOX_H
2.11 +
2.12 +
2.13 +#include <xy.h>
2.14 +
2.15 +namespace hugo {
2.16 +
2.17 + template<typename T>
2.18 + class BoundingBox {
2.19 + xy<T> bottomleft, topright;
2.20 + bool _empty;
2.21 + public:
2.22 +
2.23 + ///Default constructor: an empty bounding box
2.24 + BoundingBox() { _empty = true; }
2.25 +
2.26 + ///Constructing the instance from one point
2.27 + BoundingBox(xy<T> a) { bottomleft=topright=a; _empty = false; }
2.28 +
2.29 + ///Is there any point added
2.30 + bool empty() const {
2.31 + return _empty;
2.32 + }
2.33 +
2.34 + ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined)
2.35 + xy<T> bottomLeft() const {
2.36 + return bottomleft;
2.37 + };
2.38 +
2.39 + ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined)
2.40 + xy<T> topRight() const {
2.41 + return topright;
2.42 + };
2.43 +
2.44 + ///Checks whether a point is inside a bounding box
2.45 + bool inside(const xy<T>& u){
2.46 + if (_empty)
2.47 + return false;
2.48 + else{
2.49 + return ((u.x-bottomleft.x)*(topright.x-u.x) >= 0 &&
2.50 + (u.y-bottomleft.y)*(topright.y-u.y) >= 0 );
2.51 + }
2.52 + }
2.53 +
2.54 + ///Increments a bounding box with a point
2.55 + BoundingBox& operator +=(const xy<T>& u){
2.56 + if (_empty){
2.57 + bottomleft=topright=u;
2.58 + _empty = false;
2.59 + }
2.60 + else{
2.61 + if (bottomleft.x > u.x) bottomleft.x = u.x;
2.62 + if (bottomleft.y > u.y) bottomleft.y = u.y;
2.63 + if (topright.x < u.x) topright.x = u.x;
2.64 + if (topright.y < u.y) topright.y = u.y;
2.65 + }
2.66 + return *this;
2.67 + };
2.68 +
2.69 + ///Sums a bounding box and a point
2.70 + BoundingBox operator +(const xy<T>& u){
2.71 + BoundingBox b = *this;
2.72 + return b += u;
2.73 + };
2.74 +
2.75 + ///Increments a bounding box with an other bounding box
2.76 + BoundingBox& operator +=(const BoundingBox &u){
2.77 + if ( !u.empty() ){
2.78 + *this += u.bottomLeft();
2.79 + *this += u.topRight();
2.80 + }
2.81 + return *this;
2.82 + };
2.83 +
2.84 + ///Sums two bounding boxes
2.85 + BoundingBox operator +(const BoundingBox& u){
2.86 + BoundingBox b = *this;
2.87 + return b += u;
2.88 + };
2.89 +
2.90 + };//class BoundingBox
2.91 +
2.92 +
2.93 +} //namespace hugo
2.94 +
2.95 +#endif //HUGO_BOUNDINGBOX_H
3.1 --- a/src/work/athos/xy/xy.cc Tue Mar 23 13:47:31 2004 +0000
3.2 +++ b/src/work/athos/xy/xy.cc Tue Mar 23 17:28:47 2004 +0000
3.3 @@ -5,7 +5,7 @@
3.4 int main()
3.5 {
3.6
3.7 - cout << "Még egy skalárt is kérek (szépen)!" << endl;
3.8 + cout << "Kérek szépen egy egész számot!" << endl;
3.9 int s;
3.10 cin >> s;
3.11
4.1 --- a/src/work/athos/xy/xy.h Tue Mar 23 13:47:31 2004 +0000
4.2 +++ b/src/work/athos/xy/xy.h Tue Mar 23 17:28:47 2004 +0000
4.3 @@ -12,62 +12,54 @@
4.4
4.5 template<typename T>
4.6 class xy {
4.7 - T _x,_y;
4.8
4.9 public:
4.10 +
4.11 + T x,y;
4.12
4.13 ///Default constructor: both coordinates become 0
4.14 - xy() : _x(0), _y(0 ){ /*_x=_y=0;*/ }
4.15 + xy() : x(0), y(0) {}
4.16
4.17 - ///Constructing from coordinates
4.18 - xy(T a, T b) : _x(a), _x(b) { /*_x=a; _y=b;*/ }
4.19 + ///Constructing the instance from coordinates
4.20 + xy(T a, T b) : x(a), y(a) { }
4.21
4.22 - ///Gives back the x coordinate
4.23 - T x(){
4.24 - return _x;
4.25 - };
4.26 -
4.27 - ///Gives back the y coordinate
4.28 - T y(){
4.29 - return _y;
4.30 - };
4.31
4.32 ///Gives back the square of the norm of the vector
4.33 T normSquare(){
4.34 - return _x*_x+_y*_y;
4.35 + return x*x+y*y;
4.36 };
4.37
4.38 ///Increments the left hand side by u
4.39 xy<T>& operator +=(const xy<T>& u){
4.40 - _x += u._x;
4.41 - _y += u._y;
4.42 + x += u.x;
4.43 + y += u.y;
4.44 return *this;
4.45 };
4.46
4.47 ///Decrements the left hand side by u
4.48 xy<T>& operator -=(const xy<T>& u){
4.49 - _x -= u._x;
4.50 - _y -= u._y;
4.51 + x -= u.x;
4.52 + y -= u.y;
4.53 return *this;
4.54 };
4.55
4.56 ///Multiplying the left hand side with a scalar
4.57 xy<T>& operator *=(const T &u){
4.58 - _x *= u;
4.59 - _y *= u;
4.60 + x *= u;
4.61 + y *= u;
4.62 return *this;
4.63 };
4.64
4.65 ///Dividing the left hand side by a scalar
4.66 xy<T>& operator /=(const T &u){
4.67 - _x /= u;
4.68 - _y /= u;
4.69 + x /= u;
4.70 + y /= u;
4.71 return *this;
4.72 };
4.73
4.74 ///Returns the scalar product of two vectors
4.75 T operator *(const xy<T>& u){
4.76 - return _x*u._x+_y*u._y;
4.77 + return x*u.x+y*u.y;
4.78 };
4.79
4.80 ///Returns the sum of two vectors
4.81 @@ -96,12 +88,12 @@
4.82
4.83 ///Testing equality
4.84 bool operator==(const xy<T> &u){
4.85 - return (_x==u._x) && (_y==u._y);
4.86 + return (x==u.x) && (y==u.y);
4.87 };
4.88
4.89 ///Testing inequality
4.90 bool operator!=(xy u){
4.91 - return (_x!=u._x) || (_y!=u._y);
4.92 + return (x!=u.x) || (y!=u.y);
4.93 };
4.94
4.95 };
4.96 @@ -111,11 +103,8 @@
4.97 inline
4.98 std::istream& operator>>(std::istream &is, xy<T> &z)
4.99 {
4.100 - ///This is not the best solution here: I didn't know how to solve this with friend functions
4.101 - T a,b;
4.102 - is >> a >> b;
4.103 - xy<T> buf(a,b);
4.104 - z=buf;
4.105 +
4.106 + is >> z.x >> z.y;
4.107 return is;
4.108 }
4.109
4.110 @@ -124,7 +113,7 @@
4.111 inline
4.112 std::ostream& operator<<(std::ostream &os, xy<T> z)
4.113 {
4.114 - os << "(" << z.x() << ", " << z.y() << ")";
4.115 + os << "(" << z.x << ", " << z.y << ")";
4.116 return os;
4.117 }
4.118