-
-
Notifications
You must be signed in to change notification settings - Fork 477
/
Copy pathtest-geom-multipoints.cpp
123 lines (100 loc) · 3.55 KB
/
test-geom-multipoints.cpp
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
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2025 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include <catch.hpp>
#include "common-buffer.hpp"
#include "geom-from-osm.hpp"
#include "geom-functions.hpp"
#include "geom-output.hpp"
#include "geom.hpp"
#include <array>
TEST_CASE("multipoint_t with a single point", "[NoDB]")
{
geom::point_t const expected{1, 1};
geom::point_t const point = expected;
geom::geometry_t geom{geom::multipoint_t{}};
auto &mp = geom.get<geom::multipoint_t>();
mp.add_geometry({1, 1});
REQUIRE(geom.is_multipoint());
REQUIRE(geometry_type(geom) == "MULTIPOINT");
REQUIRE(dimension(geom) == 0);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(reverse(geom) == geom);
REQUIRE(centroid(geom) == geom::geometry_t{point});
REQUIRE(mp[0] == expected);
}
TEST_CASE("multipoint_t with several points", "[NoDB]")
{
geom::point_t const p0{1, 1};
geom::point_t const p1{2, 1};
geom::point_t const p2{3, 1};
geom::geometry_t geom{geom::multipoint_t{}};
auto &mp = geom.get<geom::multipoint_t>();
mp.add_geometry({1, 1});
mp.add_geometry({2, 1});
mp.add_geometry({3, 1});
REQUIRE(geom.is_multipoint());
REQUIRE(geometry_type(geom) == "MULTIPOINT");
REQUIRE(num_geometries(geom) == 3);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(reverse(geom) == geom);
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{2, 1}});
REQUIRE(mp[0] == p0);
REQUIRE(mp[1] == p1);
REQUIRE(mp[2] == p2);
REQUIRE(geometry_n(geom, 1) == geom::geometry_t{p0});
REQUIRE(geometry_n(geom, 2) == geom::geometry_t{p1});
REQUIRE(geometry_n(geom, 3) == geom::geometry_t{p2});
}
TEST_CASE("create_multipoint from OSM data", "[NoDB]")
{
test_buffer_t buffer;
buffer.add_node("n10 x1 y0");
buffer.add_way("w20 Nn1x1y1,n2x2y1");
buffer.add_node("n11 x1 y1");
buffer.add_node("n12 x3 y2");
buffer.add_way("w21 Nn3x10y10,n4x10y11");
buffer.add_node("n13 x3 y1");
buffer.add_relation("r30 Mw20@");
auto const geom = geom::create_multipoint(buffer.buffer());
REQUIRE(geometry_type(geom) == "MULTIPOINT");
REQUIRE(dimension(geom) == 0);
REQUIRE(num_geometries(geom) == 4);
auto const &c = geom.get<geom::multipoint_t>();
REQUIRE(c[0] == geom::point_t{1, 0});
REQUIRE(c[1] == geom::point_t{1, 1});
REQUIRE(c[2] == geom::point_t{3, 2});
REQUIRE(c[3] == geom::point_t{3, 1});
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{2, 1}});
}
TEST_CASE("create_multipoint from OSM data with only a single point", "[NoDB]")
{
test_buffer_t buffer;
SECTION("only single node in relation")
{
buffer.add_node("n10 x1 y0");
}
SECTION("two nodes in relation, but one with missing location")
{
buffer.add_node("n10 x1 y0");
buffer.add_node("n11");
}
auto const geom = geom::create_multipoint(buffer.buffer());
REQUIRE(geometry_type(geom) == "POINT");
REQUIRE(dimension(geom) == 0);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(geom.get<geom::point_t>() == geom::point_t{1, 0});
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1, 0}});
}