-
-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy pathgeom-box.cpp
More file actions
105 lines (89 loc) · 2.03 KB
/
geom-box.cpp
File metadata and controls
105 lines (89 loc) · 2.03 KB
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
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2026 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include "geom-box.hpp"
#include <algorithm>
#include <variant>
namespace geom {
box_t &box_t::extend(point_t const &point) noexcept
{
m_min_x = std::min(point.x(), m_min_x);
m_min_y = std::min(point.y(), m_min_y);
m_max_x = std::max(point.x(), m_max_x);
m_max_y = std::max(point.y(), m_max_y);
return *this;
}
void box_t::extend(point_list_t const &list) noexcept
{
for (auto const &point : list) {
extend(point);
}
}
void box_t::extend(box_t const &box) noexcept
{
m_min_x = std::min(box.min_x(), m_min_x);
m_min_y = std::min(box.min_y(), m_min_y);
m_max_x = std::max(box.max_x(), m_max_x);
m_max_y = std::max(box.max_y(), m_max_y);
}
box_t envelope(geom::nullgeom_t const & /*geom*/) { return box_t{}; }
box_t envelope(geom::point_t const &geom)
{
box_t box;
box.extend(geom);
return box;
}
box_t envelope(geom::linestring_t const &geom)
{
box_t box;
box.extend(geom);
return box;
}
box_t envelope(geom::polygon_t const &geom)
{
box_t box;
box.extend(geom.outer());
return box;
}
box_t envelope(geom::multipoint_t const &geom)
{
box_t box;
for (auto const &point : geom) {
box.extend(point);
}
return box;
}
box_t envelope(geom::multilinestring_t const &geom)
{
box_t box;
for (auto const &line : geom) {
box.extend(line);
}
return box;
}
box_t envelope(geom::multipolygon_t const &geom)
{
box_t box;
for (auto const &polygon : geom) {
box.extend(polygon.outer());
}
return box;
}
box_t envelope(geom::collection_t const &geom)
{
box_t box;
for (auto const &sgeom : geom) {
box.extend(envelope(sgeom));
}
return box;
}
box_t envelope(geometry_t const &geom)
{
return geom.visit([](auto const &g) { return envelope(g); });
}
} // namespace geom