Skip to content

Commit

Permalink
Merge pull request #879 from mapbox/wagyu-0.5.0
Browse files Browse the repository at this point in the history
Upgrade Wagyu to version 0.5.0
  • Loading branch information
e-n-f committed Aug 26, 2020
2 parents ddb7993 + ea52e88 commit 62b9d12
Show file tree
Hide file tree
Showing 58 changed files with 809 additions and 584 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 1.36.0

* Update Wagyu to version 0.5.0

## 1.35.0

* Fix calculation of mean when accumulating attributes in clusters
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
@@ -1,5 +1,6 @@
ignore:
- "test"
- "mapbox"

coverage:
status:
Expand Down
14 changes: 8 additions & 6 deletions mapbox/LICENSE-wagyu
@@ -1,18 +1,20 @@
Parts of the code in the Wagyu Library are derived from the version of the
Parts of the code in the Wagyu Library are derived from the version of the
Clipper Library by Angus Johnson listed below.

Author : Angus Johnson
Version : 6.4.0
Date : 2 July 2015
Website : http://www.angusj.com

Copyright for portions of the derived code in the Wagyu library are held
by Angus Johnson, 2010-2015. All other copyright for the Wagyu Library are held by
Mapbox, 2016. This code is published in accordance with, and retains the same license
as the Clipper Library by Angus Johnson.
Copyright for portions of the derived code in the Wagyu library are held
by Angus Johnson, 2010-2015. Copyright for the "include/mapbox/geometry/wagyu/almost_equal.hpp"
file is held by Google Inc and its license is listed at the top of that file.
All other copyright for the Wagyu Library are held by Mapbox, 2016. This code
is published in accordance with, and retains the same license as the Clipper
Library by Angus Johnson.

Copyright (c) 2010-2015, Angus Johnson
Copyright (c) 2016, Mapbox
Copyright (c) 2016-2020, Mapbox

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
Expand Down
83 changes: 36 additions & 47 deletions mapbox/geometry/wagyu/active_bound_list.hpp
Expand Up @@ -61,9 +61,7 @@ std::string output_edges(active_bound_list<T> const& bnds) {
#endif

template <typename T>
bool is_even_odd_fill_type(bound<T> const& bound,
fill_type subject_fill_type,
fill_type clip_fill_type) {
bool is_even_odd_fill_type(bound<T> const& bound, fill_type subject_fill_type, fill_type clip_fill_type) {
if (bound.poly_type == polygon_type_subject) {
return subject_fill_type == fill_type_even_odd;
} else {
Expand All @@ -72,9 +70,7 @@ bool is_even_odd_fill_type(bound<T> const& bound,
}

template <typename T>
bool is_even_odd_alt_fill_type(bound<T> const& bound,
fill_type subject_fill_type,
fill_type clip_fill_type) {
bool is_even_odd_alt_fill_type(bound<T> const& bound, fill_type subject_fill_type, fill_type clip_fill_type) {
if (bound.poly_type == polygon_type_subject) {
return clip_fill_type == fill_type_even_odd;
} else {
Expand All @@ -94,11 +90,11 @@ struct bound_insert_location {
auto const& bound1 = *b;
if (values_are_equal(bound2.current_x, bound1.current_x)) {
if (bound2.current_edge->top.y > bound1.current_edge->top.y) {
return static_cast<double>(bound2.current_edge->top.x) <
get_current_x(*(bound1.current_edge), bound2.current_edge->top.y);
return less_than(static_cast<double>(bound2.current_edge->top.x),
get_current_x(*(bound1.current_edge), bound2.current_edge->top.y));
} else {
return static_cast<double>(bound1.current_edge->top.x) >
get_current_x(*(bound2.current_edge), bound1.current_edge->top.y);
return greater_than(static_cast<double>(bound1.current_edge->top.x),
get_current_x(*(bound2.current_edge), bound1.current_edge->top.y));
}
} else {
return bound2.current_x < bound1.current_x;
Expand All @@ -107,42 +103,44 @@ struct bound_insert_location {
};

template <typename T>
active_bound_list_itr<T>
insert_bound_into_ABL(bound<T>& left, bound<T>& right, active_bound_list<T>& active_bounds) {
active_bound_list_itr<T> insert_bound_into_ABL(bound<T>& left, bound<T>& right, active_bound_list<T>& active_bounds) {

auto itr =
std::find_if(active_bounds.begin(), active_bounds.end(), bound_insert_location<T>(left));
auto itr = std::find_if(active_bounds.begin(), active_bounds.end(), bound_insert_location<T>(left));
#ifdef GCC_MISSING_VECTOR_RANGE_INSERT
itr = active_bounds.insert(itr, &right);
return active_bounds.insert(itr, &left);
#else
return active_bounds.insert(itr, { &left, &right });
#endif
}

template <typename T>
inline bool is_maxima(bound<T>& bnd, T y) {
inline bool is_maxima(bound<T> const& bnd, T y) {
return bnd.next_edge == bnd.edges.end() && bnd.current_edge->top.y == y;
}

template <typename T>
inline bool is_maxima(active_bound_list_itr<T>& bnd, T y) {
inline bool is_maxima(active_bound_list_itr<T> const& bnd, T y) {
return is_maxima(*(*bnd), y);
}

template <typename T>
inline bool is_intermediate(bound<T>& bnd, T y) {
inline bool is_intermediate(bound<T> const& bnd, T y) {
return bnd.next_edge != bnd.edges.end() && bnd.current_edge->top.y == y;
}

template <typename T>
inline bool is_intermediate(active_bound_list_itr<T>& bnd, T y) {
inline bool is_intermediate(active_bound_list_itr<T> const& bnd, T y) {
return is_intermediate(*(*bnd), y);
}

template <typename T>
inline bool current_edge_is_horizontal(active_bound_list_itr<T>& bnd) {
inline bool current_edge_is_horizontal(active_bound_list_itr<T> const& bnd) {
return is_horizontal(*((*bnd)->current_edge));
}

template <typename T>
inline bool next_edge_is_horizontal(active_bound_list_itr<T>& bnd) {
inline bool next_edge_is_horizontal(active_bound_list_itr<T> const& bnd) {
return is_horizontal(*((*bnd)->next_edge));
}

Expand All @@ -154,20 +152,19 @@ void next_edge_in_bound(bound<T>& bnd, scanbeam_list<T>& scanbeam) {
++(bnd.next_edge);
bnd.current_x = static_cast<double>(current_edge->bot.x);
if (!is_horizontal<T>(*current_edge)) {
scanbeam.push_back(current_edge->top.y);
insert_sorted_scanbeam(scanbeam, current_edge->top.y);
}
}
}

template <typename T>
active_bound_list_itr<T> get_maxima_pair(active_bound_list_itr<T> const& bnd,
active_bound_list<T>& active_bounds) {
active_bound_list_itr<T> get_maxima_pair(active_bound_list_itr<T> bnd, active_bound_list<T>& active_bounds) {
bound_ptr<T> maximum = (*bnd)->maximum_bound;
return std::find(active_bounds.begin(), active_bounds.end(), maximum);
}

template <typename T>
void set_winding_count(active_bound_list_itr<T>& bnd_itr,
void set_winding_count(active_bound_list_itr<T> bnd_itr,
active_bound_list<T>& active_bounds,
fill_type subject_fill_type,
fill_type clip_fill_type) {
Expand All @@ -181,8 +178,7 @@ void set_winding_count(active_bound_list_itr<T>& bnd_itr,

// find the edge of the same polytype that immediately preceeds 'edge' in
// AEL
while (rev_bnd_itr != active_bounds.rend() &&
(*rev_bnd_itr)->poly_type != (*bnd_itr)->poly_type) {
while (rev_bnd_itr != active_bounds.rend() && (*rev_bnd_itr)->poly_type != (*bnd_itr)->poly_type) {
++rev_bnd_itr;
}
if (rev_bnd_itr == active_bounds.rend()) {
Expand All @@ -204,8 +200,7 @@ void set_winding_count(active_bound_list_itr<T>& bnd_itr,
(*bnd_itr)->winding_count = (*rev_bnd_itr)->winding_count;
} else {
// otherwise continue to 'decrease' WC ...
(*bnd_itr)->winding_count =
(*rev_bnd_itr)->winding_count + (*bnd_itr)->winding_delta;
(*bnd_itr)->winding_count = (*rev_bnd_itr)->winding_count + (*bnd_itr)->winding_delta;
}
} else {
// now outside all polys of same polytype so set own WC ...
Expand All @@ -219,8 +214,7 @@ void set_winding_count(active_bound_list_itr<T>& bnd_itr,
(*bnd_itr)->winding_count = (*rev_bnd_itr)->winding_count;
} else {
// otherwise add to WC ...
(*bnd_itr)->winding_count =
(*rev_bnd_itr)->winding_count + (*bnd_itr)->winding_delta;
(*bnd_itr)->winding_count = (*rev_bnd_itr)->winding_count + (*bnd_itr)->winding_delta;
}
}
(*bnd_itr)->winding_count2 = (*rev_bnd_itr)->winding_count2;
Expand All @@ -244,10 +238,7 @@ void set_winding_count(active_bound_list_itr<T>& bnd_itr,
}

template <typename T>
bool is_contributing(bound<T> const& bnd,
clip_type cliptype,
fill_type subject_fill_type,
fill_type clip_fill_type) {
bool is_contributing(bound<T> const& bnd, clip_type cliptype, fill_type subject_fill_type, fill_type clip_fill_type) {
fill_type pft = subject_fill_type;
fill_type pft2 = clip_fill_type;
if (bnd.poly_type != polygon_type_subject) {
Expand Down Expand Up @@ -350,15 +341,14 @@ void insert_lm_left_and_right_bound(bound<T>& left_bound,
(*rb_abl_itr)->winding_count = (*lb_abl_itr)->winding_count;
(*rb_abl_itr)->winding_count2 = (*lb_abl_itr)->winding_count2;
if (is_contributing(left_bound, cliptype, subject_fill_type, clip_fill_type)) {
add_local_minimum_point(*(*lb_abl_itr), *(*rb_abl_itr), active_bounds,
(*lb_abl_itr)->current_edge->bot, rings);
add_local_minimum_point(*(*lb_abl_itr), *(*rb_abl_itr), active_bounds, (*lb_abl_itr)->current_edge->bot, rings);
}

// Add top of edges to scanbeam
scanbeam.push_back((*lb_abl_itr)->current_edge->top.y);
insert_sorted_scanbeam(scanbeam, (*lb_abl_itr)->current_edge->top.y);

if (!current_edge_is_horizontal<T>(rb_abl_itr)) {
scanbeam.push_back((*rb_abl_itr)->current_edge->top.y);
insert_sorted_scanbeam(scanbeam, (*rb_abl_itr)->current_edge->top.y);
}
}

Expand All @@ -376,8 +366,8 @@ void insert_local_minima_into_ABL(T const bot_y,
initialize_lm<T>(current_lm);
auto& left_bound = (*current_lm)->left_bound;
auto& right_bound = (*current_lm)->right_bound;
insert_lm_left_and_right_bound(left_bound, right_bound, active_bounds, rings, scanbeam,
cliptype, subject_fill_type, clip_fill_type);
insert_lm_left_and_right_bound(left_bound, right_bound, active_bounds, rings, scanbeam, cliptype,
subject_fill_type, clip_fill_type);
++current_lm;
}
}
Expand All @@ -392,16 +382,15 @@ void insert_horizontal_local_minima_into_ABL(T const top_y,
clip_type cliptype,
fill_type subject_fill_type,
fill_type clip_fill_type) {
while (current_lm != minima_sorted.end() && top_y == (*current_lm)->y &&
(*current_lm)->minimum_has_horizontal) {
while (current_lm != minima_sorted.end() && top_y == (*current_lm)->y && (*current_lm)->minimum_has_horizontal) {
initialize_lm<T>(current_lm);
auto& left_bound = (*current_lm)->left_bound;
auto& right_bound = (*current_lm)->right_bound;
insert_lm_left_and_right_bound(left_bound, right_bound, active_bounds, rings, scanbeam,
cliptype, subject_fill_type, clip_fill_type);
insert_lm_left_and_right_bound(left_bound, right_bound, active_bounds, rings, scanbeam, cliptype,
subject_fill_type, clip_fill_type);
++current_lm;
}
}
}
}
}
} // namespace wagyu
} // namespace geometry
} // namespace mapbox

0 comments on commit 62b9d12

Please sign in to comment.