#pragma once #include #include #include #include #include namespace mapbox { namespace geometry { namespace wagyu { template double area(mapbox::geometry::linear_ring const& poly) { std::size_t size = poly.size(); if (size < 3) { return 0.0; } double a = 0.0; auto itr = poly.begin(); auto itr_prev = poly.end(); --itr_prev; a += static_cast(itr_prev->x + itr->x) * static_cast(itr_prev->y - itr->y); ++itr; itr_prev = poly.begin(); for (; itr != poly.end(); ++itr, ++itr_prev) { a += static_cast(itr_prev->x + itr->x) * static_cast(itr_prev->y - itr->y); } return -a * 0.5; } inline bool values_are_equal(double x, double y) { return util::FloatingPoint(x).AlmostEquals(util::FloatingPoint(y)); } inline bool value_is_zero(double val) { return values_are_equal(val, static_cast(0.0)); } inline bool greater_than_or_equal(double x, double y) { return x > y || values_are_equal(x, y); } inline bool greater_than(double x, double y) { return (!values_are_equal(x, y) && x > y); } inline bool less_than(double x, double y) { return (!values_are_equal(x, y) && x < y); } template bool slopes_equal(mapbox::geometry::point const& pt1, mapbox::geometry::point const& pt2, mapbox::geometry::point const& pt3) { return static_cast(pt1.y - pt2.y) * static_cast(pt2.x - pt3.x) == static_cast(pt1.x - pt2.x) * static_cast(pt2.y - pt3.y); } template bool slopes_equal(mapbox::geometry::wagyu::point const& pt1, mapbox::geometry::wagyu::point const& pt2, mapbox::geometry::point const& pt3) { return static_cast(pt1.y - pt2.y) * static_cast(pt2.x - pt3.x) == static_cast(pt1.x - pt2.x) * static_cast(pt2.y - pt3.y); } template bool slopes_equal(mapbox::geometry::wagyu::point const& pt1, mapbox::geometry::wagyu::point const& pt2, mapbox::geometry::wagyu::point const& pt3) { return static_cast(pt1.y - pt2.y) * static_cast(pt2.x - pt3.x) == static_cast(pt1.x - pt2.x) * static_cast(pt2.y - pt3.y); } template bool slopes_equal(mapbox::geometry::point const& pt1, mapbox::geometry::point const& pt2, mapbox::geometry::point const& pt3, mapbox::geometry::point const& pt4) { return static_cast(pt1.y - pt2.y) * static_cast(pt3.x - pt4.x) == static_cast(pt1.x - pt2.x) * static_cast(pt3.y - pt4.y); } template inline T wround(double value) { return static_cast(::llround(value)); } template <> inline std::int64_t wround(double value) { return ::llround(value); } } // namespace wagyu } // namespace geometry } // namespace mapbox