Ramer-Douglas-Peucker line simplification: Difference between revisions
Ramer-Douglas-Peucker line simplification (view source)
Revision as of 12:16, 23 March 2019
, 5 years ago→{{header|Perl}}: 'strict' compliant
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: 'strict' compliant) |
|||
Line 704:
=={{header|Perl}}==
{{trans|Perl 6}}
<lang perl>use
use warnings;
use feature 'say';
use List::MoreUtils qw(firstidx minmax);
my $epsilon = 1;
Line 710 ⟶ 713:
sub norm {
my(@list) = @_;
my
$sum += $_**2 for @list;
sqrt($sum)
Line 716 ⟶ 719:
sub perpendicular_distance {
local(*start,*end,*point) = (shift, shift, shift);
return 0 if $start[0]==$point[0] && $start[1]==$point[1]
or $end[0]==$point[0] && $end[1]==$point[1];
Line 730 ⟶ 734:
my(@points) = @_;
return @points if @points == 2;
my
push @d, perpendicular_distance(@points[0, -1, $_]) for 0..@points-1;
my(undef,$dmax) = minmax @d;
my
if ($dmax > $epsilon) {
my @lo = Ramer_Douglas_Peucker( @points[0..$index]);
Line 742 ⟶ 746:
}
for Ramer_Douglas_Peucker( [0,0],[1,0.1],[2,-0.1],[3,5],[4,6],[5,7],[6,8.1],[7,9],[8,9],[9,9] )
{{out}}
<pre>(0 0)
(2 -0.1)
(3 5)
(7 9)
(9 9)</pre>
=={{header|Perl 6}}==
|