1// Boost.Geometry
2// Unit Test
3
4// Copyright (c) 2022 Barend Gehrels, Amsterdam, the Netherlands.
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#include <test_geometries/const_point.hpp>
11#include <test_geometries/custom_cartesian_point.hpp>
12
13#include <boost/geometry/algorithms/covered_by.hpp>
14#include <boost/geometry/algorithms/crosses.hpp>
15#include <boost/geometry/algorithms/disjoint.hpp>
16#include <boost/geometry/algorithms/intersects.hpp>
17#include <boost/geometry/algorithms/overlaps.hpp>
18#include <boost/geometry/algorithms/relate.hpp>
19#include <boost/geometry/algorithms/touches.hpp>
20#include <boost/geometry/algorithms/within.hpp>
21
22
23#include <geometry_test_common.hpp>
24
25
26template <typename Geometry1, typename Geometry2>
27void test_relate_const(Geometry1 const &geometry1, Geometry2 const &geometry2,
28 bool exp_cov, bool exp_crosses, bool exp_disjoint, bool exp_intersects,
29 bool exp_overlaps, bool exp_touches, bool exp_relate, bool exp_within)
30{
31 namespace bg = boost::geometry;
32
33 BOOST_CHECK_EQUAL(exp_cov, bg::covered_by(geometry1, geometry2));
34 BOOST_CHECK_EQUAL(exp_crosses, bg::crosses(geometry1, geometry2));
35 BOOST_CHECK_EQUAL(exp_disjoint, bg::disjoint(geometry1, geometry2));
36 BOOST_CHECK_EQUAL(exp_intersects, bg::intersects(geometry1, geometry2));
37 BOOST_CHECK_EQUAL(exp_overlaps, bg::overlaps(geometry1, geometry2));
38 BOOST_CHECK_EQUAL(exp_touches, bg::touches(geometry1, geometry2));
39 BOOST_CHECK_EQUAL(exp_relate, bg::relate(geometry1, geometry2, bg::de9im::mask("F0F******")));
40 BOOST_CHECK_EQUAL(exp_within, bg::within(geometry1, geometry2));
41}
42
43int test_main(int, char* [])
44{
45 ring_of_const_point const rectangle{{2, 2}, {2, 4}, {4, 4}, {4, 2}, {2, 2}};
46 ring_of_const_point const triangle{{1, 2}, {4, 5}, {5, 4}, {1, 2}};
47 linestring_of_const_point const diagonal{{0, 0}, {6, 6}};
48 linestring_of_const_point const horizontal{{0, 3}, {6, 3}};
49
50 // areal/areal
51 test_relate_const(geometry1: rectangle, geometry2: triangle, exp_cov: false, exp_crosses: false, exp_disjoint: false, exp_intersects: true, exp_overlaps: true, exp_touches: false, exp_relate: false, exp_within: false);
52
53 // point/areal
54 test_relate_const(geometry1: rectangle.front(), geometry2: triangle, exp_cov: false, exp_crosses: false, exp_disjoint: true, exp_intersects: false, exp_overlaps: false, exp_touches: false, exp_relate: false, exp_within: false);
55
56 // point/linear
57 test_relate_const(geometry1: rectangle.front(), geometry2: diagonal, exp_cov: true, exp_crosses: false, exp_disjoint: false, exp_intersects: true, exp_overlaps: false, exp_touches: false, exp_relate: false, exp_within: true);
58
59 // linear/linear
60 test_relate_const(geometry1: horizontal, geometry2: diagonal, exp_cov: false, exp_crosses: true, exp_disjoint: false, exp_intersects: true, exp_overlaps: false, exp_touches: false, exp_relate: false, exp_within: false);
61
62 custom_cartesian_line l;
63 custom_cartesian_polygon poly;
64 bg::covered_by(geometry1: l, geometry2: poly);
65 bg::crosses(geometry1: l, geometry2: poly);
66 bg::disjoint(geometry1: l, geometry2: poly);
67 bg::intersects(geometry1: l, geometry2: poly);
68 bg::overlaps(geometry1: l, geometry2: poly);
69 bg::touches(geometry1: l, geometry2: poly);
70 bg::relate(geometry1: l, geometry2: poly, mask: bg::de9im::mask("F0F******"));
71 bg::within(geometry1: l, geometry2: poly);
72
73 return 0;
74}
75

source code of boost/libs/geometry/test/algorithms/relate/relate_const_custom.cpp