Ramer-Douglas-Peucker line simplification: Difference between revisions
Ramer-Douglas-Peucker line simplification (view source)
Revision as of 15:45, 17 June 2017
, 6 years ago→{{header|Perl 6}}: Style tweaks, code simplification
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: factor out some common code) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Style tweaks, code simplification) |
||
Line 222:
<lang perl6>sub norm (*@list) { @list»².sum.sqrt }
sub perpendicular-distance (@start, @end where @end !eqv @start
return 0 if @point eqv any(@start, @end);
my ( $Δx, $Δy ) = @end «-» @start;
Line 230:
}
sub Ramer-Douglas-Peucker(
return @points if @points == 2;
my @d = (^@points).map: { perpendicular-distance |@points[0, *-1, $_] };
my ($index, $dmax) = @d.first: @d.max, :kv;
return flat
@points[0, *-1];
}
# TESTING
say
[(0,0),(1,0.1),(2,-0.1),(3,5),(4,6),(5,7),(6,8.1),(7,9),(8,9),(9,9)]
);</lang>
|