Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Apr 18, 2016
1 parent 59a0868 commit 69aab12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/vector_tile_geometry_decoder.hpp
Expand Up @@ -10,7 +10,6 @@
//mapnik
#include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/util/is_clockwise.hpp>
#if defined(DEBUG)
#include <mapnik/debug.hpp>
#endif
Expand Down
14 changes: 12 additions & 2 deletions src/vector_tile_geometry_decoder.ipp
Expand Up @@ -25,13 +25,23 @@ namespace detail
template <typename T>
bool ring_is_clockwise(T const& ring)
{
long double area = 0.0;
std::size_t num_points = ring.size();
if (num_points < 3)
{
return false;
}
double area = 0.0;
double orig_x = ring[0].x;
double orig_y = ring[0].y;
for (std::size_t i = 0; i < num_points; ++i)
{
auto const& p0 = ring[i];
auto const& p1 = ring[(i + 1) % num_points];
area += static_cast<long double>(p0.x) * static_cast<long double>(p1.y) - static_cast<long double>(p0.y) * static_cast<long double>(p1.x);
double x0 = p0.x - orig_x;
double y0 = p0.y - orig_y;
double x1 = p1.x - orig_x;
double y1 = p1.y - orig_y;
area += x0 * y1 - x1 * y0;
}
return (area < 0.0) ? true : false;
}
Expand Down

2 comments on commit 69aab12

@artemp
Copy link
Contributor

@artemp artemp commented on 69aab12 Apr 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@springmeyer - why this duplication ? We'll be sleeping much better if is_clockwise is defined once, no?
Also,

if (num_points < 3)
 +    {
 +        return false;
 +    }

^ this is a lie :)

@springmeyer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artemp - please make it right in mapnik and we can move back - refs #208

Please sign in to comment.