From cf0963306f266d42c75b91a92682b50646ed3d32 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 18 May 2016 22:27:59 -0400 Subject: [PATCH 1/2] PRF: rearrange data --- src/_path.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/_path.h b/src/_path.h index 6b1b3d1f7053..89df3931bd24 100644 --- a/src/_path.h +++ b/src/_path.h @@ -77,7 +77,7 @@ struct XY // Input 2D polygon _pgon_ with _numverts_ number of vertices and test point // _point_, returns 1 if inside, 0 if outside. template -void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &inside_flag) +void point_in_path_impl(const PointArray &points, PathIterator &path, ResultArray &inside_flag) { bool yflag1; double vtx0, vty0, vtx1, vty1; @@ -89,14 +89,28 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins size_t n = points.size(); + std::vector _x(n); + std::vector _y(n); + std::vector yflag0(n); std::vector subpath_flag(n); + path.rewind(0); for (i = 0; i < n; ++i) { inside_flag[i] = false; } + for (i = 0; i < n; ++i) { + + tx = points[i][0]; + ty = points[i][1]; + + _x[i] = tx; + _y[i] = ty; + + } + unsigned code = 0; do { @@ -135,8 +149,10 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins } for (i = 0; i < n; ++i) { - tx = points[i][0]; - ty = points[i][1]; + + tx = _x[i]; + ty = _y[i]; + if (!(std::isfinite(tx) && std::isfinite(ty))) { continue; @@ -183,8 +199,8 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins all_done = true; for (i = 0; i < n; ++i) { - tx = points[i][0]; - ty = points[i][1]; + tx = _x[i]; + ty = _y[i]; if (!(std::isfinite(tx) && std::isfinite(ty))) { continue; From da764a7ca8aa80eb8f3317b3a0f464e5fbf687a9 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 18 May 2016 21:57:28 -0400 Subject: [PATCH 2/2] PRF: only check finiteness once --- src/_path.h | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/_path.h b/src/_path.h index 89df3931bd24..2166edd676e2 100644 --- a/src/_path.h +++ b/src/_path.h @@ -94,6 +94,7 @@ void point_in_path_impl(const PointArray &points, PathIterator &path, ResultArra std::vector yflag0(n); std::vector subpath_flag(n); + std::vector both_finite(n); path.rewind(0); @@ -102,13 +103,14 @@ void point_in_path_impl(const PointArray &points, PathIterator &path, ResultArra inside_flag[i] = false; } for (i = 0; i < n; ++i) { - tx = points[i][0]; ty = points[i][1]; _x[i] = tx; _y[i] = ty; + both_finite[i] = (std::isfinite(tx) && std::isfinite(ty)); + } @@ -126,14 +128,13 @@ void point_in_path_impl(const PointArray &points, PathIterator &path, ResultArra sy = vty0 = vty1 = y; for (i = 0; i < n; ++i) { - ty = points[i][1]; - - if (std::isfinite(ty)) { - // get test bit for above/below X axis - yflag0[i] = (vty0 >= ty); + if (! both_finite[i]){ + continue; + } + // get test bit for above/below X axis + yflag0[i] = (vty0 >= ty); + subpath_flag[i] = false; - subpath_flag[i] = false; - } } do { @@ -149,15 +150,13 @@ void point_in_path_impl(const PointArray &points, PathIterator &path, ResultArra } for (i = 0; i < n; ++i) { - + if (! both_finite[i]){ + continue; + } tx = _x[i]; ty = _y[i]; - if (!(std::isfinite(tx) && std::isfinite(ty))) { - continue; - } - yflag1 = (vty1 >= ty); // Check if endpoints straddle (are on opposite sides) of // X axis (i.e. the Y's differ); if so, +X ray could @@ -199,13 +198,12 @@ void point_in_path_impl(const PointArray &points, PathIterator &path, ResultArra all_done = true; for (i = 0; i < n; ++i) { - tx = _x[i]; + if (!both_finite[i]){ + continue; + } + tx = _x[i]; ty = _y[i]; - if (!(std::isfinite(tx) && std::isfinite(ty))) { - continue; - } - yflag1 = (vty1 >= ty); if (yflag0[i] != yflag1) { if (((vty1 - ty) * (vtx0 - vtx1) >= (vtx1 - tx) * (vty0 - vty1)) == yflag1) {