00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <gfx/GfxTest>
00026
00027 using gfx::GfxTest;
00028
00029 using gfx::Line3;
00030 using gfx::Segment3;
00031 using gfx::Triangle3;
00032 using gfx::Plane;
00033 using gfx::Quad3;
00034 using gfx::Disc3;
00035
00036
00037
00038 GfxTest::GfxTest()
00039 {
00040 }
00041
00042
00043 void GfxTest::setUp()
00044 {
00045 ul = Line3(Point3(0,0,0), Vector3(1,1,1));
00046 l = Line3(Point3(0,0,0), Vector3(1,2,3));
00047 us = Segment3(Point3(0,0,0), Point3(1,1,1).normalize());
00048 s = Segment3(Point3(0,0,0), Point3(1,1,1));
00049 s2 = Segment3(Point3(1,1,1), Point3(2,2,2));
00050 s3 = Segment3(Point3(1,2,3), Point3(4,6,7));
00051
00052 q1 = Quad3(Point3(0,0,0),Point3(1,0,0),Point3(1,1,0), Point3(0,1,0));
00053 q2 = Quad3(Point3(2,0,0),Point3(3,0,0),Point3(3,1,0), Point3(2,1,0));
00054 }
00055
00056
00057 void GfxTest::tearDown()
00058 {
00059 }
00060
00061
00062 void GfxTest::testLine()
00063 {
00064 CPPUNIT_ASSERT( ul.contains(Point3(0,0,0)) );
00065 CPPUNIT_ASSERT( ul.contains(Point3(0.5,0.5,0.5)) );
00066 CPPUNIT_ASSERT( ul.contains(Point3(2,2,2)) );
00067 CPPUNIT_ASSERT( ul.contains(Point3(-2,-2,-2)) );
00068
00069 CPPUNIT_ASSERT( l.contains(Point3(1,2,3)) );
00070 CPPUNIT_ASSERT( l.contains(Point3(2,4,6)) );
00071
00072 CPPUNIT_ASSERT( Line3(Point3(0,0,0), Vector3(1,0,0)).pointClosestTo(Point3(0,1,0)).equals(Point3(0,0,0)) );
00073
00074 CPPUNIT_ASSERT( Math::equals( l.distanceTo(Point3(2,4,6)), 0 ) );
00075 CPPUNIT_ASSERT( Math::equals( Line3(Point3(0,0,0), Vector3(1,0,0)).distanceTo(Point3(0.5,0,0)), 0 ) );
00076 CPPUNIT_ASSERT( Math::equals( Line3(Point3(0,0,0), Vector3(1,0,0)).distanceTo(Point3(0,2,0)), 2 ) );
00077
00078 Line3 xl(Point3(0,0,0), Vector3(1,0,0));
00079 Line3 yl(Point3(0,-1,1), Vector3(0,1,0));
00080 Segment3 bxy(Point3(0,0,0), Point3(0,0,1));
00081 CPPUNIT_ASSERT( xl.shortestSegmentBetween(yl).equals(bxy) );
00082 CPPUNIT_ASSERT( Math::equals(xl.distanceTo(yl),1) );
00083 }
00084
00085
00086 void GfxTest::testSegment()
00087 {
00088 CPPUNIT_ASSERT( s.contains(Point3(0,0,0)) );
00089 CPPUNIT_ASSERT( s.contains(Point3(0.5,0.5,0.5)) );
00090 CPPUNIT_ASSERT( s.contains(Point3(1,1,1)) );
00091 CPPUNIT_ASSERT( !s.contains(Point3(2,2,2)) );
00092 CPPUNIT_ASSERT( !s.contains(Point3(-2,-2,-2)) );
00093 CPPUNIT_ASSERT( !s.contains(Point3(1,1,1.5)) );
00094 CPPUNIT_ASSERT( !s.contains(Point3(2,2,2.5)) );
00095 CPPUNIT_ASSERT( !s.contains(Point3(-1,-1,-0.5)) );
00096
00097 CPPUNIT_ASSERT( s.pointClosestTo(Point3(2,2,2)).equals(Point3(1,1,1)) );
00098 CPPUNIT_ASSERT( s.pointClosestTo(Point3(2,3,4)).equals(Point3(1,1,1)) );
00099 CPPUNIT_ASSERT( s.pointClosestTo(Point3(-1,-1,-1)).equals(Point3(0,0,0)) );
00100 CPPUNIT_ASSERT( s.pointClosestTo(Point3(-2,-1,-1)).equals(Point3(0,0,0)) );
00101
00102 CPPUNIT_ASSERT( Segment3(Point3(0,0,0),Point3(1,0,0)).pointClosestTo(Point3(0.5,2,1)).equals(Point3(0.5,0,0)) );
00103 CPPUNIT_ASSERT( Math::equals(Segment3(Point3(0,0,0),Point3(1,0,0)).distanceTo(Point3(0.5,2,0)),2) );
00104
00105 CPPUNIT_ASSERT( Math::equals(s.distanceTo(s2), 0) );
00106 Segment3 s4(Point3(3,3,3),Point3(4,4,4));
00107 CPPUNIT_ASSERT( Math::equals(s.distanceTo(s4), Math::sqrt(12)) );
00108
00109 Segment3 xs(Point3(-0.5,0,0), Point3(1,0,0));
00110 Segment3 ys(Point3(0,-1,1), Point3(0,1,1));
00111 CPPUNIT_ASSERT( Math::equals( xs.distanceTo(ys), 1) );
00112 CPPUNIT_ASSERT( xs.shortestSegmentBetween(ys).equals( Segment3(Point3(0,0,0),Point3(0,0,1)) ) );
00113 }
00114
00115
00116 void GfxTest::testPlane()
00117 {
00118 Plane pl1(Vector3(0,0,1),0);
00119
00120 CPPUNIT_ASSERT( Math::equals( pl1.distanceTo(Point3(0,0,1)), 1) );
00121 CPPUNIT_ASSERT( pl1.contains(Point3(0,0,0)) );
00122
00123 Plane pl2(Vector3(0,0,1),-1);
00124
00125 CPPUNIT_ASSERT( pl2.contains(Point3(0,0,1)) );
00126
00127 Plane pl3(Vector3(1,1,1),-1);
00128 Point3 p(1,1,1); p.normalize();
00129 CPPUNIT_ASSERT( pl3.contains(p) );
00130 CPPUNIT_ASSERT( !pl3.contains(Point3(2,2,2)) );
00131 }
00132
00133
00134 void GfxTest::testTriangle()
00135 {
00136 Triangle3 txy(Point3(1,0,0), Point3(0,0,0), Point3(0,1,0));
00137
00138 CPPUNIT_ASSERT( txy.pointClosestTo(Point3(20,-1,1)).equals(Point3(1,0,0)) );
00139 CPPUNIT_ASSERT( txy.pointClosestTo(Point3(0.3,0.3,1)).equals(Point3(0.3,0.3,0)) );
00140 CPPUNIT_ASSERT( txy.pointClosestTo(Point3(0.3,0.3,0)).equals(Point3(0.3,0.3,0)) );
00141
00142 Segment3 ts(Point3(0.3,0.3,1),Point3(0.4,0.4,0.2));
00143 CPPUNIT_ASSERT( txy.shortestSegmentBetween(ts).equals(Segment3(Point3(0.4,0.4,0),Point3(0.4,0.4,0.2))) );
00144
00145 Segment3 ts2(Point3(2,2,2), Point3(3,3,3));
00146 CPPUNIT_ASSERT( txy.shortestSegmentBetween(ts2).equals(Segment3(Point3(0.5,0.5,0), Point3(2,2,2))) );
00147 }
00148
00149
00150 void GfxTest::testQuad()
00151 {
00152 CPPUNIT_ASSERT( Math::equals( q1.distanceTo(q2), 1) );
00153 }
00154
00155
00156
00157 void GfxTest::testDisc()
00158 {
00159 Disc3 d1(Point3(0,0,0), Vector3(0,0,1), 1);
00160 CPPUNIT_ASSERT( Math::equals( d1.distanceTo(Point3(0,0,1)), 1) );
00161 CPPUNIT_ASSERT( Math::equals( d1.distanceTo(Point3(0.5,0.5,1)), 1) );
00162 CPPUNIT_ASSERT( Math::equals( d1.distanceTo(Point3(0,2,0)), 1) );
00163 }
00164
00165
00166
00167
00168 #ifdef DEBUG
00169 CPPUNIT_TEST_SUITE_REGISTRATION( GfxTest );
00170 #endif
00171