| 1 |
=encoding utf8 |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Math::Polygon::Clip - frame a polygon in a square |
| 6 |
|
| 7 |
=head1 INHERITANCE |
| 8 |
|
| 9 |
Math::Polygon::Clip |
| 10 |
is an Exporter |
| 11 |
|
| 12 |
=head1 SYNOPSIS |
| 13 |
|
| 14 |
my @poly = ( [1,2], [2,4], [5,7], [1, 2] ); |
| 15 |
my @box = ( $xmin, $ymin, $xmax, $ymax ); |
| 16 |
|
| 17 |
my $boxed = polygon_clip \@box, @poly; |
| 18 |
|
| 19 |
=head1 DESCRIPTION |
| 20 |
|
| 21 |
Cut-off all parts of the polygon which are outside the box |
| 22 |
|
| 23 |
=head1 FUNCTIONS |
| 24 |
|
| 25 |
=over 4 |
| 26 |
|
| 27 |
=item B<polygon_fill_clip1>(\@box, @points) |
| 28 |
|
| 29 |
Clipping a polygon into rectangles can be done in various ways. |
| 30 |
With this algorithm (which I designed myself, but may not be new), the |
| 31 |
parts of the polygon which are outside the C<@box> are mapped on the borders. |
| 32 |
The polygon stays in one piece. |
| 33 |
|
| 34 |
Returned is one list of points, which is cleaned from double points, |
| 35 |
spikes and superfluous intermediate points. |
| 36 |
|
| 37 |
=item B<polygon_fill_clip2>(\@box, @points) |
| 38 |
|
| 39 |
B<To be implemented>. The polygon falls apart in fragments, which are not |
| 40 |
connected: paths which are followed in two directions are removed. |
| 41 |
This is required by some applications, like polygons used in geographical |
| 42 |
context (country contours and such). |
| 43 |
|
| 44 |
=item B<polygon_fill_clip3>( \@box, $out-$poly, [$in-$polys] ) |
| 45 |
|
| 46 |
B<To be implemented>. A surrounding polygon, with possible |
| 47 |
inclussions. |
| 48 |
|
| 49 |
=item B<polygon_line_clip>(\@box, @points) |
| 50 |
|
| 51 |
Returned is a list of ARRAYS (possibly 0 long) containing line pieces |
| 52 |
from the input polygon (or line). |
| 53 |
|
| 54 |
example: |
| 55 |
|
| 56 |
my @points = ( [1,2], [2,3], [2,0], [1,-1], [1,2] ); |
| 57 |
my @bbox = ( 0, -2, 2, 2 ); |
| 58 |
my @l = polygon_line_clip \@bbox, @points; |
| 59 |
print scalar @l; # 1, only one piece found |
| 60 |
my @first = @{$l[0]}; # first is [2,0], [1,-1], [1,2] |
| 61 |
|
| 62 |
=back |
| 63 |
|
| 64 |
=head1 SEE ALSO |
| 65 |
|
| 66 |
This module is part of Math-Polygon version 2.00, |
| 67 |
built on September 04, 2025. Website: F<http://perl.overmeer.net/CPAN/> |
| 68 |
|
| 69 |
=head1 LICENSE |
| 70 |
|
| 71 |
For contributors see file ChangeLog. |
| 72 |
|
| 73 |
This software is copyright (c) 2004-2025 by Mark Overmeer. |
| 74 |
|
| 75 |
This is free software; you can redistribute it and/or modify it under |
| 76 |
the same terms as the Perl 5 programming language system itself. |
| 77 |
|