File: relate_const_custom.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (74 lines) | stat: -rw-r--r-- 2,876 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Boost.Geometry
// Unit Test

// Copyright (c) 2022 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <test_geometries/const_point.hpp>
#include <test_geometries/custom_cartesian_point.hpp>

#include <boost/geometry/algorithms/covered_by.hpp>
#include <boost/geometry/algorithms/crosses.hpp>
#include <boost/geometry/algorithms/disjoint.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/algorithms/overlaps.hpp>
#include <boost/geometry/algorithms/relate.hpp>
#include <boost/geometry/algorithms/touches.hpp>
#include <boost/geometry/algorithms/within.hpp>


#include <geometry_test_common.hpp>


template <typename Geometry1, typename Geometry2>
void test_relate_const(Geometry1 const &geometry1, Geometry2 const &geometry2,
    bool exp_cov, bool exp_crosses, bool exp_disjoint, bool exp_intersects,
    bool exp_overlaps, bool exp_touches, bool exp_relate, bool exp_within)
{
    namespace bg = boost::geometry;

    BOOST_CHECK_EQUAL(exp_cov, bg::covered_by(geometry1, geometry2));
    BOOST_CHECK_EQUAL(exp_crosses, bg::crosses(geometry1, geometry2));
    BOOST_CHECK_EQUAL(exp_disjoint, bg::disjoint(geometry1, geometry2));
    BOOST_CHECK_EQUAL(exp_intersects, bg::intersects(geometry1, geometry2));
    BOOST_CHECK_EQUAL(exp_overlaps, bg::overlaps(geometry1, geometry2));
    BOOST_CHECK_EQUAL(exp_touches, bg::touches(geometry1, geometry2));
    BOOST_CHECK_EQUAL(exp_relate, bg::relate(geometry1, geometry2, bg::de9im::mask("F0F******")));
    BOOST_CHECK_EQUAL(exp_within, bg::within(geometry1, geometry2));
}

int test_main(int, char* [])
{
    ring_of_const_point const rectangle{{2, 2}, {2, 4}, {4, 4}, {4, 2}, {2, 2}};
    ring_of_const_point const triangle{{1, 2}, {4, 5}, {5, 4}, {1, 2}};
    linestring_of_const_point const diagonal{{0, 0}, {6, 6}};
    linestring_of_const_point const horizontal{{0, 3}, {6, 3}};

    // areal/areal
    test_relate_const(rectangle, triangle, false, false, false, true, true, false, false, false);

    // point/areal
    test_relate_const(rectangle.front(), triangle, false, false, true, false, false, false, false, false);

    // point/linear
    test_relate_const(rectangle.front(), diagonal, true, false, false, true, false, false, false, true);

    // linear/linear
    test_relate_const(horizontal, diagonal, false, true, false, true, false, false, false, false);

    custom_cartesian_line l;
    custom_cartesian_polygon poly;
    bg::covered_by(l, poly);
    bg::crosses(l, poly);
    bg::disjoint(l, poly);
    bg::intersects(l, poly);
    bg::overlaps(l, poly);
    bg::touches(l, poly);
    bg::relate(l, poly, bg::de9im::mask("F0F******"));
    bg::within(l, poly);

    return 0;
}