math::Rect tested
This commit is contained in:
parent
dc663a4df1
commit
588a8098b4
24
photon.mm
24
photon.mm
@ -35,14 +35,7 @@
|
||||
<node COLOR="#fa6801" ID="Freemind_Link_1326895357" TEXT="Music likely bumped to 0.2 release"/>
|
||||
</node>
|
||||
</node>
|
||||
<node ID="Freemind_Link_188779968" TEXT="Test Suite">
|
||||
<node ID="Freemind_Link_1570884553" TEXT="port test-suite to Saturn core">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node ID="Freemind_Link_1104675603" TEXT="Tests">
|
||||
<node ID="Freemind_Link_1348104879" TEXT="Kernel/AppCore">
|
||||
<node ID="Freemind_Link_1664207862" TEXT="how to test?"/>
|
||||
</node>
|
||||
<node ID="Freemind_Link_288973656" TEXT="Texture">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
@ -53,7 +46,9 @@
|
||||
<node COLOR="#000000" ID="Freemind_Link_171161365" TEXT="Circle">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#000000" ID="Freemind_Link_1333080570" TEXT="Rect"/>
|
||||
<node COLOR="#000000" ID="Freemind_Link_1333080570" TEXT="Rect">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#000000" ID="Freemind_Link_63576276" TEXT="Vector2"/>
|
||||
</node>
|
||||
<node ID="Freemind_Link_279976301" TEXT="Pen"/>
|
||||
@ -68,14 +63,21 @@
|
||||
<node COLOR="#000000" ID="Freemind_Link_212747291" TEXT="allow control via mouse or keyboard"/>
|
||||
</node>
|
||||
<node COLOR="#000000" ID="Freemind_Link_964892891" TEXT="Input"/>
|
||||
<node ID="Freemind_Link_1348104879" TEXT="Kernel/AppCore">
|
||||
<node ID="Freemind_Link_1664207862" TEXT="how to test?"/>
|
||||
</node>
|
||||
</node>
|
||||
<node ID="Freemind_Link_22783417" TEXT="Example Game">
|
||||
<node ID="Freemind_Link_714736465" TEXT="Let's Draw"/>
|
||||
<node COLOR="#000000" ID="Freemind_Link_597173063" TEXT="Asteroids"/>
|
||||
</node>
|
||||
<node ID="Freemind_Link_743325646" TEXT="distribution documentation">
|
||||
<node ID="Freemind_Link_730720170" TEXT="credits"/>
|
||||
<node ID="Freemind_Link_564233418" TEXT="FAQ"/>
|
||||
<node ID="Freemind_Link_363257674" TEXT="contact info"/>
|
||||
</node>
|
||||
<node ID="Freemind_Link_486829238" POSITION="right" TEXT="0.2 Release">
|
||||
</node>
|
||||
<node FOLDED="true" ID="Freemind_Link_486829238" POSITION="right" TEXT="0.2 Release">
|
||||
<node ID="Freemind_Link_216021234" TEXT="Sprite System">
|
||||
<font NAME="SansSerif" SIZE="12"/>
|
||||
</node>
|
||||
@ -88,6 +90,7 @@
|
||||
<node COLOR="#000000" ID="Freemind_Link_420721466" TEXT="XML/XSLT sink">
|
||||
<icon BUILTIN="help"/>
|
||||
</node>
|
||||
<node ID="Freemind_Link_1298931281" TEXT="XML resource files"/>
|
||||
</node>
|
||||
<node ID="Freemind_Link_351891371" POSITION="left" TEXT="General Mateinance">
|
||||
<font BOLD="true" NAME="SansSerif" SIZE="12"/>
|
||||
@ -98,8 +101,9 @@
|
||||
<node ID="Freemind_Link_682620075" POSITION="left" TEXT="Current Problems">
|
||||
<font BOLD="true" NAME="SansSerif" SIZE="12"/>
|
||||
<node ID="Freemind_Link_1080393911" TEXT="audio:: could using some cleaning"/>
|
||||
<node ID="Freemind_Link_632977685" TEXT="make compilation succeed without OpenAL"/>
|
||||
</node>
|
||||
<node COLOR="#147f1e" ID="Freemind_Link_438641521" POSITION="left" TEXT="Version: $Id: photon.mm,v 1.14 2005/07/06 04:27:23 cozman Exp $">
|
||||
<node COLOR="#147f1e" ID="Freemind_Link_438641521" POSITION="left" TEXT="Version: $Id: photon.mm,v 1.15 2005/07/06 13:28:34 cozman Exp $">
|
||||
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
|
||||
</node>
|
||||
</node>
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user