-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#pragma once | ||
|
||
#include <mapbox/geometry/empty.hpp> | ||
#include <mapbox/feature.hpp> | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
namespace mapbox { | ||
namespace geometry { | ||
|
||
std::ostream& operator<<(std::ostream& os, const empty&) | ||
{ | ||
return os << "[]"; | ||
} | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& os, const point<T>& point) | ||
{ | ||
return os << "[" << point.x << "," << point.y << "]"; | ||
} | ||
|
||
template <typename T, template <class, class...> class C, class... Args> | ||
std::ostream& operator<<(std::ostream& os, const C<T, Args...>& cont) | ||
{ | ||
os << "["; | ||
for (auto it = cont.cbegin();;) | ||
{ | ||
os << *it; | ||
if (++it == cont.cend()) | ||
{ | ||
break; | ||
} | ||
os << ","; | ||
} | ||
return os << "]"; | ||
} | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& os, const line_string<T>& geom) | ||
{ | ||
return os << static_cast<typename line_string<T>::container_type>(geom); | ||
} | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& os, const linear_ring<T>& geom) | ||
{ | ||
return os << static_cast<typename linear_ring<T>::container_type>(geom); | ||
} | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& os, const polygon<T>& geom) | ||
{ | ||
return os << static_cast<typename polygon<T>::container_type>(geom); | ||
} | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& os, const multi_point<T>& geom) | ||
{ | ||
return os << static_cast<typename multi_point<T>::container_type>(geom); | ||
} | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& os, const multi_line_string<T>& geom) | ||
{ | ||
return os << static_cast<typename multi_line_string<T>::container_type>(geom); | ||
} | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& os, const multi_polygon<T>& geom) | ||
{ | ||
return os << static_cast<typename multi_polygon<T>::container_type>(geom); | ||
} | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& os, const geometry<T>& geom) | ||
{ | ||
geometry<T>::visit(geom, [&](const auto& g) { os << g; }); | ||
return os; | ||
} | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& os, const geometry_collection<T>& geom) | ||
{ | ||
return os << static_cast<typename geometry_collection<T>::container_type>(geom); | ||
} | ||
|
||
} // namespace geometry | ||
|
||
namespace feature { | ||
|
||
std::ostream& operator<<(std::ostream& os, const null_value_t&) | ||
{ | ||
return os << "[]"; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
brunoabinader
Author
Member
|
||
} | ||
|
||
} // namespace feature | ||
} // namespace mapbox |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <catch.hpp> | ||
#include <mapbox/geometry_io.hpp> | ||
|
||
#include <iostream> | ||
|
||
TEST_CASE("operator<<") | ||
{ | ||
mapbox::geometry::empty empty; | ||
mapbox::geometry::point<double> point{10, 20}; | ||
mapbox::geometry::point<double> point2{30, 40}; | ||
mapbox::geometry::line_string<double> lineString{point, point2}; | ||
mapbox::geometry::polygon<double> polygon{mapbox::geometry::linear_ring<double>{point, point2}}; | ||
mapbox::geometry::multi_point<double> multiPoint{point, point2}; | ||
mapbox::geometry::multi_line_string<double> multiLineString{lineString, lineString}; | ||
mapbox::geometry::multi_polygon<double> multiPolygon{polygon}; | ||
mapbox::geometry::geometry_collection<double> collection{multiPolygon}; | ||
|
||
std::stringstream stream; | ||
stream << empty << std::endl; | ||
stream << point << std::endl; | ||
stream << lineString << std::endl; | ||
stream << polygon << std::endl; | ||
stream << multiPoint << std::endl; | ||
stream << multiLineString << std::endl; | ||
stream << multiPolygon << std::endl; | ||
stream << collection << std::endl; | ||
stream << mapbox::geometry::geometry<double>{collection} << std::endl; | ||
|
||
std::string line; | ||
|
||
std::getline(stream, line); | ||
CHECK(line == std::string("[]")); | ||
|
||
std::getline(stream, line); | ||
CHECK(line == std::string("[10,20]")); | ||
|
||
std::getline(stream, line); | ||
CHECK(line == std::string("[[10,20],[30,40]]")); | ||
|
||
std::getline(stream, line); | ||
CHECK(line == std::string("[[[10,20],[30,40]]]")); | ||
|
||
std::getline(stream, line); | ||
CHECK(line == std::string("[[10,20],[30,40]]")); | ||
|
||
std::getline(stream, line); | ||
CHECK(line == std::string("[[[10,20],[30,40]],[[10,20],[30,40]]]")); | ||
|
||
std::getline(stream, line); | ||
CHECK(line == std::string("[[[[10,20],[30,40]]]]")); | ||
|
||
std::getline(stream, line); | ||
CHECK(line == std::string("[[[[[10,20],[30,40]]]]]")); | ||
|
||
std::getline(stream, line); | ||
CHECK(line == std::string("[[[[[10,20],[30,40]]]]]")); | ||
} |
@brunoabinader noting that this is missing code coverage. Do you think this is important to test?
Note: I can see this because I have https://github.com/codecov/browser-extension installed.