| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| 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/>. | 
|---|
| 21 | */ | 
|---|
| 22 |  | 
|---|
| 23 | /* | 
|---|
| 24 | * Tesselation_BoundaryTriangleUnitTest.cpp | 
|---|
| 25 | * | 
|---|
| 26 | *  Created on: Jan 13, 2010 | 
|---|
| 27 | *      Author: heber | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | // include config.h | 
|---|
| 31 | #ifdef HAVE_CONFIG_H | 
|---|
| 32 | #include <config.h> | 
|---|
| 33 | #endif | 
|---|
| 34 |  | 
|---|
| 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> | 
|---|
| 42 | #include <iostream> | 
|---|
| 43 |  | 
|---|
| 44 | #include "CodePatterns/Log.hpp" | 
|---|
| 45 | #include "Helpers/defs.hpp" | 
|---|
| 46 | #include "Atom/TesselPoint.hpp" | 
|---|
| 47 | #include "LinearAlgebra/Plane.hpp" | 
|---|
| 48 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| 49 | #include "LinearAlgebra/VectorSet.hpp" | 
|---|
| 50 | #include "Tesselation/BoundaryPointSet.hpp" | 
|---|
| 51 | #include "Tesselation/BoundaryLineSet.hpp" | 
|---|
| 52 | #include "Tesselation/BoundaryTriangleSet.hpp" | 
|---|
| 53 | #include "Tesselation/CandidateForTesselation.hpp" | 
|---|
| 54 |  | 
|---|
| 55 | #include "Tesselation_BoundaryTriangleUnitTest.hpp" | 
|---|
| 56 |  | 
|---|
| 57 | #ifdef HAVE_TESTRUNNER | 
|---|
| 58 | #include "UnitTestMain.hpp" | 
|---|
| 59 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
| 60 |  | 
|---|
| 61 | const double TesselationBoundaryTriangleTest::SPHERERADIUS=2.; | 
|---|
| 62 |  | 
|---|
| 63 | /********************************************** Test classes **************************************/ | 
|---|
| 64 |  | 
|---|
| 65 | // Registers the fixture into the 'registry' | 
|---|
| 66 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest ); | 
|---|
| 67 |  | 
|---|
| 68 |  | 
|---|
| 69 | void TesselationBoundaryTriangleTest::createTriangle(const std::vector<Vector> &Vectors) | 
|---|
| 70 | { | 
|---|
| 71 | CPPUNIT_ASSERT_EQUAL( (size_t)NDIM, Vectors.size() ); | 
|---|
| 72 |  | 
|---|
| 73 | // create nodes | 
|---|
| 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 | } | 
|---|
| 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); | 
|---|
| 89 | Plane p(Vectors[0], Vectors[1], Vectors[2]); | 
|---|
| 90 | triangle->GetNormalVector(p.getNormal()); | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 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 |  | 
|---|
| 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 | } | 
|---|
| 118 |  | 
|---|
| 119 | void TesselationBoundaryTriangleTest::tearDown() | 
|---|
| 120 | { | 
|---|
| 121 | removeTriangle(); | 
|---|
| 122 | logger::purgeInstance(); | 
|---|
| 123 | errorLogger::purgeInstance(); | 
|---|
| 124 | } | 
|---|
| 125 |  | 
|---|
| 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 | { | 
|---|
| 212 | removeTriangle(); | 
|---|
| 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 ) ); | 
|---|
| 223 | } | 
|---|
| 224 | { | 
|---|
| 225 | removeTriangle(); | 
|---|
| 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 ) ); | 
|---|
| 237 | } | 
|---|
| 238 | { | 
|---|
| 239 | removeTriangle(); | 
|---|
| 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! | 
|---|
| 243 | // we test now against correct intersection | 
|---|
| 244 | const Vector testIntersection(14.6872,36.204,39.8043); | 
|---|
| 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 | } | 
|---|
| 252 | } | 
|---|
| 253 |  | 
|---|
| 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 |  | 
|---|
| 279 | removeTriangle(); | 
|---|
| 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 |  | 
|---|
| 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 | { | 
|---|
| 314 | removeTriangle(); | 
|---|
| 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) | 
|---|
| 319 | // testPoint2 is corrected version | 
|---|
| 320 | const Vector testPoint(27.56537519896,13.40256646925,6.672946688134); | 
|---|
| 321 | const Vector testPoint2(14.6872,36.204,39.8043); | 
|---|
| 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); | 
|---|
| 329 | CPPUNIT_ASSERT ( testPoint != testIntersection ); | 
|---|
| 330 | CPPUNIT_ASSERT ( testPoint2 == testIntersection ); | 
|---|
| 331 | } | 
|---|
| 332 | } | 
|---|
| 333 |  | 
|---|
| 334 | /** UnitTest for Tesselation::IsInnerPoint() | 
|---|
| 335 | */ | 
|---|
| 336 | void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest() | 
|---|
| 337 | { | 
|---|
| 338 | Vector TestIntersection; | 
|---|
| 339 | Vector Point; | 
|---|
| 340 |  | 
|---|
| 341 | // simple test on y line | 
|---|
| 342 | Point = Vector(-1.,0.5,0.); | 
|---|
| 343 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 344 | Point = Vector(0.,0.5,0.); | 
|---|
| 345 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 346 | Point = Vector(-4.,0.5,0.); | 
|---|
| 347 | CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 348 | Point = Vector(0.,0.5,0.); | 
|---|
| 349 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 350 |  | 
|---|
| 351 | // simple test on x line | 
|---|
| 352 | Point = Vector(0.5,-1.,0.); | 
|---|
| 353 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 354 | Point = Vector(0.5,0.,0.); | 
|---|
| 355 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 356 | Point = Vector(0.5,-6.,0.); | 
|---|
| 357 | CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 358 | Point = Vector(0.5,0.,0.); | 
|---|
| 359 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 360 |  | 
|---|
| 361 | // simple test on slanted line | 
|---|
| 362 | Point = Vector(1.,1.,0.); | 
|---|
| 363 | CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 364 | Point = Vector(0.5,0.5,0.); | 
|---|
| 365 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 366 | Point = Vector(5.,5.,0.); | 
|---|
| 367 | CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 368 | Point = Vector(0.5,0.5,0.); | 
|---|
| 369 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 370 |  | 
|---|
| 371 | // simple test on first node | 
|---|
| 372 | Point = Vector(-1.,-1.,0.); | 
|---|
| 373 | CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 374 | Point = Vector(0.,0.,0.); | 
|---|
| 375 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 376 |  | 
|---|
| 377 | // simple test on second node | 
|---|
| 378 | Point = Vector(0.,2.,0.); | 
|---|
| 379 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 380 | Point = Vector(0.,1.,0.); | 
|---|
| 381 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 382 |  | 
|---|
| 383 | // simple test on third node | 
|---|
| 384 | Point = Vector(2.,0.,0.); | 
|---|
| 385 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 386 | Point = Vector(1.,0.,0.); | 
|---|
| 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 | 
|---|
| 398 | Point = Vector(1./3.,1./3.,+5.); | 
|---|
| 399 | CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 400 | Point = Vector(1./3.,1./3.,0.); | 
|---|
| 401 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 402 | Point = Vector(1./3.,1./3.,-5.); | 
|---|
| 403 | CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 404 | Point = Vector(1./3.,1./3.,0.); | 
|---|
| 405 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 406 |  | 
|---|
| 407 | // simple test on y line | 
|---|
| 408 | Point = Vector(-1.,0.5,+2.); | 
|---|
| 409 | CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 410 | Point = Vector(0.,0.5,0.); | 
|---|
| 411 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 412 | Point = Vector(-1.,0.5,-3.); | 
|---|
| 413 | CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 414 | Point = Vector(0.,0.5,0.); | 
|---|
| 415 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 416 |  | 
|---|
| 417 | // simple test on x line | 
|---|
| 418 | Point = Vector(0.5,-1.,+1.); | 
|---|
| 419 | CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 420 | Point = Vector(0.5,0.,0.); | 
|---|
| 421 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 422 | Point = Vector(0.5,-1.,-2.); | 
|---|
| 423 | CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 424 | Point = Vector(0.5,0.,0.); | 
|---|
| 425 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 426 |  | 
|---|
| 427 | // simple test on slanted line | 
|---|
| 428 | Point = Vector(1.,1.,+3.); | 
|---|
| 429 | CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 430 | Point = Vector(0.5,0.5,0.); | 
|---|
| 431 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 432 | Point = Vector(1.,1.,-4.); | 
|---|
| 433 | CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 434 | Point = Vector(0.5,0.5,0.); | 
|---|
| 435 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 436 |  | 
|---|
| 437 | // simple test on first node | 
|---|
| 438 | Point = Vector(-1.,-1.,5.); | 
|---|
| 439 | CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 440 | Point = Vector(0.,0.,0.); | 
|---|
| 441 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 442 |  | 
|---|
| 443 | // simple test on second node | 
|---|
| 444 | Point = Vector(0.,2.,5.); | 
|---|
| 445 | CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 446 | Point = Vector(0.,1.,0.); | 
|---|
| 447 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 448 |  | 
|---|
| 449 | // simple test on third node | 
|---|
| 450 | Point = Vector(2.,0.,5.); | 
|---|
| 451 | CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) ); | 
|---|
| 452 | Point = Vector(1.,0.,0.); | 
|---|
| 453 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| 454 | }; | 
|---|