1 /**
2  *   SFCGAL
3  *
4  *   Copyright (C) 2012-2013 Oslandia <infos@oslandia.com>
5  *   Copyright (C) 2012-2013 IGN (http://www.ign.fr)
6  *
7  *   This library is free software; you can redistribute it and/or
8  *   modify it under the terms of the GNU Library General Public
9  *   License as published by the Free Software Foundation; either
10  *   version 2 of the License, or (at your option) any later version.
11  *
12  *   This library is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *   Library General Public License for more details.
16 
17  *   You should have received a copy of the GNU Library General Public
18  *   License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <boost/test/unit_test.hpp>
21 
22 #include <SFCGAL/Point.h>
23 #include <SFCGAL/LineString.h>
24 #include <SFCGAL/Polygon.h>
25 #include <SFCGAL/Triangle.h>
26 #include <SFCGAL/PolyhedralSurface.h>
27 #include <SFCGAL/TriangulatedSurface.h>
28 #include <SFCGAL/Solid.h>
29 #include <SFCGAL/GeometryCollection.h>
30 #include <SFCGAL/MultiPoint.h>
31 #include <SFCGAL/MultiLineString.h>
32 #include <SFCGAL/MultiPolygon.h>
33 #include <SFCGAL/MultiSolid.h>
34 #include <SFCGAL/io/wkt.h>
35 #include <SFCGAL/algorithm/connection.h>
36 
37 using namespace boost::unit_test ;
38 using namespace SFCGAL ;
39 using namespace SFCGAL::algorithm ;
40 
41 BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_Connected )
42 
BOOST_AUTO_TEST_CASE(allFine)43 BOOST_AUTO_TEST_CASE( allFine )
44 {
45     std::unique_ptr< Geometry > geom ( io::readWkt(
46                                          "POLYHEDRALSURFACE(((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\
47                                    ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\
48                                    ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\
49                                    ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\
50                                    ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\
51                                    ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)))" ) );
52 
53     SurfaceGraph graph( geom->as< PolyhedralSurface >() );
54     BOOST_CHECK_MESSAGE( isConnected( graph ) , "not connected" );
55     BOOST_CHECK_MESSAGE( isClosed( graph ) , "not closed" );
56 }
57 
BOOST_AUTO_TEST_CASE(notConnected)58 BOOST_AUTO_TEST_CASE( notConnected )
59 {
60     std::unique_ptr< Geometry > geom ( io::readWkt(
61                                          "POLYHEDRALSURFACE(((0 0 -1, 0 1 -1, 1 1 -1, 1 0 -1, 0 0 -1)),\
62                                    ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\
63                                    ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\
64                                    ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\
65                                    ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\
66                                    ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)))" ) );
67 
68     SurfaceGraph graph( geom->as< PolyhedralSurface >() );
69     BOOST_CHECK_MESSAGE( !isConnected( graph ) , "connected" );
70     BOOST_CHECK_MESSAGE( !isClosed( graph ) , "closed" );
71 }
72 
BOOST_AUTO_TEST_CASE(notClosed)73 BOOST_AUTO_TEST_CASE( notClosed )
74 {
75     std::unique_ptr< Geometry > geom ( io::readWkt(
76                                          "POLYHEDRALSURFACE(((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\
77                                    ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\
78                                    ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\
79                                    ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\
80                                    ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)))" ) );
81 
82     SurfaceGraph graph( geom->as< PolyhedralSurface >() );
83     BOOST_CHECK_MESSAGE( isConnected( graph ) , "not connected" );
84     BOOST_CHECK_MESSAGE( !isClosed( graph ) , "closed" );
85 
86 }
87 
88 BOOST_AUTO_TEST_SUITE_END()
89