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