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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#include "catch.hpp"
#include <osmium/area/assembler.hpp>
#include <osmium/area/assembler_config.hpp>
#include <osmium/builder/attr.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/osm/area.hpp>
#include <osmium/osm/way.hpp>
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
TEST_CASE("Build area from way") {
osmium::memory::Buffer buffer{10240};
const auto wpos = osmium::builder::add_way(buffer,
_id(1),
_nodes({
{1, {1.0, 1.0}},
{2, {1.0, 2.0}},
{3, {2.0, 2.0}},
{4, {2.0, 1.0}},
{1, {1.0, 1.0}}
})
);
const osmium::area::AssemblerConfig config;
osmium::area::Assembler assembler{config};
osmium::memory::Buffer area_buffer{10240};
REQUIRE(assembler(buffer.get<osmium::Way>(wpos), area_buffer));
const auto& area = area_buffer.get<osmium::Area>(0);
REQUIRE(area.from_way());
REQUIRE(area.id() == 2);
const auto it = area.outer_rings().begin();
REQUIRE(it != area.outer_rings().end());
REQUIRE(it->size() == 5);
const auto& s = assembler.stats();
REQUIRE(s.area_simple_case == 1);
REQUIRE(s.from_ways == 1);
REQUIRE(s.nodes == 4);
REQUIRE(s.duplicate_nodes == 0);
REQUIRE(s.invalid_locations == 0);
}
TEST_CASE("Build area from way with duplicate nodes") {
osmium::memory::Buffer buffer{10240};
const auto wpos = osmium::builder::add_way(buffer,
_id(1),
_nodes({
{1, {1.0, 1.0}},
{2, {1.0, 2.0}},
{3, {2.0, 2.0}},
{3, {2.0, 2.0}},
{4, {2.0, 1.0}},
{1, {1.0, 1.0}}
})
);
const osmium::area::AssemblerConfig config;
osmium::area::Assembler assembler{config};
osmium::memory::Buffer area_buffer{10240};
REQUIRE(assembler(buffer.get<osmium::Way>(wpos), area_buffer));
const auto& area = area_buffer.get<osmium::Area>(0);
REQUIRE(area.from_way());
REQUIRE(area.id() == 2);
const auto it = area.outer_rings().begin();
REQUIRE(it != area.outer_rings().end());
REQUIRE(it->size() == 5);
const auto& s = assembler.stats();
REQUIRE(s.area_simple_case == 1);
REQUIRE(s.from_ways == 1);
REQUIRE(s.nodes == 4);
REQUIRE(s.duplicate_nodes == 1);
REQUIRE(s.invalid_locations == 0);
}
TEST_CASE("Build area from way with invalid location") {
osmium::memory::Buffer buffer{10240};
const auto wpos = osmium::builder::add_way(buffer,
_id(1),
_nodes({
{1, {1.0, 1.0}},
{2, {1.0, 2.0}},
{3},
{4, {2.0, 1.0}},
{1, {1.0, 1.0}}
})
);
const osmium::area::AssemblerConfig config;
osmium::area::Assembler assembler{config};
osmium::memory::Buffer area_buffer{10240};
REQUIRE_FALSE(assembler(buffer.get<osmium::Way>(wpos), area_buffer));
const auto& s = assembler.stats();
REQUIRE(s.duplicate_nodes == 0);
REQUIRE(s.invalid_locations == 1);
}
TEST_CASE("Build area from way with ignored invalid location") {
osmium::memory::Buffer buffer{10240};
const auto wpos = osmium::builder::add_way(buffer,
_id(1),
_nodes({
{1, {1.0, 1.0}},
{2, {1.0, 2.0}},
{3},
{4, {2.0, 1.0}},
{1, {1.0, 1.0}}
})
);
osmium::area::AssemblerConfig config;
config.ignore_invalid_locations = true;
osmium::area::Assembler assembler{config};
osmium::memory::Buffer area_buffer{10240};
REQUIRE(assembler(buffer.get<osmium::Way>(wpos), area_buffer));
const auto& area = area_buffer.get<osmium::Area>(0);
REQUIRE(area.from_way());
REQUIRE(area.id() == 2);
const auto it = area.outer_rings().begin();
REQUIRE(it != area.outer_rings().end());
REQUIRE(it->size() == 4);
const auto& s = assembler.stats();
REQUIRE(s.area_simple_case == 1);
REQUIRE(s.from_ways == 1);
REQUIRE(s.nodes == 3);
REQUIRE(s.invalid_locations == 1);
}
|