Math::...urface(3pm)
π Math::Polygon::Surface π
okay bestie, so this is a page from the User Contributed Perl Documentation section, manual page Math::...urface(3pm) β yes the name is truncated like that, it's giving mystery, iykyk β¨
πΈ NAME πΈ
Math::Polygon::Surface β Polygon with exclusions π«Ά
β¨ SYNOPSIS β¨
my $outer = Math::Polygon->new( [1,2], [2,4], [5,7], [1,2] );
my $surface = Math::Polygon::Surface->new($outer);
π¦ DESCRIPTION π¦
So like, a surface is one polygon that's the outer bounds of an array β the main character π β plus, optionally, a whole list of polygons that represent exclusions from that outer polygon. Think of it as the polygon but with little cutouts, and honestly? Obsessed. π
π METHODS π
π§ Constructors
$any->new( [%options], [@polygons], %options )β the vibe is: you may merge%optionsright in with@polygons, nbg. You can also use the"outer"and"inner"options.
Okay so each polygon is a reference to an ARRAY of points, and each point is an ARRAY of X and Y. But fr fr, just pass Math::Polygon objects instead, it's way better. π
Here's the option tea:
innerβ default:[]inner => \@polygonsβ the inner@polygons, zero or moreMath::Polygonobjects.
outerβ default:undefouter => $polygonβ the outer$polygon, aMath::Polygon.
π Attributes
$obj->inner()β hands you a list (often empty, and that's fine, it's valid π₯Ί) of inner polygons.$obj->outer()β hands you the outer polygon. Periodt.
π Simple calculations
area()β gives you the area enclosed by the outer polygon, minus the areas of all the inner polygons. Peep methodMath::Polygon::area()for the deets.$obj->bbox()β returns a list of four elements:(xmin, ymin, xmax, ymax), which describe the bounding box of the surface, and that bbox is literally the bbox of the outer polygon. Peep methodMath::Polygon::bbox().$obj->perimeter()β the length of the border, which is the sum of the outer and inner perimeters. Peep methodMath::Polygon::perimeter().
β Clipping
$obj->fillClip1($box)β so clipping a polygon into rectangles can be done in various ways (many paths, many vibes). With this algorithm, the parts of the polygon that sit outside the$boxget mapped onto the borders. Every polygon is treated separately, no grouping up. π$obj->lineClip($box)β what you get back is a list ofARRAYS-OF-POINTScontaining line pieces from the input surface. Lines coming from outer polygons and inner polygons are undistinguishable from each other. Peep methodMath::Polygon::lineClip().$obj->string()β translates the surface structure into some string. If you need a standardized format, useGeo::WKTinstead, bestie. What you get back is a single string that possibly contains multiple lines: the first line is the outer, and the other lines represent the inner polygons. π
π DIAGNOSTICS π
Error: surface requires outer polygonβ cast bynew(). Yeah, no outer polygon, no surface. It said what it said. π
π₯ SEE ALSO π₯
This module is part of Math-Polygon version 2.00, built on September 04, 2025. Website: http://perl.overmeer.net/CPAN/ π
π 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. π«Ά
and that's a wrap, babe β¨ this whole thing shipped with perl v5.40.1 on 2025-10-04, and it lives in the Math::...urface(3pm) page β slay, go clip some polygons π
π¦ 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