00001 #include "geom_util.h"
00002
00003 int main()
00004 {
00005 cout << endl;
00006 cout << "----------------------------" << endl
00007 << " geom_util.C unit tests " << endl;
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 tPolygond P,Q;
00033 P.resize(3);
00034 P[0][0]=0; P[0][1]=0;
00035 P[1][0]=0; P[1][1]=1;
00036 P[2][0]=1; P[2][1]=0;
00037 Q.resize(3);
00038 Q[0][0]=0.1; Q[0][1]=0.1;
00039 Q[1][0]=0.1; Q[1][1]=1.0;
00040 Q[2][0]=0.8; Q[2][1]=0.0;
00041
00042
00043 cout << "----------------------------------" << endl;
00044 cout << "Testing point in polygon..." << endl;
00045 bool res =true;
00046 for(short i=0;i<3;i++)
00047 if (!point_in_convpoly2D(Q[i], P))
00048 {
00049 res= false;
00050 cout << "FAILED" << endl;
00051 }
00052
00053 if (res)
00054 cout << "PASSED" << endl;
00055
00056 cout << "----------------------------------" << endl;
00057 cout << "Testing polygon in polygon..." << endl;
00058
00059
00060 if ( poly_in_convpoly2D(Q, P))
00061 cerr << "PASSED: P is in Q\n";
00062 else
00063 cerr << "FAILED: Polygon containment test failed\n";
00064
00065 if (poly_in_convpoly2D(P, Q))
00066 cerr << "FAILED: Polygon containment test failed\n";
00067 else
00068 cerr << "PASSED: Q is not in P" << endl;
00069
00070
00071 cout << "----------------------------------" << endl;
00072 cout << "Testing triangle prism intersection..." << endl;
00073 double tri[3][3] = {0,0.25,0.25,
00074 0,0.25,0.0,
00075 0.25,0.25,0.25};
00076
00077 double tri2[3][3] = {0.0, 0.15, 0,
00078 0.25, 0.15, 0.0,
00079 0, 0.15, 0.25};
00080
00081 double tri3[3][3] = {-1.0, 0.26, 1.25,
00082 0.0, 0.26, 0.0,
00083 1.25, 0.26, 1.25};
00084 double tri4[3][3] = {-1, 0.25, 0,
00085 1.0, 0.25, 0.0,
00086 0, 0.25, 1};
00087
00088 double pri[6][3] = {0, 0.25, 0.25,
00089 0, 0.25, 0,
00090 0.25, 0.25, 0.25,
00091 0, -0.25, 0.25,
00092 0, -0.25, 0,
00093 0.25, -0.25, 0.25
00094 };
00095
00096 vector<Vec3D> xpoly2;
00097
00098
00099 if (tri_prism_X(tri,pri,xpoly2)== 0.03125)
00100 {
00101 cerr << "PASSED: Triangle in prism\n";
00102 }
00103 else
00104 {
00105 cerr << "FAILED: Triangle in prism, area reported "
00106 << tri_prism_X(tri,pri,xpoly2) <<"\n";
00107 }
00108
00109
00110 if (tri_prism_X(tri4,pri,xpoly2)== 0.03125)
00111 {
00112 cerr << "PASSED: Prism trace in triangle\n";
00113 }
00114 else
00115 {
00116 cerr << "FAILED: Prism trace in triangle, area reported "
00117 << tri_prism_X(tri4,pri,xpoly2) <<"\n";
00118 }
00119
00120
00121 if (tri_prism_X(tri3,pri,xpoly2)== 0)
00122 {
00123 cerr << "PASSED: No intersection\n";
00124 }
00125 else
00126 {
00127 cerr << "FAILED: No interesection\n";
00128 }
00129
00130
00131 if (tri_prism_X(tri2,pri,xpoly2)== 0.015625)
00132 {
00133 cerr << "PASSED: Triangle intersects prism\n";
00134 }
00135 else
00136 {
00137 cerr << "FAILED: Triangle intersects prism, area reported "
00138 << tri_prism_X(tri2,pri,xpoly2) <<"\n";
00139 }
00140 return 0;
00141 }