• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // QuickBook Example
3 
4 // Copyright (c) 2020 Digvijay Janartha, Hamirpur, India.
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 //[touches_one_geometry
11 //` Checks if a geometry has at least one touching point (self-tangency)
12 
13 #include <iostream>
14 
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/polygon.hpp>
18 
19 namespace bg = boost::geometry; /*< Convenient namespace alias >*/
20 
main()21 int main()
22 {
23     // Checks if the geometry has self-tangency.
24     bg::model::polygon<bg::model::d2::point_xy<double> > poly1;
25     bg::read_wkt("POLYGON((0 0,0 3,2 3,2 2,1 2,1 1,2 1,2 2,3 2,3 0,0 0))", poly1);
26     bool check_touches = bg::touches(poly1);
27     if (check_touches) {
28          std::cout << "Touches: Yes" << std::endl;
29     } else {
30         std::cout << "Touches: No" << std::endl;
31     }
32 
33     bg::model::polygon<bg::model::d2::point_xy<double> > poly2;
34     bg::read_wkt("POLYGON((0 0,0 4,4 4,4 0,2 3,0 0))", poly2);
35     check_touches = bg::touches(poly2);
36     if (check_touches) {
37          std::cout << "Touches: Yes" << std::endl;
38     } else {
39         std::cout << "Touches: No" << std::endl;
40     }
41 
42     return 0;
43 }
44 
45 //]
46 
47 
48 //[touches_one_geometry_output
49 /*`
50 Output:
51 [pre
52 Touches: Yes
53 
54 [$img/algorithms/touches_one_geometry.png]
55 
56 Touches: No
57 ]
58 */
59 //]
60