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_two_geometries
11 //` Checks if two geometries have at least one touching point (tangent - non overlapping)
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 touch
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((0 0,0 -4,-4 -4,-4 0,0 0))", poly2);
28 bool check_touches = bg::touches(poly1, poly2);
29 if (check_touches) {
30 std::cout << "Touches: Yes" << std::endl;
31 } else {
32 std::cout << "Touches: No" << std::endl;
33 }
34
35 bg::model::polygon<bg::model::d2::point_xy<double> > poly3;
36 bg::read_wkt("POLYGON((1 1,0 -4,-4 -4,-4 0,1 1))", poly3);
37 check_touches = bg::touches(poly1, poly3);
38 if (check_touches) {
39 std::cout << "Touches: Yes" << std::endl;
40 } else {
41 std::cout << "Touches: No" << std::endl;
42 }
43
44 return 0;
45 }
46
47 //]
48
49
50 //[touches_two_geometries_output
51 /*`
52 Output:
53 [pre
54 Touches: Yes
55
56 [$img/algorithms/touches_two_geometries.png]
57
58 Touches: No
59 ]
60 */
61 //]
62