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 %options right 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 more Math::Polygon objects.
  • outer β€” default: undef
    • outer => $polygon β€” the outer $polygon, a Math::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 method Math::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 method Math::Polygon::bbox().
  • $obj->perimeter() β€” the length of the border, which is the sum of the outer and inner perimeters. Peep method Math::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 $box get mapped onto the borders. Every polygon is treated separately, no grouping up. πŸ™ˆ
  • $obj->lineClip($box) β€” what you get back is a list of ARRAYS-OF-POINTS containing line pieces from the input surface. Lines coming from outer polygons and inner polygons are undistinguishable from each other. Peep method Math::Polygon::lineClip().
  • $obj->string() β€” translates the surface structure into some string. If you need a standardized format, use Geo::WKT instead, 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 by new(). 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