File: test_perimeter.hpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (124 lines) | stat: -rw-r--r-- 3,768 bytes parent folder | download | duplicates (6)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test

// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.

// This file was modified by Oracle on 2021.
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// 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)

#ifndef BOOST_GEOMETRY_TEST_PERIMETER_HPP
#define BOOST_GEOMETRY_TEST_PERIMETER_HPP


#include <boost/variant/variant.hpp>

#include <geometry_test_common.hpp>

#include <boost/geometry/algorithms/perimeter.hpp>
#include <boost/geometry/geometries/geometry_collection.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/io/wkt/read.hpp>


template <typename Geometry>
void test_perimeter(Geometry const& geometry, long double expected_perimeter)
{
    typename bg::default_length_result<Geometry>::type
        perimeter = bg::perimeter(geometry);

#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::ostringstream out;
    out << typeid(typename bg::coordinate_type<Geometry>::type).name()
        << std::endl
        //<< typeid(typename bg::default_perimeter_result<Geometry>::type).name()
        << std::endl
        << "perimeter : " << bg::perimeter(geometry)
        << std::endl;
    std::cout << out.str();
#endif

    BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);

    boost::variant<Geometry> v(geometry);
    perimeter = bg::perimeter(v);

    BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);

    bg::model::geometry_collection<boost::variant<Geometry>> gc{v};
    perimeter = bg::perimeter(gc);

    BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
}


template <typename Geometry, typename Strategy>
void test_perimeter(Geometry const& geometry, long double expected_perimeter, Strategy strategy)
{
    typename bg::default_length_result<Geometry>::type
        perimeter = bg::perimeter(geometry, strategy);

#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::ostringstream out;
    out << typeid(typename bg::coordinate_type<Geometry>::type).name()
        << std::endl
        //<< typeid(typename bg::default_perimeter_result<Geometry>::type).name()
        << std::endl
        << "perimeter : " << bg::perimeter(geometry, strategy)
        << std::endl;
    std::cout << out.str();
#endif

    BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);

    boost::variant<Geometry> v(geometry);
    perimeter = bg::perimeter(v, strategy);

    BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);

    bg::model::geometry_collection<boost::variant<Geometry>> gc{v};
    perimeter = bg::perimeter(gc, strategy);

    BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
}

template <typename Geometry>
void test_geometry(std::string const& wkt, double expected_perimeter)
{
    Geometry geometry;
    bg::read_wkt(wkt, geometry);
    test_perimeter(geometry, expected_perimeter);
}

template <typename Geometry, typename Strategy>
void test_geometry(std::string const& wkt, double expected_perimeter, Strategy strategy)
{
    Geometry geometry;
    bg::read_wkt(wkt, geometry);
    boost::variant<Geometry> v(geometry);

    test_perimeter(geometry, expected_perimeter, strategy);
#if !defined(BOOST_GEOMETRY_TEST_DEBUG)
    test_perimeter(v, expected_perimeter, strategy);
#endif
}

template <typename Geometry>
void test_empty_input(Geometry const& geometry)
{
    try
    {
        bg::perimeter(geometry);
    }
    catch(bg::empty_input_exception const& )
    {
        return;
    }
    BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
}

#endif