1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2015 Barend Gehrels, Amsterdam, the Netherlands.
5 
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 #include <cstddef>
11 #include <string>
12 
13 #include <boost/geometry/algorithms/is_convex.hpp>
14 
15 #include <geometry_test_common.hpp>
16 
17 #include <boost/geometry/algorithms/correct.hpp>
18 #include <boost/geometry/io/wkt/wkt.hpp>
19 #include <boost/geometry/strategies/strategies.hpp>
20 #include <boost/geometry/geometries/point_xy.hpp>
21 #include <boost/geometry/geometries/ring.hpp>
22 
23 
24 template <typename Geometry>
test_one(std::string const & case_id,std::string const & wkt,bool expected)25 void test_one(std::string const& case_id, std::string const& wkt, bool expected)
26 {
27     Geometry geometry;
28     bg::read_wkt(wkt, geometry);
29     bg::correct(geometry);
30 
31     bool detected = bg::is_convex(geometry);
32     BOOST_CHECK_MESSAGE(detected == expected,
33         "Not as expected, case: " << case_id
34             << " / expected: " << expected
35             << " / detected: " << detected);
36 }
37 
38 
39 template <typename P>
test_all()40 void test_all()
41 {
42     // rectangular, with concavity
43     std::string const concave1 = "polygon((1 1, 1 4, 3 4, 3 3, 4 3, 4 4, 5 4, 5 1, 1 1))";
44     std::string const triangle = "polygon((1 1, 1 4, 5 1, 1 1))";
45 
46     test_one<bg::model::ring<P> >("triangle", triangle, true);
47     test_one<bg::model::ring<P> >("concave1", concave1, false);
48     test_one<bg::model::ring<P, false, false> >("triangle", triangle, true);
49     test_one<bg::model::ring<P, false, false> >("concave1", concave1, false);
50 
51     test_one<bg::model::box<P> >("box", "box(0 0,2 2)", true);
52 }
53 
54 
test_main(int,char * [])55 int test_main(int, char* [])
56 {
57     test_all<bg::model::d2::point_xy<int> >();
58     test_all<bg::model::d2::point_xy<double> >();
59 
60     return 0;
61 }
62