• 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 //[disjoint
11 //` Checks if two geometries are disjoint
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 two geometries are disjoint, which means that two geometries have zero intersection.
24     bg::model::polygon<bg::model::d2::point_xy<double> > poly1;
25     bg::read_wkt("POLYGON((0 2,-2 0,-4 2,-2 4,0 2))", poly1);
26     bg::model::polygon<bg::model::d2::point_xy<double> > poly2;
27     bg::read_wkt("POLYGON((2 2,4 4,6 2,4 0,2 2))", poly2);
28     bool check_disjoint = bg::disjoint(poly1, poly2);
29     if (check_disjoint) {
30          std::cout << "Disjoint: Yes" << std::endl;
31     } else {
32         std::cout << "Disjoint: No" << std::endl;
33     }
34 
35     bg::model::polygon<bg::model::d2::point_xy<double> > poly3;
36     bg::read_wkt("POLYGON((0 2,2 4,4 2,2 0,0 2))", poly3);
37     check_disjoint = bg::disjoint(poly1, poly3);
38     if (check_disjoint) {
39          std::cout << "Disjoint: Yes" << std::endl;
40     } else {
41         std::cout << "Disjoint: No" << std::endl;
42     }
43 
44     return 0;
45 }
46 
47 //]
48 
49 
50 //[disjoint_output
51 /*`
52 Output:
53 [pre
54 Disjoint: Yes
55 Disjoint: No
56 
57 [$img/algorithms/disjoint.png]
58 
59 ]
60 */
61 //]
62