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 β€” default 1.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 β€” default 0
  • line β€” default undef
  • rc β€” default undef
  • x β€” default undef
  • y β€” default undef

Now the tea on each one:

  • b => FLOAT β€” Only used in combination with option rc to 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. The rc and b are 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 is y= rc*x+b. The rc equals -dy/dx, the firing angle. If undef is explicitly specified then b is used as constant x: it's a vertical mirror. So like, undef is not an error here, it's a choice, and it flips you vertical 🌈
  • x => FLOAT β€” Mirror in the line x=value, which means that y stays unchanged. y is just standing there. Being unchanged. Unbothered. 🌸
  • y => FLOAT β€” Mirror in the line y=value, which means that x stays unchanged. Flip flopped roles, x gets 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 β€” default 0
  • dy β€” default 0
  • dx => 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 β€” default 1.0
  • xscale β€” 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 than 1 = 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 β€” default 0
  • radians β€” default 0
  • center => 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 β€” default undef
  • same β€” default 0.0001
  • slope β€” default undef
  • max_points => INTEGER β€” First, same and slope reduce 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 the same and slope filters 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 than slope longer 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 by polygon_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