• 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 //[covered_by
11 //` Checks if the first geometry is inside or on border the second geometry
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 first geometry is inside or on border the second geometry.
24     bg::model::polygon<bg::model::d2::point_xy<double> > poly1;
25     bg::read_wkt("POLYGON((0 2,0 3,2 4,1 2,0 2))", poly1);
26     bg::model::polygon<bg::model::d2::point_xy<double> > poly2;
27     bg::read_wkt("POLYGON((0 4,3 4,2 2,0 1,0 4))", poly2);
28     bool check_covered = bg::covered_by(poly1, poly2);
29     if (check_covered) {
30          std::cout << "Covered: Yes" << std::endl;
31     } else {
32         std::cout << "Covered: 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_covered = bg::covered_by(poly1, poly3);
38     if (check_covered) {
39          std::cout << "Covered: Yes" << std::endl;
40     } else {
41         std::cout << "Covered: No" << std::endl;
42     }
43 
44     // This should return true since both polygons are same, so they are lying on each other.
45     check_covered = bg::covered_by(poly1, poly1);
46     if (check_covered) {
47          std::cout << "Covered: Yes" << std::endl;
48     } else {
49         std::cout << "Covered: No" << std::endl;
50     }
51 
52     return 0;
53 }
54 
55 //]
56 
57 
58 //[covered_by_output
59 /*`
60 Output:
61 [pre
62 Covered: Yes
63 
64 [$img/algorithms/covered_by.png]
65 
66 Covered: No
67 Covered: Yes
68 ]
69 */
70 //]
71