[Lemon-commits] [lemon_svn] deba: r2940 - in hugo/trunk: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 21:51:22 CET 2006
Author: deba
Date: Fri Sep 8 10:55:07 2006
New Revision: 2940
Modified:
hugo/trunk/lemon/dim2.h
hugo/trunk/test/dim_test.cc
Log:
Some small improvments
size() and subscription operators
compatibility with higher dimensions
Modified: hugo/trunk/lemon/dim2.h
==============================================================================
--- hugo/trunk/lemon/dim2.h (original)
+++ hugo/trunk/lemon/dim2.h Fri Sep 8 10:55:07 2006
@@ -73,6 +73,14 @@
///Construct an instance from coordinates
Point(T a, T b) : x(a), y(b) { }
+ ///Size of vector
+ int size() const { return 2; }
+
+ ///Subscripting operator
+ T& operator[](int idx) { return idx == 0 ? x : y; }
+
+ ///Const subscripting operator
+ const T& operator[](int idx) const { return idx == 0 ? x : y; }
///Conversion constructor
template<class TT> Point(const Point<TT> &p) : x(p.x), y(p.y) {}
@@ -163,7 +171,7 @@
///Return an Point
///\relates Point
template <typename T>
- inline Point<T> make_Point(const T& x, const T& y) {
+ inline Point<T> makePoint(const T& x, const T& y) {
return Point<T>(x, y);
}
Modified: hugo/trunk/test/dim_test.cc
==============================================================================
--- hugo/trunk/test/dim_test.cc (original)
+++ hugo/trunk/test/dim_test.cc Fri Sep 8 10:55:07 2006
@@ -29,54 +29,58 @@
typedef dim2::Point<int> Point;
- Point seged;
- Point a(1,2);
- Point b(3,4);
+ Point seged;
+ check(seged.size()==2, "Wrong vector addition");
- seged = a+b;
- check(seged.x==4 && seged.y==6, "Wrong vector addition");
+ Point a(1,2);
+ Point b(3,4);
- seged = a-b;
- check(seged.x==-2 && seged.y==-2, "a-b");
+ check(a[0]==1 && a[1]==2, "Wrong vector addition");
- check(a.normSquare()==5,"Wrong norm calculation");
- check(a*b==11, "a*b");
+ seged = a+b;
+ check(seged.x==4 && seged.y==6, "Wrong vector addition");
- int l=2;
- seged = a*l;
- check(seged.x==2 && seged.y==4, "a*l");
+ seged = a-b;
+ check(seged.x==-2 && seged.y==-2, "a-b");
- seged = b/l;
- check(seged.x==1 && seged.y==2, "b/l");
+ check(a.normSquare()==5,"Wrong norm calculation");
+ check(a*b==11, "a*b");
- typedef dim2::BoundingBox<int> BB;
- BB doboz1;
- check(doboz1.empty(), "It should be empty.");
+ int l=2;
+ seged = a*l;
+ check(seged.x==2 && seged.y==4, "a*l");
+
+ seged = b/l;
+ check(seged.x==1 && seged.y==2, "b/l");
+
+ typedef dim2::BoundingBox<int> BB;
+ BB doboz1;
+ check(doboz1.empty(), "It should be empty.");
- doboz1.add(a);
- check(!doboz1.empty(), "It should not be empty.");
- doboz1.add(b);
-
- check(doboz1.bottomLeft().x==1 &&
- doboz1.bottomLeft().y==2 &&
- doboz1.topRight().x==3 &&
- doboz1.topRight().y==4,
- "added points to box");
-
- seged.x=2;seged.y=3;
- check(doboz1.inside(seged),"It should be inside.");
-
- seged.x=1;seged.y=3;
- check(doboz1.inside(seged),"It should be inside.");
-
- seged.x=0;seged.y=3;
- check(!doboz1.inside(seged),"It should not be inside.");
-
- BB doboz2(seged);
- check(!doboz2.empty(),
- "It should not be empty. Constructed from 1 point.");
-
- doboz2.add(doboz1);
- check(doboz2.inside(seged),
- "It should be inside. Incremented a box with another one.");
+ doboz1.add(a);
+ check(!doboz1.empty(), "It should not be empty.");
+ doboz1.add(b);
+
+ check(doboz1.bottomLeft().x==1 &&
+ doboz1.bottomLeft().y==2 &&
+ doboz1.topRight().x==3 &&
+ doboz1.topRight().y==4,
+ "added points to box");
+
+ seged.x=2;seged.y=3;
+ check(doboz1.inside(seged),"It should be inside.");
+
+ seged.x=1;seged.y=3;
+ check(doboz1.inside(seged),"It should be inside.");
+
+ seged.x=0;seged.y=3;
+ check(!doboz1.inside(seged),"It should not be inside.");
+
+ BB doboz2(seged);
+ check(!doboz2.empty(),
+ "It should not be empty. Constructed from 1 point.");
+
+ doboz2.add(doboz1);
+ check(doboz2.inside(seged),
+ "It should be inside. Incremented a box with another one.");
}
More information about the Lemon-commits
mailing list