| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [94d5ac6] | 5 | * | 
|---|
|  | 6 | * | 
|---|
|  | 7 | *   This file is part of MoleCuilder. | 
|---|
|  | 8 | * | 
|---|
|  | 9 | *    MoleCuilder is free software: you can redistribute it and/or modify | 
|---|
|  | 10 | *    it under the terms of the GNU General Public License as published by | 
|---|
|  | 11 | *    the Free Software Foundation, either version 2 of the License, or | 
|---|
|  | 12 | *    (at your option) any later version. | 
|---|
|  | 13 | * | 
|---|
|  | 14 | *    MoleCuilder is distributed in the hope that it will be useful, | 
|---|
|  | 15 | *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 16 | *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 17 | *    GNU General Public License for more details. | 
|---|
|  | 18 | * | 
|---|
|  | 19 | *    You should have received a copy of the GNU General Public License | 
|---|
|  | 20 | *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| [bcf653] | 21 | */ | 
|---|
|  | 22 |  | 
|---|
| [e9c677] | 23 | /* | 
|---|
| [f844ef] | 24 | * Tesselation_BoundaryTriangleUnitTest.cpp | 
|---|
| [e9c677] | 25 | * | 
|---|
|  | 26 | *  Created on: Jan 13, 2010 | 
|---|
|  | 27 | *      Author: heber | 
|---|
|  | 28 | */ | 
|---|
|  | 29 |  | 
|---|
| [bf3817] | 30 | // include config.h | 
|---|
|  | 31 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 32 | #include <config.h> | 
|---|
|  | 33 | #endif | 
|---|
|  | 34 |  | 
|---|
| [e9c677] | 35 | using namespace std; | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #include <cppunit/CompilerOutputter.h> | 
|---|
|  | 38 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
|  | 39 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
|  | 40 |  | 
|---|
|  | 41 | #include <cstring> | 
|---|
| [d74077] | 42 | #include <iostream> | 
|---|
| [e9c677] | 43 |  | 
|---|
| [255829] | 44 | #include "CodePatterns/Log.hpp" | 
|---|
| [e4fe8d] | 45 | #include "Helpers/defs.hpp" | 
|---|
| [6f0841] | 46 | #include "Atom/TesselPoint.hpp" | 
|---|
| [471dec] | 47 | #include "LinearAlgebra/Plane.hpp" | 
|---|
| [6dc3fe] | 48 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| [471dec] | 49 | #include "LinearAlgebra/VectorSet.hpp" | 
|---|
| [d127c8] | 50 | #include "Tesselation/BoundaryPointSet.hpp" | 
|---|
|  | 51 | #include "Tesselation/BoundaryLineSet.hpp" | 
|---|
|  | 52 | #include "Tesselation/BoundaryTriangleSet.hpp" | 
|---|
|  | 53 | #include "Tesselation/CandidateForTesselation.hpp" | 
|---|
| [f844ef] | 54 |  | 
|---|
|  | 55 | #include "Tesselation_BoundaryTriangleUnitTest.hpp" | 
|---|
| [e9c677] | 56 |  | 
|---|
| [9b6b2f] | 57 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 58 | #include "UnitTestMain.hpp" | 
|---|
|  | 59 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 60 |  | 
|---|
| [88b400] | 61 | const double TesselationBoundaryTriangleTest::SPHERERADIUS=2.; | 
|---|
| [e9c677] | 62 |  | 
|---|
|  | 63 | /********************************************** Test classes **************************************/ | 
|---|
|  | 64 |  | 
|---|
|  | 65 | // Registers the fixture into the 'registry' | 
|---|
|  | 66 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest ); | 
|---|
|  | 67 |  | 
|---|
|  | 68 |  | 
|---|
| [471dec] | 69 | void TesselationBoundaryTriangleTest::createTriangle(const std::vector<Vector> &Vectors) | 
|---|
| [e9c677] | 70 | { | 
|---|
| [c1d78c] | 71 | CPPUNIT_ASSERT_EQUAL( (size_t)NDIM, Vectors.size() ); | 
|---|
| [e9c677] | 72 |  | 
|---|
|  | 73 | // create nodes | 
|---|
| [471dec] | 74 | for (size_t count = 0; count < NDIM; ++count) { | 
|---|
|  | 75 | tesselpoints[count] = new TesselPoint; | 
|---|
|  | 76 | tesselpoints[count]->setPosition( Vectors[count] ); | 
|---|
|  | 77 | tesselpoints[count]->setName(toString(count)); | 
|---|
|  | 78 | tesselpoints[count]->setNr(count); | 
|---|
|  | 79 | points[count] = new BoundaryPointSet(tesselpoints[count]); | 
|---|
|  | 80 | } | 
|---|
| [e9c677] | 81 |  | 
|---|
|  | 82 | // create line | 
|---|
|  | 83 | lines[0] = new BoundaryLineSet(points[0], points[1], 0); | 
|---|
|  | 84 | lines[1] = new BoundaryLineSet(points[1], points[2], 1); | 
|---|
|  | 85 | lines[2] = new BoundaryLineSet(points[0], points[2], 2); | 
|---|
|  | 86 |  | 
|---|
|  | 87 | // create triangle | 
|---|
|  | 88 | triangle = new BoundaryTriangleSet(lines, 0); | 
|---|
| [471dec] | 89 | Plane p(Vectors[0], Vectors[1], Vectors[2]); | 
|---|
|  | 90 | triangle->GetNormalVector(p.getNormal()); | 
|---|
|  | 91 | } | 
|---|
| [e9c677] | 92 |  | 
|---|
| [c1d78c] | 93 | /** This cleanly removes a triangle created via createTriangle() from memory. | 
|---|
|  | 94 | * | 
|---|
|  | 95 | */ | 
|---|
|  | 96 | void TesselationBoundaryTriangleTest::removeTriangle() | 
|---|
|  | 97 | { | 
|---|
|  | 98 | delete(triangle); | 
|---|
|  | 99 | for (int i=0;i<NDIM;++i) { | 
|---|
|  | 100 | // TesselPoint does not delete its vector as it only got a reference | 
|---|
|  | 101 | delete tesselpoints[i]; | 
|---|
|  | 102 | } | 
|---|
|  | 103 | } | 
|---|
|  | 104 |  | 
|---|
| [471dec] | 105 | void TesselationBoundaryTriangleTest::setUp() | 
|---|
|  | 106 | { | 
|---|
|  | 107 | setVerbosity(5); | 
|---|
|  | 108 |  | 
|---|
|  | 109 | // create nodes | 
|---|
|  | 110 | std::vector<Vector> Vectors; | 
|---|
|  | 111 | Vectors.push_back( Vector(0., 0., 0.) ); | 
|---|
|  | 112 | Vectors.push_back( Vector(0., 1., 0.) ); | 
|---|
|  | 113 | Vectors.push_back( Vector(1., 0., 0.) ); | 
|---|
|  | 114 |  | 
|---|
|  | 115 | // create triangle | 
|---|
|  | 116 | createTriangle(Vectors); | 
|---|
|  | 117 | } | 
|---|
| [e9c677] | 118 |  | 
|---|
|  | 119 | void TesselationBoundaryTriangleTest::tearDown() | 
|---|
|  | 120 | { | 
|---|
| [c1d78c] | 121 | removeTriangle(); | 
|---|
| [e9c677] | 122 | logger::purgeInstance(); | 
|---|
|  | 123 | errorLogger::purgeInstance(); | 
|---|
| [6dc3fe] | 124 | } | 
|---|
| [e9c677] | 125 |  | 
|---|
| [471dec] | 126 | /** UnitTest for Tesselation::IsInsideTriangle() | 
|---|
|  | 127 | */ | 
|---|
|  | 128 | void TesselationBoundaryTriangleTest::IsInsideTriangleTest() | 
|---|
|  | 129 | { | 
|---|
|  | 130 | // inside points | 
|---|
|  | 131 | { | 
|---|
|  | 132 | // check each endnode | 
|---|
|  | 133 | for (size_t i=0; i< NDIM; ++i) { | 
|---|
|  | 134 | const Vector testPoint(triangle->endpoints[i]->node->getPosition()); | 
|---|
|  | 135 | LOG(1, "INFO: Testing whether " << testPoint << " is an inner point."); | 
|---|
|  | 136 | CPPUNIT_ASSERT( triangle->IsInsideTriangle( testPoint ) ); | 
|---|
|  | 137 | } | 
|---|
|  | 138 | } | 
|---|
|  | 139 |  | 
|---|
|  | 140 | { | 
|---|
|  | 141 | // check points along each BoundaryLine | 
|---|
|  | 142 | for (size_t i=0; i< NDIM; ++i) { | 
|---|
|  | 143 | Vector offset = triangle->endpoints[i%3]->node->getPosition(); | 
|---|
|  | 144 | Vector direction = triangle->endpoints[(i+1)%3]->node->getPosition() - offset; | 
|---|
|  | 145 | for (double s = 0.1; s < 1.; s+= 0.1) { | 
|---|
|  | 146 | Vector testPoint = offset + s*direction; | 
|---|
|  | 147 | LOG(1, "INFO: Testing whether " << testPoint << " is an inner point."); | 
|---|
|  | 148 | CPPUNIT_ASSERT( triangle->IsInsideTriangle( testPoint ) ); | 
|---|
|  | 149 | } | 
|---|
|  | 150 | } | 
|---|
|  | 151 | } | 
|---|
|  | 152 |  | 
|---|
|  | 153 | { | 
|---|
|  | 154 | // check central point | 
|---|
|  | 155 | Vector center; | 
|---|
|  | 156 | triangle->GetCenter(center); | 
|---|
|  | 157 | LOG(1, "INFO: Testing whether " << center << " is an inner point."); | 
|---|
|  | 158 | CPPUNIT_ASSERT( triangle->IsInsideTriangle( center ) ); | 
|---|
|  | 159 | } | 
|---|
|  | 160 |  | 
|---|
|  | 161 | // outside points | 
|---|
|  | 162 | { | 
|---|
|  | 163 | // check points outside (i.e. those not in xy-plane through origin) | 
|---|
|  | 164 | double n[3]; | 
|---|
|  | 165 | const double boundary = 4.; | 
|---|
|  | 166 | const double step = 1.; | 
|---|
|  | 167 | // go through the cube and check each point | 
|---|
|  | 168 | for (n[0] = -boundary; n[0] <= boundary; n[0]+=step) | 
|---|
|  | 169 | for (n[1] = -boundary; n[1] <= boundary; n[1]+=step) | 
|---|
|  | 170 | for (n[2] = -boundary; n[2] <= boundary; n[2]+=step) { | 
|---|
|  | 171 | const Vector testPoint(n[0], n[1], n[2]); | 
|---|
|  | 172 | if (n[2] != 0) { | 
|---|
|  | 173 | LOG(1, "INFO: Testing whether " << testPoint << " is not an inner point."); | 
|---|
|  | 174 | CPPUNIT_ASSERT( !triangle->IsInsideTriangle( testPoint ) ); | 
|---|
|  | 175 | } | 
|---|
|  | 176 | } | 
|---|
|  | 177 | } | 
|---|
|  | 178 |  | 
|---|
|  | 179 | { | 
|---|
|  | 180 | // check points within the plane but outside of triangle | 
|---|
|  | 181 | double n[3]; | 
|---|
|  | 182 | const double boundary = 4.; | 
|---|
|  | 183 | const double step = 1.; | 
|---|
|  | 184 | n[2] = 0; | 
|---|
|  | 185 | for (n[0] = -boundary; n[0] <= boundary; n[0]+=step) | 
|---|
|  | 186 | for (n[1] = -boundary; n[1] <= boundary; n[1]+=step) { | 
|---|
|  | 187 | const Vector testPoint(n[0], n[1], n[2]); | 
|---|
|  | 188 | if ((n[0] >=0) && (n[1] >=0) && (n[0]<=1) && (n[1]<=1)) { | 
|---|
|  | 189 | if (n[0]+n[1] <= 1) { | 
|---|
|  | 190 | LOG(1, "INFO: Testing whether " << testPoint << " is an inner point."); | 
|---|
|  | 191 | CPPUNIT_ASSERT( triangle->IsInsideTriangle( testPoint) ); | 
|---|
|  | 192 | } else { | 
|---|
|  | 193 | LOG(1, "INFO: Testing whether " << testPoint << " is not an inner point."); | 
|---|
|  | 194 | CPPUNIT_ASSERT( !triangle->IsInsideTriangle( testPoint) ); | 
|---|
|  | 195 | } | 
|---|
|  | 196 | } else { | 
|---|
|  | 197 | LOG(1, "INFO: Testing whether " << testPoint << " is not an inner point."); | 
|---|
|  | 198 | CPPUNIT_ASSERT( !triangle->IsInsideTriangle( testPoint) ); | 
|---|
|  | 199 | } | 
|---|
|  | 200 | } | 
|---|
|  | 201 | } | 
|---|
|  | 202 | } | 
|---|
|  | 203 |  | 
|---|
|  | 204 | /** UnitTest for Tesselation::IsInsideTriangle() | 
|---|
|  | 205 | * | 
|---|
|  | 206 | * We test for some specific points that occured in larger examples of the code. | 
|---|
|  | 207 | * | 
|---|
|  | 208 | */ | 
|---|
|  | 209 | void TesselationBoundaryTriangleTest::IsInsideTriangle_specificTest() | 
|---|
|  | 210 | { | 
|---|
|  | 211 | { | 
|---|
| [c1d78c] | 212 | removeTriangle(); | 
|---|
| [471dec] | 213 | // test is from --create-micelle 200 --radius 30. --position "0,0,0" of sles.data | 
|---|
|  | 214 | // failure is: Intersection (23.1644,24.1867,65.1272) is not inside triangle [659|Na2451,O3652,Na3762]. | 
|---|
|  | 215 | const Vector testPoint(1.57318,1.57612,10.9874); | 
|---|
|  | 216 | const Vector testIntersection(23.1644,24.1867,65.1272); | 
|---|
|  | 217 | std::vector<Vector> vectors; | 
|---|
|  | 218 | vectors.push_back( Vector(23.0563,30.4673,73.7555) ); | 
|---|
|  | 219 | vectors.push_back( Vector(25.473,25.1512,68.5467) ); | 
|---|
|  | 220 | vectors.push_back( Vector(23.1644,24.1867,65.1272) ); | 
|---|
|  | 221 | createTriangle(vectors); | 
|---|
|  | 222 | CPPUNIT_ASSERT( triangle->IsInsideTriangle( testIntersection ) ); | 
|---|
| [03a713] | 223 | } | 
|---|
|  | 224 | { | 
|---|
| [c1d78c] | 225 | removeTriangle(); | 
|---|
| [03a713] | 226 | // test is from --create-micelle 200 --radius 30. --position "0,0,0" of sles.data | 
|---|
|  | 227 | // failure is: Intersection (20.6787,70.655,71.5657) is not inside triangle [622|Na1197,Na2166,O3366]. | 
|---|
|  | 228 | // fix is lower LINALG_MYEPSILON (not std::numeric_limits<doubble>*100 but *1e-4) | 
|---|
|  | 229 | const Vector testPoint(1.57318,14.185,61.2155); | 
|---|
|  | 230 | const Vector testIntersection(20.67867516517798,70.65496977054023,71.56572984946152); | 
|---|
|  | 231 | std::vector<Vector> vectors; | 
|---|
|  | 232 | vectors.push_back( Vector(22.9592,68.7791,77.5907) ); | 
|---|
|  | 233 | vectors.push_back( Vector(18.4729,72.0386,68.08839999999999) ); | 
|---|
|  | 234 | vectors.push_back( Vector(20.3834,71.0154,70.1443) ); | 
|---|
|  | 235 | createTriangle(vectors); | 
|---|
|  | 236 | CPPUNIT_ASSERT( triangle->IsInsideTriangle( testIntersection ) ); | 
|---|
| [471dec] | 237 | } | 
|---|
| [c27ce7] | 238 | { | 
|---|
| [c1d78c] | 239 | removeTriangle(); | 
|---|
| [c27ce7] | 240 | // test is from --create-micelle 200 --radius 30. --position "0,0,0" of sles.data | 
|---|
|  | 241 | // failure is:Intersection (27.56537519896,13.40256646925,6.672946688134) is not inside triangle [702|Na5016,O6388,Na6498]. | 
|---|
|  | 242 | // note that the Intersection cannot possibly lie be within the triangle! | 
|---|
| [6a7fcbb] | 243 | // we test now against correct intersection | 
|---|
|  | 244 | const Vector testIntersection(14.6872,36.204,39.8043); | 
|---|
| [c27ce7] | 245 | std::vector<Vector> vectors; | 
|---|
|  | 246 | vectors.push_back( Vector(10.7513,43.4247,48.4127) ); | 
|---|
|  | 247 | vectors.push_back( Vector(13.7119,37.0827,47.4203) ); | 
|---|
|  | 248 | vectors.push_back( Vector(14.6872,36.204,39.8043) ); | 
|---|
|  | 249 | createTriangle(vectors); | 
|---|
|  | 250 | CPPUNIT_ASSERT( triangle->IsInsideTriangle( testIntersection ) ); | 
|---|
|  | 251 | } | 
|---|
| [471dec] | 252 | } | 
|---|
|  | 253 |  | 
|---|
| [6dc3fe] | 254 | /** UnitTest for Tesselation::GetClosestPointInsideTriangle() | 
|---|
|  | 255 | * | 
|---|
|  | 256 | * We check whether this function always returns a intersection inside the | 
|---|
|  | 257 | * triangle. | 
|---|
|  | 258 | * | 
|---|
|  | 259 | */ | 
|---|
|  | 260 | void TesselationBoundaryTriangleTest::GetClosestPointInsideTriangleTest() | 
|---|
|  | 261 | { | 
|---|
|  | 262 | Vector TestIntersection; | 
|---|
|  | 263 |  | 
|---|
|  | 264 | { | 
|---|
|  | 265 | // march through a cube mesh on triangle in xy plane | 
|---|
|  | 266 | double n[3]; | 
|---|
|  | 267 | const double boundary = 4.; | 
|---|
|  | 268 | const double step = 1.; | 
|---|
|  | 269 | // go through the cube and check each point | 
|---|
|  | 270 | for (n[0] = -boundary; n[0] <= boundary; n[0]+=step) | 
|---|
|  | 271 | for (n[1] = -boundary; n[1] <= boundary; n[1]+=step) | 
|---|
|  | 272 | for (n[2] = -boundary; n[2] <= boundary; n[2]+=step) { | 
|---|
|  | 273 | const Vector testPoint(n[0], n[1], n[2]); | 
|---|
|  | 274 | triangle->GetClosestPointInsideTriangle(testPoint, TestIntersection); | 
|---|
|  | 275 | CPPUNIT_ASSERT( triangle->IsInsideTriangle( TestIntersection )); | 
|---|
|  | 276 | } | 
|---|
|  | 277 | } | 
|---|
|  | 278 |  | 
|---|
| [c1d78c] | 279 | removeTriangle(); | 
|---|
| [6dc3fe] | 280 | // create better triangle; | 
|---|
|  | 281 | VECTORSET(std::vector) Vectors; | 
|---|
|  | 282 | Vectors.push_back( Vector(0., 0., 0.) ); | 
|---|
|  | 283 | Vectors.push_back( Vector(0., 1., 0.) ); | 
|---|
|  | 284 | Vectors.push_back( Vector(1., 0., 0.) ); | 
|---|
|  | 285 | RealSpaceMatrix M; | 
|---|
|  | 286 | M.setRotation(M_PI/3., M_PI/4., 2.*M_PI/3.); | 
|---|
|  | 287 | Vectors.transform(M); | 
|---|
|  | 288 | createTriangle(Vectors); | 
|---|
|  | 289 |  | 
|---|
|  | 290 | { | 
|---|
|  | 291 | // march through a cube mesh on rotated triangle | 
|---|
|  | 292 | double n[3]; | 
|---|
|  | 293 | const double boundary = 4.; | 
|---|
|  | 294 | const double step = 1.; | 
|---|
|  | 295 | // go through the cube and check each point | 
|---|
|  | 296 | for (n[0] = -boundary; n[0] <= boundary; n[0]+=step) | 
|---|
|  | 297 | for (n[1] = -boundary; n[1] <= boundary; n[1]+=step) | 
|---|
|  | 298 | for (n[2] = -boundary; n[2] <= boundary; n[2]+=step) { | 
|---|
|  | 299 | const Vector testPoint(n[0], n[1], n[2]); | 
|---|
|  | 300 | triangle->GetClosestPointInsideTriangle(testPoint, TestIntersection); | 
|---|
|  | 301 | CPPUNIT_ASSERT( triangle->IsInsideTriangle( TestIntersection )); | 
|---|
|  | 302 | } | 
|---|
|  | 303 | } | 
|---|
|  | 304 | } | 
|---|
|  | 305 |  | 
|---|
| [c27ce7] | 306 | /** UnitTest for Tesselation::GetClosestPointInsideTriangle() | 
|---|
|  | 307 | * | 
|---|
|  | 308 | * We test for some specific points that occured in larger examples of the code. | 
|---|
|  | 309 | * | 
|---|
|  | 310 | */ | 
|---|
|  | 311 | void TesselationBoundaryTriangleTest::GetClosestPointInsideTriangle_specificTest() | 
|---|
|  | 312 | { | 
|---|
|  | 313 | { | 
|---|
| [c1d78c] | 314 | removeTriangle(); | 
|---|
| [c27ce7] | 315 | // test is from --create-micelle 200 --radius 30. --position "0,0,0" of sles.data | 
|---|
|  | 316 | // failure is:Intersection (27.56537519896,13.40256646925,6.672946688134) is not inside triangle [702|Na5016,O6388,Na6498]. | 
|---|
|  | 317 | // note that the Intersection cannot possibly lie be within the triangle | 
|---|
|  | 318 | // however, it is on its plane (off only by 2.7e-12) | 
|---|
| [6a7fcbb] | 319 | // testPoint2 is corrected version | 
|---|
| [c27ce7] | 320 | const Vector testPoint(27.56537519896,13.40256646925,6.672946688134); | 
|---|
| [6a7fcbb] | 321 | const Vector testPoint2(14.6872,36.204,39.8043); | 
|---|
| [c27ce7] | 322 | Vector testIntersection; | 
|---|
|  | 323 | std::vector<Vector> vectors; | 
|---|
|  | 324 | vectors.push_back( Vector(10.7513,43.4247,48.4127) ); | 
|---|
|  | 325 | vectors.push_back( Vector(13.7119,37.0827,47.4203) ); | 
|---|
|  | 326 | vectors.push_back( Vector(14.6872,36.204,39.8043) ); | 
|---|
|  | 327 | createTriangle(vectors); | 
|---|
|  | 328 | triangle->GetClosestPointInsideTriangle(testPoint, testIntersection); | 
|---|
| [6a7fcbb] | 329 | CPPUNIT_ASSERT ( testPoint != testIntersection ); | 
|---|
|  | 330 | CPPUNIT_ASSERT ( testPoint2 == testIntersection ); | 
|---|
| [c27ce7] | 331 | } | 
|---|
|  | 332 | } | 
|---|
| [6dc3fe] | 333 |  | 
|---|
| [e9c677] | 334 | /** UnitTest for Tesselation::IsInnerPoint() | 
|---|
|  | 335 | */ | 
|---|
|  | 336 | void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest() | 
|---|
|  | 337 | { | 
|---|
|  | 338 | Vector TestIntersection; | 
|---|
|  | 339 | Vector Point; | 
|---|
|  | 340 |  | 
|---|
|  | 341 | // simple test on y line | 
|---|
| [1bd79e] | 342 | Point = Vector(-1.,0.5,0.); | 
|---|
| [d74077] | 343 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 344 | Point = Vector(0.,0.5,0.); | 
|---|
| [e9c677] | 345 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 346 | Point = Vector(-4.,0.5,0.); | 
|---|
| [d74077] | 347 | CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 348 | Point = Vector(0.,0.5,0.); | 
|---|
| [e9c677] | 349 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 350 |  | 
|---|
|  | 351 | // simple test on x line | 
|---|
| [1bd79e] | 352 | Point = Vector(0.5,-1.,0.); | 
|---|
| [d74077] | 353 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 354 | Point = Vector(0.5,0.,0.); | 
|---|
| [e9c677] | 355 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 356 | Point = Vector(0.5,-6.,0.); | 
|---|
| [d74077] | 357 | CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 358 | Point = Vector(0.5,0.,0.); | 
|---|
| [e9c677] | 359 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 360 |  | 
|---|
|  | 361 | // simple test on slanted line | 
|---|
| [1bd79e] | 362 | Point = Vector(1.,1.,0.); | 
|---|
| [d74077] | 363 | CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 364 | Point = Vector(0.5,0.5,0.); | 
|---|
| [e9c677] | 365 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 366 | Point = Vector(5.,5.,0.); | 
|---|
| [d74077] | 367 | CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 368 | Point = Vector(0.5,0.5,0.); | 
|---|
| [e9c677] | 369 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 370 |  | 
|---|
|  | 371 | // simple test on first node | 
|---|
| [1bd79e] | 372 | Point = Vector(-1.,-1.,0.); | 
|---|
| [d74077] | 373 | CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 374 | Point = Vector(0.,0.,0.); | 
|---|
| [e9c677] | 375 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 376 |  | 
|---|
|  | 377 | // simple test on second node | 
|---|
| [1bd79e] | 378 | Point = Vector(0.,2.,0.); | 
|---|
| [d74077] | 379 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 380 | Point = Vector(0.,1.,0.); | 
|---|
| [e9c677] | 381 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 382 |  | 
|---|
|  | 383 | // simple test on third node | 
|---|
| [1bd79e] | 384 | Point = Vector(2.,0.,0.); | 
|---|
| [d74077] | 385 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 386 | Point = Vector(1.,0.,0.); | 
|---|
| [e9c677] | 387 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 388 | }; | 
|---|
|  | 389 |  | 
|---|
|  | 390 | /** UnitTest for Tesselation::IsInnerPoint() | 
|---|
|  | 391 | */ | 
|---|
|  | 392 | void TesselationBoundaryTriangleTest::GetClosestPointOffPlaneTest() | 
|---|
|  | 393 | { | 
|---|
|  | 394 | Vector TestIntersection; | 
|---|
|  | 395 | Vector Point; | 
|---|
|  | 396 |  | 
|---|
|  | 397 | // straight down/up | 
|---|
| [1bd79e] | 398 | Point = Vector(1./3.,1./3.,+5.); | 
|---|
| [d74077] | 399 | CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 400 | Point = Vector(1./3.,1./3.,0.); | 
|---|
| [e9c677] | 401 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 402 | Point = Vector(1./3.,1./3.,-5.); | 
|---|
| [d74077] | 403 | CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 404 | Point = Vector(1./3.,1./3.,0.); | 
|---|
| [e9c677] | 405 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 406 |  | 
|---|
|  | 407 | // simple test on y line | 
|---|
| [1bd79e] | 408 | Point = Vector(-1.,0.5,+2.); | 
|---|
| [d74077] | 409 | CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 410 | Point = Vector(0.,0.5,0.); | 
|---|
| [e9c677] | 411 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 412 | Point = Vector(-1.,0.5,-3.); | 
|---|
| [d74077] | 413 | CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 414 | Point = Vector(0.,0.5,0.); | 
|---|
| [e9c677] | 415 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 416 |  | 
|---|
|  | 417 | // simple test on x line | 
|---|
| [1bd79e] | 418 | Point = Vector(0.5,-1.,+1.); | 
|---|
| [d74077] | 419 | CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 420 | Point = Vector(0.5,0.,0.); | 
|---|
| [e9c677] | 421 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 422 | Point = Vector(0.5,-1.,-2.); | 
|---|
| [d74077] | 423 | CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 424 | Point = Vector(0.5,0.,0.); | 
|---|
| [e9c677] | 425 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 426 |  | 
|---|
|  | 427 | // simple test on slanted line | 
|---|
| [1bd79e] | 428 | Point = Vector(1.,1.,+3.); | 
|---|
| [d74077] | 429 | CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 430 | Point = Vector(0.5,0.5,0.); | 
|---|
| [e9c677] | 431 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 432 | Point = Vector(1.,1.,-4.); | 
|---|
| [d74077] | 433 | CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 434 | Point = Vector(0.5,0.5,0.); | 
|---|
| [e9c677] | 435 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 436 |  | 
|---|
|  | 437 | // simple test on first node | 
|---|
| [1bd79e] | 438 | Point = Vector(-1.,-1.,5.); | 
|---|
| [d74077] | 439 | CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 440 | Point = Vector(0.,0.,0.); | 
|---|
| [e9c677] | 441 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 442 |  | 
|---|
|  | 443 | // simple test on second node | 
|---|
| [1bd79e] | 444 | Point = Vector(0.,2.,5.); | 
|---|
| [d74077] | 445 | CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 446 | Point = Vector(0.,1.,0.); | 
|---|
| [e9c677] | 447 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 448 |  | 
|---|
|  | 449 | // simple test on third node | 
|---|
| [1bd79e] | 450 | Point = Vector(2.,0.,5.); | 
|---|
| [d74077] | 451 | CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| [1bd79e] | 452 | Point = Vector(1.,0.,0.); | 
|---|
| [e9c677] | 453 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 454 | }; | 
|---|