Math::...nsform(3pm)
π Math::Polygon::Transform β bestie edition π
okay so you found the polygon glow-up module, and I am obsessed. This page lives in the User Contributed Perl Documentation section of your manual, and it's literally all about taking a polygon and β¨transformingβ¨ it. Sit down, hydrate, let's go π«Ά
πΈ NAME πΈ
Math::Polygon::Transform β Polygon transformation. That's it, that's the whole vibe. It transforms polygons. periodt π
π¦ INHERITANCE π¦
Math::Polygon::Transform is an Exporter. So it hands out its functions to you like friendship bracelets, no cap π
β¨ SYNOPSIS β¨
Here's the group-chat screenshot of what using it looks like:
my @poly = ( [1,2], [2,4], [5,7], [1, 2] );
my $area = polygon_transform resize => 3.14, @poly;
# requires [2.00]
my $area = polygon_transform +{resize => 3.14}, @poly;
See that second call style? That one needs version [2.00] or later, so don't be out here with an ancient install, bestie π
π DESCRIPTION π
This package contains polygon transformation algorithms. That's the whole description. It's giving "confident, minimal, doesn't over-explain" and honestly? Iconic. π
π₯ FUNCTIONS π₯
π polygon_grid(%options|\%options, @points)
Snap the polygon points to grid points, where artifacts are removed. Basically you're telling your messy little points to sit up straight and align themselves on the grid, bye messy edges β¨
Options and their defaults:
rasterβ default1.0
And here's what raster actually does:
raster => FLOATβ The raster size, which determines the points to round to. The origin[0,0]is always on a grid-point. When the raster value is zero, no transformation will take place. Zero means nothing happens. Not "a little" β nothing. Zero. Nada. π«
π§ polygon_mirror(%options|\%options, @points)
Mirror the polygon in a line. Only one of the options can be provided. Some programs call this "flip" or "flop". We call it a mirror, because we're classy like that π
β οΈ heads up bestie: only ONE of these options can be given. Pick your lane.
Options and defaults:
bβ default0lineβ defaultundefrcβ defaultundefxβ defaultundefyβ defaultundef
Now the tea on each one:
b => FLOATβ Only used in combination with optionrcto describe a line. It doesn't get to do anything on its own, it's a supporting character π«Άline => [POINT, POINT]β Alternative way to specify the mirror line. Thercandbare computed from the two points of the line. So you hand it two points and it figures out the math for you. Main character energy, let the module do the homework πrc => FLOATβ Description of the line which is used to mirror in. The line isy= rc*x+b. Thercequals-dy/dx, the firing angle. Ifundefis explicitly specified thenbis used as constant x: it's a vertical mirror. So like,undefis not an error here, it's a choice, and it flips you vertical πx => FLOATβ Mirror in the linex=value, which means thatystays unchanged.yis just standing there. Being unchanged. Unbothered. πΈy => FLOATβ Mirror in the liney=value, which means thatxstays unchanged. Flip flopped roles,xgets to chill π
π polygon_move(%options|\%options, @points)
Returns a list of points which are moved over the indicated distance. You're just sliding the whole polygon over, no drama, no rotation, just vibes and displacement β¨
Options and defaults:
dxβ default0dyβ default0dx => FLOATβ Displacement in the horizontal direction. Left/right situation π«dy => FLOATβ Displacement in the vertical direction. Up/down situation π«
example:
my @moved = polygon_move dx => -5.12, @points;
my @moved = polygon_move +{dx => -5.12}, @points; # since [2.00]
That second style? Same deal as before β needs [2.00], iykyk π
π¦ polygon_resize(%options|\%options, @points)
Make the polygon smaller or larger, with respect to a center. Grow it, shrink it, glow it up π¦
Options and their defaults:
centerβ default[0,0]scaleβ default1.0xscaleβ default<scale>yscaleβ default<scale>center => POINTβ the point everything scales relative to. The anchor. The main character everyone orbits around πscale => FLOATβ Resize the polygon with the indicated factor. When the factor is larger than 1, the resulting polygon with grow, when small it will be reduced in size. The scale will be respective from the center. So bigger than1= glowed up, smaller = minimized, and it all happens relative to the center πxscale => FLOATβ Specific scaling factor in the horizontal direction. Stretch just the x-axis, live your truth β¨yscale => FLOATβ Specific scaling factor in the vertical direction. Stretch just the y-axis, also valid π
π« polygon_rotate(%options|\%options, @points)
Rotate a polygon around a center. Spinning. Twirling. SLAY π
Options and defaults:
centerβ default[0,0]degreesβ default0radiansβ default0center => POINTβ the pivot point you're spinning around πΈdegrees => FLOATβ specify rotation angle in degrees (between -180 and 360). Keep it in that range, bestie. πradians => FLOATβ specify rotation angle in rads (between -pi and 2*pi). Yeah, "rads". That's what it says. We're keeping it exactly as written, no cap π₯
π polygon_simplify(%options|\%options, @points)
Trim down your point count so your polygon stops rambling like a 3am voice memo π
Options and defaults:
max_pointsβ defaultundefsameβ default0.0001slopeβ defaultundefmax_points => INTEGERβ First,sameandslopereduce the number of points. Then, if there are still more than the specified number of points left, the points with the widest angles will be removed until the specified maximum number is reached. So it's a two-stage glow-down: first thesameandslopefilters do their thing, then the widest-angle points get cut until you hit your number βοΈsame => FLOATβ The distance between two points to be considered "the same" point. The value is used as radius of the circle. Two points that close together? Yeah, the module says they're the same, they're basically twins at that point πslope => FLOATβ With three points X(n),X(n+1),X(n+2), the point X(n+1) will be removed if the length of the path over all three points is less thanslopelonger than the direct path between X(n) and X(n+2). Okay so real talk: if the detour through the middle point isn't meaningfully longer than the shortcut, the middle point gets deleted.
The slope will not be removed around the starting point of the polygon. Removing points will change the area of the polygon.
β οΈ bestie, read that again: removing points will change the area of the polygon. That's not a bug, that's just geometry being geometry. Do not come for me later. π
π DIAGNOSTICS π
Error: you need to specify 'x', 'y', 'rc', or 'line'β Cast bypolygon_mirror(). Yep, that's the "you gave me nothing to mirror in, bestie" error π
π SEE ALSO π
This module is part of Math-Polygon version 2.00, built on September 04, 2025. Website: http://perl.overmeer.net/CPAN/ β go say hi, tell 'em I sent you π«Ά
π 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 the whole page, bestie!! π This one's for perl v5.40.1, dated 2025-10-04, and it rendered in the Math::...nsform(3pm) corner of the manual. Go transform something pretty πΈβ¨π¦π
π¦ 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