my $modified = reduce{
my( $x1, $y1, $x2, $y2 ) = ( @{ @{ $a }[ -1 ] }, @$b );
$x2 < $x1 ? pop @{ $a } : push @{ $a }, $b;
$a;
} [ shift @points ], @points;
####
my $i = 1;
while ($i < @points) {
if ($points[$i-1][0] > $points[$i][0]) {
splice @points,$i-1,2;
--$i or $i = 0;
} else {
$i++;
}
}
####
my $modified = [];
for my $point (@points) {
if (@$modified and $modified->[-1][0] > $point->[0]) {
pop @$modified;
} else {
push @$modified, $point;
}
}
####
my @m;
@m&&$m[-1][0]>$_->[0]?pop @m:push @m,$_ for @points;