-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87fef2a
commit fed6140
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
namespace mapbox { namespace geometry { | ||
|
||
template <typename T> | ||
struct box | ||
{ | ||
using point_type = point<T>; | ||
|
||
box(point_type const& min_, point_type const& max_) | ||
: min(min_), max(max_) | ||
{} | ||
|
||
point_type min; | ||
point_type max; | ||
}; | ||
|
||
template <typename T> | ||
bool operator==(box<T> const& lhs, box<T> const& rhs) | ||
{ | ||
return lhs.min == rhs.min && lhs.max == rhs.max; | ||
} | ||
|
||
template <typename T> | ||
bool operator!=(box<T> const& lhs, box<T> const& rhs) | ||
{ | ||
return lhs.min != rhs.min || lhs.max != rhs.max; | ||
} | ||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <mapbox/geometry/box.hpp> | ||
#include <mapbox/geometry/for_each_point.hpp> | ||
|
||
#include <limits> | ||
|
||
namespace mapbox { namespace geometry { | ||
|
||
template <typename G, typename T = typename G::coordinate_type> | ||
box<T> envelope(G const& geometry) | ||
{ | ||
using limits = std::numeric_limits<T>; | ||
|
||
T min_t = limits::has_infinity ? -limits::infinity() : limits::min(); | ||
T max_t = limits::has_infinity ? limits::infinity() : limits::max(); | ||
|
||
point<T> min(max_t, max_t); | ||
point<T> max(min_t, min_t); | ||
|
||
for_each_point(geometry, [&] (point<T> const& point) { | ||
if (min.x > point.x) min.x = point.x; | ||
if (min.y > point.y) min.y = point.y; | ||
if (max.x < point.x) max.x = point.x; | ||
if (max.y < point.y) max.y = point.y; | ||
}); | ||
|
||
return box<T>(min, max); | ||
} | ||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <mapbox/geometry/geometry.hpp> | ||
|
||
namespace mapbox { namespace geometry { | ||
|
||
template <typename T, typename F> | ||
void for_each_point(point<T> const& point, F const& f) | ||
{ | ||
f(point); | ||
} | ||
|
||
template <typename T, typename F> | ||
void for_each_point(geometry<T> const& geom, F const& f) | ||
{ | ||
geometry<T>::visit(geom, [&] (auto const& g) { for_each_point(g, f); }); | ||
} | ||
|
||
template <typename Container, typename F> | ||
void for_each_point(Container const& container, F const& f) | ||
{ | ||
for (auto const& e: container) { | ||
for_each_point(e, f); | ||
} | ||
} | ||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters