Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Algorithms_ClosestPoints_tests.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 #include <gtest/gtest.h>
43 
44 #include <ACG/Math/VectorT.hh>
45 #include <ACG/Geometry/Algorithms.hh>
46 
47 #include "../Math/MatrixTestHelper.hh"
48 
49 namespace {
50 
51 TEST(Algorithms_ClosestPoints, closestPointTri_inside) {
52  // Closest point inside
53  {
54  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
55  ACG::Vec3d(0.180189728737, 0.284434795380, 0.685222446918),
56  ACG::Vec3d(0.780881822109, -0.711405277252, 0.000000000000),
57  ACG::Vec3d(-1.080165147781, 0.470909714699, 0.000000000000),
58  ACG::Vec3d(0.663306236267, 1.208429455757, 0.000000000000)
59  );
60  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(0.180189728737, 0.284434795380, 0.000000000000)));
61  }
62  {
63  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
64  ACG::Vec3d(0.180189728737, 0.284434795380, 0.685222446918),
65  ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407),
66  ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581),
67  ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)
68  );
69  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(0.379620872542, 0.129005603666, 0.039932640059)));
70  }
71  {
72  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
73  ACG::Vec3d(0.383401751518, -0.044320285320, -0.729106009007),
74  ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407),
75  ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581),
76  ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)
77  );
78  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(0.165861088939, 0.125222789570, -0.025220099004)));
79  }
80 }
81 
82 TEST(Algorithms_ClosestPoints, closestPointTri_onEdge) {
83  // Closest point on edges.
84  {
85  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
86  ACG::Vec3d(2.194746255875, 0.654435634613, 1.605020284653),
87  ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407),
88  ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581),
89  ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)
90  );
91  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(0.826052171821, 0.158427751505, 0.170818395715)));
92  }
93  {
94  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
95  ACG::Vec3d(-1.639497995377, -1.687432765961, 0.645231306553),
96  ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407),
97  ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581),
98  ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)
99  );
100  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-0.312445889897, -0.008722876212, -0.140780953244)));
101  }
102  {
103  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
104  ACG::Vec3d(-0.954960584641, 3.141639709473, -0.399959266186),
105  ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407),
106  ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581),
107  ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)
108  );
109  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-0.091698979114, 0.882223932862, -0.287157561834)));
110  }
111  {
112  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
113  ACG::Vec3d(-0.326786577702, -0.595147013664, -0.012022850104),
114  ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407),
115  ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581),
116  ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)
117  );
118  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-0.062953975601, -0.153517634035, -0.028797485905)));
119  }
120 }
121 
122 TEST(Algorithms_ClosestPoints, closestPointTri_onCorner) {
123  {
124  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
125  ACG::Vec3d(-1.840421676636, 0.351687341928, -1.691396117210),
126  ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407),
127  ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581),
128  ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)
129  );
130  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581)));
131  }
132  {
133  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
134  ACG::Vec3d(1.548038601875, 1.783731102943, -0.995657980442),
135  ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407),
136  ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581),
137  ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)
138  );
139  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)));
140  }
141  {
142  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
143  ACG::Vec3d(1.674694657326, -1.574745774269, -0.140889823437),
144  ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407),
145  ACG::Vec3d(-1.138887882233, 0.470909774303, -0.511726200581),
146  ACG::Vec3d(0.738806843758, 1.208429455757, -0.109056398273)
147  );
148  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(0.898327171803, -0.711405336857, 0.402669787407)));
149  }
150 }
151 
152 TEST(Algorithms_ClosestPoints, closestPointTri_degenerate) {
153  {
154  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
155  ACG::Vec3d(0.379400968552, -0.866840600967, -1.375681400299),
156  ACG::Vec3d(-2.827600002289, -1.685648560524, -0.758169531822),
157  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070630312),
158  ACG::Vec3d(-0.661723732948, 1.627503752708, -0.181971758604)
159  );
160  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-1.568279320469, 0.240740866643, -0.423146806300)));
161  }
162  {
163  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
164  ACG::Vec3d(0.842265009880, 3.628707885742, -0.395066857338),
165  ACG::Vec3d(-2.827600002289, -1.685648560524, -0.758169531822),
166  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070630312),
167  ACG::Vec3d(-0.661723732948, 1.627503752708, -0.181971758604)
168  );
169  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-0.661723732948, 1.627503752708, -0.181971758604)));
170  }
171  {
172  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
173  ACG::Vec3d(0.842265009880, 3.628707885742, -0.395066857338),
174  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070600510),
175  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070630312),
176  ACG::Vec3d(-0.661723732948, 1.627503752708, -0.181971758604)
177  );
178  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-0.661723732948, 1.627503752708, -0.181971758604)));
179  }
180  {
181  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
182  ACG::Vec3d(-3.731231689453, -2.141752481461, -0.150896072388),
183  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070600510),
184  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070630312),
185  ACG::Vec3d(-0.661723732948, 1.627503752708, -0.181971758604)
186  );
187  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070600510)));
188  }
189  {
190  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
191  ACG::Vec3d(-0.966588973999, 0.534245491028, 0.345366060734),
192  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070600510),
193  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070630312),
194  ACG::Vec3d(-0.661723732948, 1.627503752708, -0.181971758604)
195  );
196  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-1.200293249127, 0.803651109932, -0.325249806970)));
197  }
198  {
199  ACG::Vec3d closest_point = ACG::Geometry::closestPointTri(
200  ACG::Vec3d(-0.966588973999, 0.534245491028, 0.345366060734),
201  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070600510),
202  ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070630312),
203  ACG::Vec3d(-1.744661808014, -0.029072403908, -0.470070600510)
204  );
205  EXPECT_TRUE(areClose(closest_point, ACG::Vec3d(-1.744661808014, -0.029072359204, -0.470070600510)));
206  }
207 }
208 
209 } /* namespace */