MeshKit  1.0
pntTrnsfrmLnr2D.cpp
Go to the documentation of this file.
00001 
00007 // C++
00008 #include <iostream>
00009 #include <list>
00010 #include <vector>
00011 
00012 // MeshKit
00013 #include "meshkit/AF2Binding.hpp"
00014 #include "meshkit/AF2Point2D.hpp"
00015 #include "meshkit/AF2PntTrnsfrmLnrV.hpp"
00016 #include "meshkit/AF2RuleExistVertex.hpp"
00017 #include "meshkit/Error.hpp"
00018 
00019 // MeshKit testing
00020 #include "TestUtil.hpp"
00021 
00022 void testListConstructErrorX();
00023 void testListConstructErrorY();
00024 void testVectorConstructErrorX();
00025 void testVectorConstructErrorY();
00026 void testUnboundError();
00027 void testSingleVertexJustX();
00028 void testSingleVertexJustY();
00029 void testSingleVertexFull();
00030 void testMultipleVertices();
00031 
00032 int main(int argc, char **argv)
00033 {
00034   int num_fail = 0;
00035 
00036   num_fail += RUN_TEST(testListConstructErrorX);
00037   num_fail += RUN_TEST(testListConstructErrorY);
00038   num_fail += RUN_TEST(testVectorConstructErrorX);
00039   num_fail += RUN_TEST(testVectorConstructErrorY);
00040   num_fail += RUN_TEST(testUnboundError);
00041   num_fail += RUN_TEST(testSingleVertexJustX);
00042   num_fail += RUN_TEST(testSingleVertexJustY);
00043   num_fail += RUN_TEST(testSingleVertexFull);
00044   num_fail += RUN_TEST(testMultipleVertices);
00045 
00046   return num_fail;
00047 }
00048 
00049 void testListConstructErrorX()
00050 {
00051   std::list<const AF2RuleExistVertex*> emptyVertexList;
00052   std::list<double> xCoeff;
00053   std::list<double> yCoeff;
00054 
00055   xCoeff.push_back(1.0);
00056   xCoeff.push_back(0.0);
00057 
00058   bool exceptionThrown = false;
00059   try
00060   {
00061     AF2PntTrnsfrmLnrV* shouldFail =
00062         new AF2PntTrnsfrmLnrV(emptyVertexList, xCoeff, yCoeff);
00063     delete shouldFail;
00064   }
00065   catch (MeshKit::Error& mkError)
00066   {
00067     CHECK_EQUAL(MeshKit::MK_BAD_INPUT, mkError.error_code());
00068     std::cout << "Good: The error is a bad input error." << std::endl;
00069     std::cout << "The error message is:\n" << mkError.what() << std::endl;
00070     exceptionThrown = true;
00071   }
00072 
00073   CHECK(exceptionThrown);
00074   std::cout << "PASS: A mismatch in the size of the vertex list and the\n"
00075       << "  x-coefficient list in the constructor caused an exception."
00076       << std::endl;
00077 }
00078 
00079 void testListConstructErrorY()
00080 {
00081   std::list<const AF2RuleExistVertex*> emptyVertexList;
00082   std::list<double> xCoeff;
00083   std::list<double> yCoeff;
00084 
00085   yCoeff.push_back(0.0);
00086   yCoeff.push_back(1.0);
00087 
00088   bool exceptionThrown = false;
00089   try
00090   {
00091     AF2PntTrnsfrmLnrV* shouldFail =
00092         new AF2PntTrnsfrmLnrV(emptyVertexList, xCoeff, yCoeff);
00093     delete shouldFail;
00094   }
00095   catch (MeshKit::Error& mkError)
00096   {
00097     CHECK_EQUAL(MeshKit::MK_BAD_INPUT, mkError.error_code());
00098     std::cout << "Good: The error is a bad input error." << std::endl;
00099     std::cout << "The error message is:\n" << mkError.what() << std::endl;
00100     exceptionThrown = true;
00101   }
00102 
00103   CHECK(exceptionThrown);
00104   std::cout << "PASS: A mismatch in the size of the vertex list and the\n"
00105       << "  y-coefficient list in the constructor caused an exception."
00106       << std::endl;
00107 }
00108 
00109 void testVectorConstructErrorX()
00110 {
00111   std::vector<const AF2RuleExistVertex*> emptyVertexVector;
00112   std::vector<double> xCoeff;
00113   std::vector<double> yCoeff;
00114 
00115   xCoeff.push_back(1.0);
00116   xCoeff.push_back(0.0);
00117 
00118   bool exceptionThrown = false;
00119   try
00120   {
00121     AF2PntTrnsfrmLnrV* shouldFail =
00122         new AF2PntTrnsfrmLnrV(emptyVertexVector, xCoeff, yCoeff);
00123     delete shouldFail;
00124   }
00125   catch (MeshKit::Error& mkError)
00126   {
00127     CHECK_EQUAL(MeshKit::MK_BAD_INPUT, mkError.error_code());
00128     std::cout << "Good: The error is a bad input error." << std::endl;
00129     std::cout << "The error message is:\n" << mkError.what() << std::endl;
00130     exceptionThrown = true;
00131   }
00132 
00133   CHECK(exceptionThrown);
00134   std::cout << "PASS: A mismatch in the size of the vertex vector and the\n"
00135       << "  x-coefficient vector in the constructor caused an exception."
00136       << std::endl;
00137 }
00138 
00139 void testVectorConstructErrorY()
00140 {
00141   std::vector<const AF2RuleExistVertex*> emptyVertexVector;
00142   std::vector<double> xCoeff;
00143   std::vector<double> yCoeff;
00144 
00145   yCoeff.push_back(0.0);
00146   yCoeff.push_back(1.0);
00147 
00148   bool exceptionThrown = false;
00149   try
00150   {
00151     AF2PntTrnsfrmLnrV* shouldFail =
00152         new AF2PntTrnsfrmLnrV(emptyVertexVector, xCoeff, yCoeff);
00153     delete shouldFail;
00154   }
00155   catch (MeshKit::Error& mkError)
00156   {
00157     CHECK_EQUAL(MeshKit::MK_BAD_INPUT, mkError.error_code());
00158     std::cout << "Good: The error is a bad input error." << std::endl;
00159     std::cout << "The error message is:\n" << mkError.what() << std::endl;
00160     exceptionThrown = true;
00161   }
00162 
00163   CHECK(exceptionThrown);
00164   std::cout << "PASS: A mismatch in the size of the vertex vector and the\n"
00165       << "  y-coefficient vector in the constructor caused an exception."
00166       << std::endl;
00167 }
00168 
00169 void testUnboundError()
00170 {
00171   std::vector<const AF2RuleExistVertex*> vertexVector;
00172   AF2RuleExistVertex* existVertex = new AF2RuleExistVertex(0.0, 0.0);
00173   vertexVector.push_back(existVertex);
00174   std::vector<double> xCoeff;
00175   xCoeff.push_back(1.0);
00176   xCoeff.push_back(0.0);
00177   std::vector<double> yCoeff;
00178   yCoeff.push_back(0.0);
00179   yCoeff.push_back(0.0);
00180   
00181   AF2PntTrnsfrmLnrV pntTrnsfrm(vertexVector, xCoeff, yCoeff);
00182   AF2Binding emptyBinding;
00183   AF2Point2D aPoint(0.5, 0.5);
00184 
00185   bool exceptionThrown = false;
00186   try
00187   {
00188     pntTrnsfrm.transformPoint(aPoint, emptyBinding);
00189   }
00190   catch (MeshKit::Error& mkError)
00191   {
00192     CHECK_EQUAL(MeshKit::MK_BAD_INPUT, mkError.error_code());
00193     std::cout << "Good: The error is a bad input error." << std::endl;
00194     std::cout << "The error message is:\n" << mkError.what() << std::endl;
00195     exceptionThrown = true;
00196   }
00197 
00198   CHECK(exceptionThrown);
00199   std::cout << "PASS: A binding that does not have bound values for all of\n"
00200       << "  the vertices that the linear transformation uses causes an error."
00201       << std::endl;
00202 
00203   delete existVertex;
00204 }
00205 
00206 void testSingleVertexJustX()
00207 {
00208   std::vector<const AF2RuleExistVertex*> vertexVector;
00209   AF2RuleExistVertex* existVertex = new AF2RuleExistVertex(0.0, 0.0);
00210   vertexVector.push_back(existVertex);
00211   std::vector<double> xCoeff;
00212   xCoeff.push_back(1.0);
00213   xCoeff.push_back(0.0);
00214   std::vector<double> yCoeff;
00215   yCoeff.push_back(0.0);
00216   yCoeff.push_back(0.0);
00217   AF2PntTrnsfrmLnrV pntTrnsfrm(vertexVector, xCoeff, yCoeff);
00218 
00219   AF2Binding binding;
00220   AF2Point2D boundPnt(0.75, 0.25);
00221   binding.bind(existVertex, &boundPnt);
00222 
00223   AF2Point2D pointArg(0.5, 0.5);
00224   AF2Point2D resultPoint = pntTrnsfrm.transformPoint(pointArg, binding);
00225   CHECK_REAL_EQUAL(1.25, resultPoint.getX(), 1e-14);
00226   std::cout << "Good: The resulting point has an x-coordinate of 1.25"
00227       << std::endl;
00228   CHECK_REAL_EQUAL(0.5, resultPoint.getY(), 1e-14);
00229   std::cout << "Good: The resulting point has a y-coordinate of 0.5"
00230       << std::endl;
00231 
00232   std::cout << "PASS: A translation in the x direction works."
00233       << std::endl;
00234 
00235   delete existVertex;
00236 }
00237 
00238 void testSingleVertexJustY()
00239 {
00240   std::vector<const AF2RuleExistVertex*> vertexVector;
00241   AF2RuleExistVertex* existVertex = new AF2RuleExistVertex(1.0, 1.0);
00242   vertexVector.push_back(existVertex);
00243   std::vector<double> xCoeff;
00244   xCoeff.push_back(0.0);
00245   xCoeff.push_back(0.0);
00246   std::vector<double> yCoeff;
00247   yCoeff.push_back(0.0);
00248   yCoeff.push_back(1.0);
00249   AF2PntTrnsfrmLnrV pntTrnsfrm(vertexVector, xCoeff, yCoeff);
00250 
00251   AF2Binding binding;
00252   AF2Point2D boundPnt(1.75, 1.25);
00253   binding.bind(existVertex, &boundPnt);
00254 
00255   AF2Point2D pointArg(0.5, 0.5);
00256   AF2Point2D resultPoint = pntTrnsfrm.transformPoint(pointArg, binding);
00257   CHECK_REAL_EQUAL(0.5, resultPoint.getX(), 1e-14);
00258   std::cout << "Good: The resulting point has an x-coordinate of 0.5"
00259       << std::endl;
00260   CHECK_REAL_EQUAL(0.75, resultPoint.getY(), 1e-14);
00261   std::cout << "Good: The resulting point has a y-coordinate of 0.75"
00262       << std::endl;
00263 
00264   std::cout << "PASS: A translation in the y direction works."
00265       << std::endl;
00266 
00267   delete existVertex;
00268 }
00269 
00270 void testSingleVertexFull()
00271 {
00272   std::vector<const AF2RuleExistVertex*> vertexVector;
00273   AF2RuleExistVertex* existVertex = new AF2RuleExistVertex(0.0, 0.0);
00274   vertexVector.push_back(existVertex);
00275   std::vector<double> xCoeff;
00276   xCoeff.push_back(1.0);
00277   xCoeff.push_back(-2.0);
00278   std::vector<double> yCoeff;
00279   yCoeff.push_back(-3.0);
00280   yCoeff.push_back(4.0);
00281   AF2PntTrnsfrmLnrV pntTrnsfrm(vertexVector, xCoeff, yCoeff);
00282 
00283   AF2Binding binding;
00284   AF2Point2D boundPnt(1.0, 10.0);
00285   binding.bind(existVertex, &boundPnt);
00286 
00287   AF2Point2D pointArg(0.0, 0.0);
00288   AF2Point2D resultPoint = pntTrnsfrm.transformPoint(pointArg, binding);
00289   CHECK_REAL_EQUAL(-19.0, resultPoint.getX(), 1e-14);
00290   std::cout << "Good: The resulting point has an x-coordinate of 8.0"
00291       << std::endl;
00292   CHECK_REAL_EQUAL(37.0, resultPoint.getY(), 1e-14);
00293   std::cout << "Good: The resulting point has a y-coordinate of 37.0"
00294       << std::endl;
00295 
00296   std::cout << "PASS: A translation involving a single vertex and all\n"
00297       << "  four coefficients works." << std::endl;
00298 
00299   delete existVertex;
00300 }
00301 
00302 void testMultipleVertices()
00303 {
00304   std::vector<const AF2RuleExistVertex*> vertexVector;
00305   AF2RuleExistVertex firstExistVertex(0.0, 0.0);
00306   AF2RuleExistVertex secondExistVertex(1.0, 0.0);
00307   vertexVector.push_back(&firstExistVertex);
00308   vertexVector.push_back(&secondExistVertex);
00309   std::vector<double> xCoeff;
00310   xCoeff.push_back(1.0);
00311   xCoeff.push_back(0.0);
00312   xCoeff.push_back(0.0);
00313   xCoeff.push_back(3.0);
00314   std::vector<double> yCoeff;
00315   yCoeff.push_back(0.0);
00316   yCoeff.push_back(5.0);
00317   yCoeff.push_back(1.0);
00318   yCoeff.push_back(0.0);
00319   AF2PntTrnsfrmLnrV pntTrnsfrm(vertexVector, xCoeff, yCoeff);
00320 
00321   AF2Binding binding;
00322   AF2Point2D firstBoundPnt(0.125, 0.25);
00323   AF2Point2D secondBoundPnt(1.5, 0.0625);
00324   binding.bind(&firstExistVertex, &firstBoundPnt);
00325   binding.bind(&secondExistVertex, &secondBoundPnt);
00326 
00327   AF2Point2D pointArg(0.0, 0.0);
00328   AF2Point2D resultPoint = pntTrnsfrm.transformPoint(pointArg, binding);
00329   CHECK_REAL_EQUAL(0.3125, resultPoint.getX(), 1e-14);
00330   std::cout << "Good: The resulting point has an x-coordinate of 0.3125"
00331       << std::endl;
00332   CHECK_REAL_EQUAL(1.75, resultPoint.getY(), 1e-14);
00333   std::cout << "Good: The resulting point has a y-coordinate of 1.75"
00334       << std::endl;
00335 
00336   std::cout << "PASS: A translation involving multiple vertices works."
00337       << std::endl;
00338 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines