Skip to content

Commit 59cc668

Browse files
committed
fix simplify for small LinearRings
1 parent a7620d6 commit 59cc668

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/transformations/simplify.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,14 @@ function _simplify(alg::RadialDistance, points::Vector, _)
240240
end
241241
## Never remove the end points
242242
distances[begin] = distances[end] = Inf
243-
return _get_points(alg, points, distances)
243+
indices = _get_indices(alg, points, distances)
244+
# Check there is at least one mid point
245+
if !any(view(indices, firstindex(indices)+1:lastindex(indices)-1))
246+
# If not use the midpoint of the removed points ?
247+
indices[lastindex(indices) ÷ 2] = true
248+
end
249+
250+
return points[indices]
244251
end
245252

246253

@@ -410,7 +417,7 @@ end
410417
function _simplify(alg::VisvalingamWhyatt, points::Vector, _)
411418
length(points) <= MIN_POINTS && return points
412419
areas = _build_tolerances(_triangle_double_area, points)
413-
return _get_points(alg, points, areas)
420+
return points[_get_indices(alg, points, areas)]
414421
end
415422

416423
# Calculates double the area of a triangle given its vertices
@@ -481,20 +488,19 @@ function tuple_points(geom)
481488
return points
482489
end
483490

484-
function _get_points(alg, points, tolerances)
491+
function _get_indices(alg, points, tolerances)
485492
## This assumes that `alg` has the properties
486493
## `tol`, `number`, and `ratio` available...
487494
tol = alg.tol
488495
number = alg.number
489496
ratio = alg.ratio
490-
bit_indices = if !isnothing(tol)
497+
return if !isnothing(tol)
491498
_tol_indices(alg.tol::Float64, points, tolerances)
492499
elseif !isnothing(number)
493500
_number_indices(alg.number::Int64, points, tolerances)
494501
else
495502
_ratio_indices(alg.ratio::Float64, points, tolerances)
496503
end
497-
return points[bit_indices]
498504
end
499505

500506
function _tol_indices(tol, points, tolerances)

0 commit comments

Comments
 (0)