1+ // Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
2+ //
3+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4+ // of this software and associated documentation files (the "Software"), to deal
5+ // in the Software without restriction, including without limitation the rights
6+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+ // copies of the Software, and to permit persons to whom the Software is
8+ // furnished to do so, subject to the following conditions:
9+ //
10+ // The above copyright notice and this permission notice shall be included in
11+ // all copies or substantial portions of the Software.
12+ //
13+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+ // THE SOFTWARE.
20+ using NUnit . Framework ;
21+
22+ namespace SharpDX . Tests
23+ {
24+ [ TestFixture ]
25+ public class MathCollisionTest
26+ {
27+ [ Test ]
28+ public void ClosestPointPointTriangleTest ( )
29+ {
30+ Assert . AreEqual ( ClosestPointPointTriangle ( new Vector3 ( 0 , 0 , 0 ) , new Vector3 ( 1 , 1 , 0 ) , new Vector3 ( 2 , 2 , 0 ) , new Vector3 ( 3 , 1 , 0 ) ) , new Vector3 ( 1 , 1 , 0 ) ) ;
31+ Assert . AreEqual ( ClosestPointPointTriangle ( new Vector3 ( 1 , 1 , 0 ) , new Vector3 ( 1 , 1 , 0 ) , new Vector3 ( 2 , 2 , 0 ) , new Vector3 ( 3 , 1 , 0 ) ) , new Vector3 ( 1 , 1 , 0 ) ) ;
32+ Assert . AreEqual ( ClosestPointPointTriangle ( new Vector3 ( 2 , 3 , 0 ) , new Vector3 ( 1 , 1 , 0 ) , new Vector3 ( 2 , 2 , 0 ) , new Vector3 ( 3 , 1 , 0 ) ) , new Vector3 ( 2 , 2 , 0 ) ) ;
33+ Assert . AreEqual ( ClosestPointPointTriangle ( new Vector3 ( 4 , 1 , 0 ) , new Vector3 ( 1 , 1 , 0 ) , new Vector3 ( 2 , 2 , 0 ) , new Vector3 ( 3 , 1 , 0 ) ) , new Vector3 ( 3 , 1 , 0 ) ) ;
34+ Assert . AreEqual ( ClosestPointPointTriangle ( new Vector3 ( 1 , 2 , 0 ) , new Vector3 ( 1 , 1 , 0 ) , new Vector3 ( 2 , 2 , 0 ) , new Vector3 ( 3 , 1 , 0 ) ) , new Vector3 ( 1.5f , 1.5f , 0 ) ) ;
35+ Assert . AreEqual ( ClosestPointPointTriangle ( new Vector3 ( 3 , 2 , 0 ) , new Vector3 ( 1 , 1 , 0 ) , new Vector3 ( 2 , 2 , 0 ) , new Vector3 ( 3 , 1 , 0 ) ) , new Vector3 ( 2.5f , 1.5f , 0 ) ) ;
36+ Assert . AreEqual ( ClosestPointPointTriangle ( new Vector3 ( 2 , 0 , 0 ) , new Vector3 ( 1 , 1 , 0 ) , new Vector3 ( 2 , 2 , 0 ) , new Vector3 ( 3 , 1 , 0 ) ) , new Vector3 ( 2 , 1 , 0 ) ) ;
37+
38+ Assert . AreEqual ( ClosestPointPointTriangle ( new Vector3 ( 2 , 1.5f , 1 ) , new Vector3 ( 1 , 1 , 0 ) , new Vector3 ( 2 , 2 , 0 ) , new Vector3 ( 3 , 1 , 0 ) ) , new Vector3 ( 2 , 1.5f , 0 ) ) ;
39+ }
40+ private static Vector3 ClosestPointPointTriangle ( Vector3 point , Vector3 vertex1 , Vector3 vertex2 , Vector3 vertex3 )
41+ {
42+ Vector3 result ;
43+ Collision . ClosestPointPointTriangle ( ref point , ref vertex1 , ref vertex2 , ref vertex3 , out result ) ;
44+ return result ;
45+ }
46+ }
47+ }
0 commit comments