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())
100 Box& extend(
const Location& location) noexcept {
101 if (location.valid()) {
103 if (location.x() < m_bottom_left.x()) {
104 m_bottom_left.set_x(location.x());
106 if (location.x() > m_top_right.x()) {
107 m_top_right.set_x(location.x());
109 if (location.y() < m_bottom_left.y()) {
110 m_bottom_left.set_y(location.y());
112 if (location.y() > m_top_right.y()) {
113 m_top_right.set_y(location.y());
116 m_bottom_left = location;
117 m_top_right = location;
130 Box& extend(
const Box& box) noexcept {
131 extend(box.bottom_left());
132 extend(box.top_right());
139 explicit constexpr
operator bool() const noexcept {
140 return bool(m_bottom_left) && bool(m_top_right);
147 constexpr
bool valid() const noexcept {
148 return bottom_left().
valid() && top_right().
valid();
154 constexpr Location bottom_left() const noexcept {
155 return m_bottom_left;
161 Location& bottom_left() noexcept {
162 return m_bottom_left;
168 constexpr Location top_right() const noexcept {
175 Location& top_right() noexcept {
184 double left() const noexcept {
186 return m_bottom_left.lon_without_check();
194 double right() const noexcept {
196 return m_top_right.lon_without_check();
204 double top() const noexcept {
206 return m_top_right.lat_without_check();
214 double bottom() const noexcept {
216 return m_bottom_left.lat_without_check();
226 assert(bottom_left());
229 return location.x() >= bottom_left().
x() && location.y() >= bottom_left().
y() &&
230 location.x() <= top_right().
x() && location.y() <= top_right().
y();
241 double size()
const {
242 return (m_top_right.lon() - m_bottom_left.lon()) *
243 (m_top_right.lat() - m_bottom_left.lat());
252 inline constexpr
bool operator==(
const Box& lhs,
const Box& rhs) noexcept {
253 return lhs.bottom_left() == rhs.bottom_left() &&
254 lhs.top_right() == rhs.top_right();
263 template <
typename TChar,
typename TTraits>
264 inline std::basic_ostream<TChar, TTraits>&
operator<<(std::basic_ostream<TChar, TTraits>& out,
const osmium::Box& box) {
267 box.bottom_left().as_string_without_check(std::ostream_iterator<char>(out));
269 box.top_right().as_string_without_check(std::ostream_iterator<char>(out));
272 out <<
"(undefined)";
Definition: location.hpp:271
constexpr int32_t x() const noexcept
Definition: location.hpp:373
constexpr bool valid() const noexcept
Definition: location.hpp:348
constexpr int32_t y() const noexcept
Definition: location.hpp:377
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:442
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &out, const item_type item_type)
Definition: item_type.hpp:187