RINGMesh  Version 5.0.0
A programming library for geological model meshes
test-geometry.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2017, Association Scientifique pour la Geologie et ses
3  * Applications (ASGA). All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ASGA nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASGA BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * http://www.ring-team.org
28  *
29  * RING Project
30  * Ecole Nationale Superieure de Geologie - GeoRessources
31  * 2 Rue du Doyen Marcel Roubault - TSA 70605
32  * 54518 VANDOEUVRE-LES-NANCY
33  * FRANCE
34  */
35 
36 #include <ringmesh/ringmesh_tests_config.h>
37 
39 
44 using namespace RINGMesh;
45 
47 {
48  Logger::out( "TEST", "Test triangle barycentric coordinates" );
49  vec3 p0( 0, 0, 0 );
50  vec3 p1( 1, 0, 0 );
51  vec3 p2( 0, 1, 0 );
52 
53  std::array< double, 3 > lambdas;
54  std::tie( std::ignore, lambdas ) =
55  triangle_barycentric_coordinates( vec3( 0.25, 0.25, 0 ), p0, p1, p2 );
56  if( lambdas[0] != 0.5 || lambdas[1] != 0.25 || lambdas[2] != 0.25 )
57  {
58  throw RINGMeshException(
59  "TEST", "Error in triangle barycentric coordinates" );
60  }
61  std::tie( std::ignore, lambdas ) =
62  triangle_barycentric_coordinates( vec3( 0.5, 0.5, 0 ), p0, p1, p2 );
63  if( lambdas[0] != 0 || lambdas[1] != 0.5 || lambdas[2] != 0.5 )
64  {
65  throw RINGMeshException(
66  "TEST", "Error in triangle barycentric coordinates" );
67  }
68  std::tie( std::ignore, lambdas ) =
69  triangle_barycentric_coordinates( vec3( 1, 1, 0 ), p0, p1, p2 );
70  if( lambdas[0] != -1 || lambdas[1] != 1 || lambdas[2] != 1 )
71  {
72  throw RINGMeshException(
73  "TEST", "Error in triangle barycentric coordinates" );
74  }
75 }
76 
78 {
79  Logger::out( "TEST", "Test point plane distance" );
80 
81  vec3 test0{ 1, 1, 1 };
82  Geometry::Plane plane0{ { 0, 0, 2 }, { 0, 0, 0 } };
83  vec3 projected0;
84  std::tie( std::ignore, projected0 ) =
85  Distance::point_to_plane( test0, plane0 );
86  if( projected0 != vec3{ 1, 1, 0 } )
87  {
88  throw RINGMeshException( "TEST", "Error in point plane distance" );
89  }
90 
91  vec3 test1{ 0, 0.5, 1 };
92  Geometry::Plane plane1{ { 1, 0, 0 }, { 1, 1, 1 } };
93  vec3 projected1;
94  std::tie( std::ignore, projected1 ) =
95  Distance::point_to_plane( test1, plane1 );
96  if( projected1 != vec3{ 1, 0.5, 1 } )
97  {
98  throw RINGMeshException( "TEST", "Error in point plane distance" );
99  }
100 }
101 
102 int main()
103 {
104  using namespace RINGMesh;
105 
106  try
107  {
109 
110  Logger::out( "TEST", "Test geometric tools" );
111 
114  }
115  catch( const RINGMeshException& e )
116  {
117  Logger::err( e.category(), e.what() );
118  return 1;
119  }
120  catch( const std::exception& e )
121  {
122  Logger::err( "Exception", e.what() );
123  return 1;
124  }
125  Logger::out( "TEST", "SUCCESS" );
126  return 0;
127 }
vecn< 3 > vec3
Definition: types.h:76
void test_point_plane_distance()
std::tuple< bool, std::array< double, 3 > > RINGMESH_API triangle_barycentric_coordinates(const vec3 &p, const vec3 &p0, const vec3 &p1, const vec3 &p2)
Definition: geometry.cpp:118
void test_triangle_barycentric_coordinates()
static void err(const std::string &feature, const Args &... args)
Definition: logger.h:68
static void out(const std::string &feature, const Args &... args)
Definition: logger.h:61
std::tuple< double, vec3 > RINGMESH_API point_to_plane(const Geometry::Point3D &point, const Geometry::Plane &plane)
const std::string & category() const
Definition: common.h:165
int main()
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
void RINGMESH_API default_configure()
Definition: common.cpp:99