diff --git a/photon.mm b/photon.mm
index 76aa75e..d0659a9 100644
--- a/photon.mm
+++ b/photon.mm
@@ -35,14 +35,7 @@
-
-
-
-
-
-
-
@@ -53,7 +46,9 @@
-
+
+
+
@@ -68,14 +63,21 @@
+
+
+
+
+
+
-
+
+
@@ -88,6 +90,7 @@
+
@@ -98,8 +101,9 @@
+
-
+
diff --git a/src/math/Rect.cpp b/src/math/Rect.cpp
index 54bca86..499ee46 100644
--- a/src/math/Rect.cpp
+++ b/src/math/Rect.cpp
@@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
-// $Id: Rect.cpp,v 1.2 2005/03/03 09:25:47 cozman Exp $
+// $Id: Rect.cpp,v 1.3 2005/07/06 13:28:35 cozman Exp $
#include "math/Rect.hpp"
@@ -84,16 +84,16 @@ bool Rect::intersects(const Circle &circle) const
bool Rect::contains(const Point2 &point) const
{
- return point.x > topLeft_.x && point.x < bottomRight_.x &&
- point.y > topLeft_.y && point.y < bottomRight_.y;
+ return point.x >= topLeft_.x && point.x <= bottomRight_.x &&
+ point.y >= topLeft_.y && point.y <= bottomRight_.y;
}
bool Rect::contains(const Rect &rect) const
{
- return rect.topLeft_.x > topLeft_.x &&
- rect.bottomRight_.x < bottomRight_.x &&
- rect.topLeft_.y > topLeft_.y &&
- bottomRight_.y < bottomRight_.y;
+ return rect.topLeft_.x >= topLeft_.x &&
+ rect.bottomRight_.x <= bottomRight_.x &&
+ rect.topLeft_.y >= topLeft_.y &&
+ rect.bottomRight_.y <= bottomRight_.y;
}
Rect Rect::calcIntersection(const Rect &rect) const
diff --git a/test/math_test.cpp b/test/math_test.cpp
index f42f94d..60f1c87 100644
--- a/test/math_test.cpp
+++ b/test/math_test.cpp
@@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
-// $Id: math_test.cpp,v 1.1 2005/07/06 04:27:23 cozman Exp $
+// $Id: math_test.cpp,v 1.2 2005/07/06 13:28:35 cozman Exp $
// Tests almost everything within photon::math
// Doesn't test:
@@ -20,7 +20,12 @@
using namespace photon;
using namespace std;
-int main()
+// example checks should always contain a positive check followed by a negative
+// ex:
+// a contains origin
+// b doesn't contain origin
+
+void testGeneral()
{
// Show sample usage of all functions in math.hpp
cout << "--General Math-------------------------------------------------\n";
@@ -35,14 +40,17 @@ int main()
cout << "PI/6 radians = " << math::radToDeg(math::PI/6) << " degrees\n";
cout << "45 degrees = " << math::degToRad(45) << " radians\n";
cout << endl;
-
+}
+
+void testCircle()
+{
// Demo Circle class
cout << "--Circles------------------------------------------------------\n";
math::Circle a( math::Point2(0, 0), 1); // circle at origin w/ radius 5
math::Circle b( math::Point2(10, 10), 25); // circle at 10,10 w/ radius 25
math::Circle c( math::Point2(-10, -10), 1); // circle at -10,-10 w/ radius 1
math::Point2 ori(0, 0); //origin
- cout << "a: " << a << "\nb: " << b << "\n";
+ cout << "a: " << a << "\nb: " << b << "\nc: " << c << "\n";
cout << (a == a ? "a ==" : "a !=") << " a\n";
cout << (a == b ? "a ==" : "a !=") << " b\n";
cout << "Moving a to 100,100: ";
@@ -60,16 +68,65 @@ int main()
cout << "Resizing a's radius by +3: ";
a.resizeRel(3);
cout << "a: " << a << "\n";
- cout << "a and b " << (a.intersects(b) ? "" : "do not") << " intersect.\n";
- cout << "a and c " << (a.intersects(c) ? "" : "do not") << " intersect.\n";
+ cout << "a and b" << (a.intersects(b) ? "" : " do not") << " intersect.\n";
+ cout << "a and c" << (a.intersects(c) ? "" : " do not") << " intersect.\n";
cout << "a " << (a.contains(ori) ? "contains " : "doesn't contain ") << ori
<< ".\n";
cout << "c " << (c.contains(ori) ? "contains " : "doesn't contain ") << ori
<< ".\n";
-
cout << endl;
-
+}
+
+void testRect()
+{
// Demo Rect class
cout << "--Rects--------------------------------------------------------\n";
-
+ // show both construction methods
+ math::Rect a(math::Point2(-4, -4), 4, 4);
+ math::Rect b(math::Point2(-4, -4), math::Point2(6, 6));
+ math::Rect c(a); // copy of a for later use
+ math::Rect d(math::Point2(-3, -3), 1, 1);
+ math::Point2 ori(0, 0); //origin
+ cout << "a: " << a << "\nb: " << b << "\nc: " << c << "\nd: " << d << "\n";
+ cout << (a == a ? "a ==" : "a !=") << " a\n";
+ cout << (a == b ? "a ==" : "a !=") << " b\n";
+ cout << "Moving a to 0,0: ";
+ a.moveTo( math::Point2(0, 0) );
+ cout << "a: " << a << "\n";
+ cout << "Moving a by 4,4: ";
+ a.moveRel( 4, 4 );
+ cout << "a: " << a << "\n";
+ cout << "Resizing a to 8x8: ";
+ a.resize( 8, 8 );
+ cout << "a: " << a << "\n";
+ cout << "Resizing a by 2 in each direction: ";
+ a.resizeRel( 2, 2 );
+ cout << "a: " << a << "\n";
+ cout << "a and b" << (a.intersects(b) ? "" : " do not") << " intersect.\n";
+ cout << "a and c" << (a.intersects(c) ? "" : " do not") << " intersect.\n";
+ cout << "c " << (c.contains(d) ? "contains" : "doesn't contain") << " d\n";
+ cout << "d " << (d.contains(c) ? "contains" : "doesn't contain") << " c\n";
+ cout << "c " << (c.contains(ori) ? "contains " : "doesn't contain ") << ori
+ << ".\n";
+ cout << "d " << (d.contains(ori) ? "contains " : "doesn't contain ") << ori
+ << ".\n";
+ cout << "a.calcIntersection(b) = " << a.calcIntersection(b) << "\n";
+ cout << "a.calcIntersection(a) = " << a.calcIntersection(a) << "\n";
+ cout << "a.calcIntersection(c) = " << a.calcIntersection(c) << "\n";
+ cout << endl;
+}
+
+void testVector2()
+{
+ // Demo Vector2 class
+ cout << "--Vector2------------------------------------------------------\n";
+ cout << endl;
+}
+
+int main()
+{
+ testGeneral();
+ testCircle();
+ testRect();
+ testVector2();
}