1.1 --- a/lemon/dim2.h Thu Sep 07 14:16:47 2006 +0000
1.2 +++ b/lemon/dim2.h Fri Sep 08 08:55:07 2006 +0000
1.3 @@ -73,6 +73,14 @@
1.4 ///Construct an instance from coordinates
1.5 Point(T a, T b) : x(a), y(b) { }
1.6
1.7 + ///Size of vector
1.8 + int size() const { return 2; }
1.9 +
1.10 + ///Subscripting operator
1.11 + T& operator[](int idx) { return idx == 0 ? x : y; }
1.12 +
1.13 + ///Const subscripting operator
1.14 + const T& operator[](int idx) const { return idx == 0 ? x : y; }
1.15
1.16 ///Conversion constructor
1.17 template<class TT> Point(const Point<TT> &p) : x(p.x), y(p.y) {}
1.18 @@ -163,7 +171,7 @@
1.19 ///Return an Point
1.20 ///\relates Point
1.21 template <typename T>
1.22 - inline Point<T> make_Point(const T& x, const T& y) {
1.23 + inline Point<T> makePoint(const T& x, const T& y) {
1.24 return Point<T>(x, y);
1.25 }
1.26
2.1 --- a/test/dim_test.cc Thu Sep 07 14:16:47 2006 +0000
2.2 +++ b/test/dim_test.cc Fri Sep 08 08:55:07 2006 +0000
2.3 @@ -29,54 +29,58 @@
2.4
2.5 typedef dim2::Point<int> Point;
2.6
2.7 - Point seged;
2.8 - Point a(1,2);
2.9 - Point b(3,4);
2.10 + Point seged;
2.11 + check(seged.size()==2, "Wrong vector addition");
2.12
2.13 - seged = a+b;
2.14 - check(seged.x==4 && seged.y==6, "Wrong vector addition");
2.15 + Point a(1,2);
2.16 + Point b(3,4);
2.17
2.18 - seged = a-b;
2.19 - check(seged.x==-2 && seged.y==-2, "a-b");
2.20 + check(a[0]==1 && a[1]==2, "Wrong vector addition");
2.21
2.22 - check(a.normSquare()==5,"Wrong norm calculation");
2.23 - check(a*b==11, "a*b");
2.24 + seged = a+b;
2.25 + check(seged.x==4 && seged.y==6, "Wrong vector addition");
2.26
2.27 - int l=2;
2.28 - seged = a*l;
2.29 - check(seged.x==2 && seged.y==4, "a*l");
2.30 + seged = a-b;
2.31 + check(seged.x==-2 && seged.y==-2, "a-b");
2.32
2.33 - seged = b/l;
2.34 - check(seged.x==1 && seged.y==2, "b/l");
2.35 + check(a.normSquare()==5,"Wrong norm calculation");
2.36 + check(a*b==11, "a*b");
2.37
2.38 - typedef dim2::BoundingBox<int> BB;
2.39 - BB doboz1;
2.40 - check(doboz1.empty(), "It should be empty.");
2.41 + int l=2;
2.42 + seged = a*l;
2.43 + check(seged.x==2 && seged.y==4, "a*l");
2.44 +
2.45 + seged = b/l;
2.46 + check(seged.x==1 && seged.y==2, "b/l");
2.47 +
2.48 + typedef dim2::BoundingBox<int> BB;
2.49 + BB doboz1;
2.50 + check(doboz1.empty(), "It should be empty.");
2.51
2.52 - doboz1.add(a);
2.53 - check(!doboz1.empty(), "It should not be empty.");
2.54 - doboz1.add(b);
2.55 + doboz1.add(a);
2.56 + check(!doboz1.empty(), "It should not be empty.");
2.57 + doboz1.add(b);
2.58
2.59 - check(doboz1.bottomLeft().x==1 &&
2.60 - doboz1.bottomLeft().y==2 &&
2.61 - doboz1.topRight().x==3 &&
2.62 - doboz1.topRight().y==4,
2.63 - "added points to box");
2.64 + check(doboz1.bottomLeft().x==1 &&
2.65 + doboz1.bottomLeft().y==2 &&
2.66 + doboz1.topRight().x==3 &&
2.67 + doboz1.topRight().y==4,
2.68 + "added points to box");
2.69
2.70 - seged.x=2;seged.y=3;
2.71 - check(doboz1.inside(seged),"It should be inside.");
2.72 + seged.x=2;seged.y=3;
2.73 + check(doboz1.inside(seged),"It should be inside.");
2.74
2.75 - seged.x=1;seged.y=3;
2.76 - check(doboz1.inside(seged),"It should be inside.");
2.77 + seged.x=1;seged.y=3;
2.78 + check(doboz1.inside(seged),"It should be inside.");
2.79
2.80 - seged.x=0;seged.y=3;
2.81 - check(!doboz1.inside(seged),"It should not be inside.");
2.82 + seged.x=0;seged.y=3;
2.83 + check(!doboz1.inside(seged),"It should not be inside.");
2.84
2.85 - BB doboz2(seged);
2.86 - check(!doboz2.empty(),
2.87 - "It should not be empty. Constructed from 1 point.");
2.88 + BB doboz2(seged);
2.89 + check(!doboz2.empty(),
2.90 + "It should not be empty. Constructed from 1 point.");
2.91
2.92 - doboz2.add(doboz1);
2.93 - check(doboz2.inside(seged),
2.94 - "It should be inside. Incremented a box with another one.");
2.95 + doboz2.add(doboz1);
2.96 + check(doboz2.inside(seged),
2.97 + "It should be inside. Incremented a box with another one.");
2.98 }