1#ifndef OSMIUM_OSM_BOX_HPP
2#define OSMIUM_OSM_BOX_HPP
60 constexpr Box() noexcept = default;
67 Box(
double minx,
double miny,
double maxx,
double maxy) :
68 m_bottom_left(minx, miny),
69 m_top_right(maxx, maxy) {
70 assert(minx <= maxx && miny <= maxy);
83 m_bottom_left(bottom_left),
84 m_top_right(top_right) {
86 (!!bottom_left && !!top_right) ||
87 (bottom_left.
x() <= top_right.
x() && bottom_left.
y() <= top_right.
y()));
99 Box& extend(
const Location& location)
noexcept {
100 if (location.valid()) {
102 if (location.x() < m_bottom_left.x()) {
103 m_bottom_left.set_x(location.x());
105 if (location.x() > m_top_right.x()) {
106 m_top_right.set_x(location.x());
108 if (location.y() < m_bottom_left.y()) {
109 m_bottom_left.set_y(location.y());
111 if (location.y() > m_top_right.y()) {
112 m_top_right.set_y(location.y());
115 m_bottom_left = location;
116 m_top_right = location;
129 Box& extend(
const Box& box)
noexcept {
130 extend(box.bottom_left());
131 extend(box.top_right());
138 explicit constexpr operator bool() const noexcept {
139 return static_cast<bool>(m_bottom_left) &&
static_cast<bool>(m_top_right);
146 constexpr bool valid() const noexcept {
147 return bottom_left().
valid() && top_right().
valid();
153 constexpr Location bottom_left() const noexcept {
154 return m_bottom_left;
160 Location& bottom_left() noexcept {
161 return m_bottom_left;
167 constexpr Location top_right() const noexcept {
174 Location& top_right() noexcept {
183 double left() const noexcept {
185 return m_bottom_left.lon_without_check();
193 double right() const noexcept {
195 return m_top_right.lon_without_check();
203 double top() const noexcept {
205 return m_top_right.lat_without_check();
213 double bottom() const noexcept {
215 return m_bottom_left.lat_without_check();
225 assert(bottom_left());
228 return location.x() >= bottom_left().
x() && location.y() >= bottom_left().
y() &&
229 location.x() <= top_right().
x() && location.y() <= top_right().
y();
240 double size()
const {
241 return (m_top_right.lon() - m_bottom_left.lon()) *
242 (m_top_right.lat() - m_bottom_left.lat());
251 inline constexpr bool operator==(
const Box& lhs,
const Box& rhs)
noexcept {
252 return lhs.bottom_left() == rhs.bottom_left() &&
253 lhs.top_right() == rhs.top_right();
262 template <
typename TChar,
typename TTraits>
263 inline std::basic_ostream<TChar, TTraits>&
operator<<(std::basic_ostream<TChar, TTraits>& out,
const osmium::Box& box) {
266 box.bottom_left().as_string_without_check(std::ostream_iterator<char>(out));
268 box.top_right().as_string_without_check(std::ostream_iterator<char>(out));
271 out <<
"(undefined)";
Definition: location.hpp:271
constexpr int32_t x() const noexcept
Definition: location.hpp:377
constexpr bool valid() const noexcept
Definition: location.hpp:352
constexpr int32_t y() const noexcept
Definition: location.hpp:381
bool contains(const osmium::Box &lhs, const osmium::Box &rhs) noexcept
Definition: relations.hpp:46
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
bool operator==(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:440
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &out, const item_type item_type)
Definition: item_type.hpp:187