proj home

Files   Classes   Functions   Hierarchy  

halfspaceD2test.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 using namespace std;
00003 
00004 #include <point.h>
00005 #include <typedefs.h>
00006 #include <print.h>
00007 
00008 #include <halfspaceD2.h>
00009 #include <halfspaceD2test.h>
00010 
00011 void halfspaceD2test::test01()
00012 {
00013   cout << "halfspace h1(0,1)" << endl;
00014   cout << "Enter a point to test isinside:  ";
00015 
00016   typedef point2<double> pt2;
00017   pt2 p;
00018   cin >> p.x >> p.y;
00019   
00020   halfspaceD2< pt2, double > h1(pt2(0.0,0.0),pt2(0.0,1.0));
00021 
00022   cout << SHOW (h1.isInside(p)) << endl;
00023   cout << SHOW (h1.isInsideOrOnBoundary(p)) << endl;
00024   cout << SHOW (partitionspace<pt2>::classifystring(h1.classify(p))) << endl;
00025 }
00026 
00027 
00028 void halfspaceD2test::test02()
00029 {
00030   cout << "Testing finding the minimum point on the line to the given point" << endl;
00031   typedef point2<double> pt2;
00032   pt2 p0(0.0,0.0);
00033   pt2 p1(1.0,0.0);
00034   cout << "line from " << p0 << " to " << p1 << endl;
00035 
00036   halfspaceD2< pt2, double > h1(p0,p1);
00037   pt2 p(0.5,1.0);
00038   double t;
00039   h1.minimizepointtoline(t,p);
00040   pt2 pmin;
00041   h1.pointOnLine(pmin,t);
00042   cout << SHOW(t) << endl;
00043   cout << SHOW(pmin) << endl;
00044 
00045   cout << SHOW(h1.distancefromhalfspace(p)) << endl;
00046   p=pt2(0.5,2.0);
00047   cout << SHOW(p) << endl;
00048   cout << SHOW(h1.distancefromhalfspace(p)) << endl;
00049   p=pt2(0.3,0.7);
00050   cout << SHOW(p) << endl;
00051   cout << SHOW(h1.distancefromhalfspace(p)) << endl;
00052   p=pt2(0.1,0.7);
00053   cout << SHOW(p) << endl;
00054   cout << SHOW(h1.distancefromhalfspace(p)) << endl;
00055   p=pt2(0.1,0.4);
00056   cout << SHOW(p) << endl;
00057   cout << SHOW(h1.distancefromhalfspace(p)) << endl;
00058   
00059 }
00060 
00061 int halfspaceD2test::unittest01()
00062 {
00063   cout << "Testing clipping in half-space D2." << endl;
00064   cout << "Constructing a vertical half-space left of y-axis." << endl;
00065 
00066   cout << "Sending lines on left, right and through the y-axis." << endl;
00067 
00068   typedef point2<double> pt2;
00069 
00070   // Half space defined left of y-axis.
00071   pt2 p0(0.0,0.0);
00072   pt2 p1(0.0,1.0);
00073   halfspaceD2< pt2, double > h1(p0,p1);
00074 
00075   // Vertical line
00076   pt2 a(0.0,0.5);
00077   pt2 m(1.0,0.0);
00078 
00079   point2<double> t0(.12, .7);
00080   //cout << SHOW(t0) << endl;
00081   assertreturnOS(h1.clip(t0[0],t0[1],a,m)==false);
00082 
00083   point2<double> t1(-.12, -.7);
00084   assertreturnOS(h1.clip(t1[0],t1[1],a,m)==true);
00085 
00086   point2<double> t2(-3, 4.2);
00087   assertreturnOS(h1.clip(t2[0],t2[1],a,m)==true);
00088 
00089   point2<double> t3(-3, 4.2);
00090   assertreturnOS(h1.clipNeg(t3[0],t3[1],a,m)==true);
00091 
00092   point2<double> t4(1.3, 4.2);
00093   assertreturnOS(h1.clipNeg(t4[0],t4[1],a,m)==true);
00094 
00095   point2<double> t5(-5.3, -2.3);
00096   assertreturnOS(h1.clipNeg(t5[0],t5[1],a,m)==false);
00097 
00098   return 0;
00099 }
00100 
00101 
00102 
00103 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8