Math::...n::Clip(3pm)
π Math::...n::Clip β bestie edition π
okay so real talk, this page lives in the User Contributed Perl Documentation pile, and it's about taking a polygon and β¨shoving it into a boxβ¨. no cap.
πΈ NAME πΈ
Math::Polygon::Clip β frame a polygon in a square πΌοΈ
like⦠picture a polygon that's being a little too much, going places it shouldn't. this module gives it a box to stay in. iconic behavior, honestly.
𧬠INHERITANCE π§¬
Math::Polygon::Clip
is an Exporter
so yeah, it's an Exporter, which means it hands you functions directly β you don't gotta do the whole Math::Polygon::Clip:: song and dance, iykyk π«Ά
β¨ SYNOPSIS β¨
here's the vibe in code form, copy-paste energy:
my @poly = ( [1,2], [2,4], [5,7], [1, 2] );
my @box = ( $xmin, $ymin, $xmax, $ymax );
my $boxed = polygon_clip \@box, @poly;
that's it. that's the whole glow-up. your polygon walks in messy, walks out framed π
π DESCRIPTION π
Cut-off all parts of the polygon which are outside the box.
literally just that, bestie. anything hanging outside the box? gone. βοΈ bye.
π οΈ FUNCTIONS π οΈ
okay this is the good part, the main character section π
polygon_fill_clip1(\@box, @points)
Clipping a polygon into rectangles can be done in various ways β there's options, there's range, we love that for us. With this algorithm (which the author designed himself, but it may not be new, humble king behavior π), the parts of the polygon which are outside the @box are mapped on the borders. The polygon stays in one piece. π§©
Returned is one list of points, which is cleaned from double points, spikes and superfluous intermediate points. so it comes out tidy, no stray crumbs left behind π
polygon_fill_clip2(\@box, @points)
To be implemented. π not done yet, bestie, it's giving "coming soon" energy.
The plan: the polygon falls apart in fragments, which are not connected: paths which are followed in two directions are removed. This is required by some applications, like polygons used in geographical context (country contours and such). π like when you're doing map stuff and you need the pieces to actually come apart properly.
polygon_fill_clip3( \@box, $out-$poly, [$in-$polys] )
To be implemented. π also not done yet.
The plan here: A surrounding polygon, with possible inclussions. (that's how the original spells it, we keep it exactly as-is, no editing the queen's spelling βοΈ)
polygon_line_clip(\@box, @points)
Returned is a list of ARRAYS (possibly 0 long) containing line pieces from the input polygon (or line). so sometimes you get zero, sometimes you get a bunch β it's a whole range, it's flexible, we respect it π
example:
my @points = ( [1,2], [2,3], [2,0], [1,-1], [1,2] );
my @bbox = ( 0, -2, 2, 2 );
my @l = polygon_line_clip \@bbox, @points;
print scalar @l; # 1, only one piece found
my @first = @{$l[0]}; # first is [2,0], [1,-1], [1,2]
see that? one piece found, and the first one is [2,0], [1,-1], [1,2]. ate. π₯
π SEE ALSO π
This module is part of Math-Polygon version 2.00, built on September 04, 2025. Website: http://perl.overmeer.net/CPAN/
go visit, it's the source, it's the origin story π
π LICENSE π
For contributors see file ChangeLog.
This software is copyright (c) 2004-2025 by Mark Overmeer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
free software!! the way that it's free π«Ά use it, remix it, live your truth.
<div align="center">
and that's a wrap, bestie π this whole page was served up by perl v5.40.1, dated 2025-10-04, under the name Math::...n::Clip(3pm). love that for us. mwah πβ¨
</div>
π¦ where this page comes from
- ubuntu resolute: libmath-polygon-perl 2.00-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmath-polygon-perl 2.00-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms