Boost:...:Utils(3pm)

πŸ’– Boost::Geometry::Utils β€” a whole manual but make it cute πŸ’–

okay bestie, so this is Boost::Geometry::Utils, and it lives in the User Contributed Perl Documentation corner of your local perl man pages (so yes, Boost:...:Utils(3pm) is the whole vibe). it's Bindings for the Boost Geometry library ✨


πŸŽ€ NAME πŸŽ€

Boost::Geometry::Utils β€” literally just Bindings for the Boost Geometry library. that's the name, that's the whole personality πŸ’…


🌸 VERSION 🌸

this is version 0.07, bestie. iconic. periodt.


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so here's the whole thing in action. copy it exactly, no cap:

use Boost::Geometry::Utils qw(polygon linestring polygon_linestring_intersection);

my $square = [  # ccw
    [10, 10],
    [20, 10],
    [20, 20],
    [10, 20],
];
my $hole_in_square = [  # cw
    [14, 14],
    [14, 16],
    [16, 16],
    [16, 14],
];
my $polygon = polygon($square, $hole_in_square);
my $linestring = linestring([ [5, 15], [30, 15] ]);

my $intersection = polygon_linestring_intersection($polygon, $linestring);

# $intersection is:
# [
#     [ [10, 15], [14, 15] ],
#     [ [16, 15], [20, 15] ],
# ]

and yes, the comments say # ccw and # cw because orientation matters and the module knows. 🫢


✨ ABSTRACT ✨

so this module gives you bindings so you can do some geometric operations using the Boost Geometry library. it is not trying to give you full bindings for that library β€” which is exactly why the author left the Boost::Geometry namespace free, bestie, he was being polite πŸ™ˆ.

he says he's unsure about the optimal architecture for providing full bindings, but he's interested in that kind of project β€” so if you have ideas, please get in touch with him. collab era πŸ‘‘

⚠️ Warning: the API could change in the future. like, for real. don't get too attached. πŸ’€

πŸ’… METHODS πŸ’…

polygon_linestring_intersection

does an intersection between the polygon you supplied and the linestring you supplied, and hands you back an arrayref of linestrings (each one represented as an arrayref of points). also, fun fact bestie: this kind of intersection is also called clipping. slay.

polygon_multi_linestring_intersection

same as polygon_linestring_intersection, but it accepts a multilinestring object so you can do multiple clippings in a single batch. efficiency queen πŸ‘‘

multi_polygon_multi_linestring_intersection

same as polygon_multi_linestring_intersection, except it accepts a multipolygon object, so again: multiple clippings, one single batch. πŸ’–

multi_linestring_multi_polygon_difference

performs a difference between the multilinestring you supplied and the multipolygon you supplied. returns a multilinestring object. it's giving subtraction but make it geometry 🌈

polygon_to_wkt

converts one or more arrayref(s) of points into a WKT representation of a polygon (with holes). yes, with holes. we love a polygon with lore. πŸ•³οΈ

linestring_to_wkt

converts an arrayref of points into a WKT representation of a multilinestring.

wkt_to_multilinestring

parses a MULTILINESTRING back into a Perl data structure. the round trip is real, fr fr.

linestring_simplify

accepts an arrayref of points representing a linestring and a numeric tolerance, and returns an arrayref of points representing the simplified linestring ✨

multi_linestring_simplify

accepts an arrayref of arrayrefs of points representing a multilinestring and a numeric tolerance, and returns an arrayref of arrayrefs of points representing the simplified linestrings. nesting? we love her. πŸͺ†

point_covered_by_polygon

accepts a point and an arrayref of points representing a polygon, and returns true or false depending on the 'cover_by' strategy.

point_covered_by_multi_polygon

same as above, but it accepts a multipolygon arrayref 🫢

point_within_polygon

accepts a point and an arrayref of points representing a polygon, and returns true or false depending on the 'within' strategy.

point_within_multi_polygon

same as above, but it accepts a multipolygon arrayref πŸ’œ

linestring_length

returns the length of a linestring. measuring tape out πŸ“

polygon_centroid

returns the centroid point of a given polygon.

linestring_centroid

returns the centroid point of a given linestring.

multi_linestring_centroid

returns the centroid point of a given multi_linestring.

correct_polygon

corrects the orientation(s) of the given polygon. it's a glow-up but for winding order πŸ’…

correct_multi_polygon

corrects the orientation(s) of the given multi_polygon.

polygon_area

returns the area of the given polygon. she's got range (literally, area is two-dimensional 😭).


🌟 ACKNOWLEDGEMENTS 🌟

huge thanks to mauke and mst (Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>) for their valuable help in getting this to compile under Windows (MinGW) too. and thanks to Mark Hindness for his work on data types conversion. the real ones fr fr πŸ™Œ


πŸ‘‘ AUTHOR πŸ‘‘

Alessandro Ranellucci <aar@cpan.org>


this software is copyright (c) 2013 by Alessandro Ranellucci.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so go forth and redistribute, bestie πŸ’–


and that's the tea πŸŽ€ this page came to you courtesy of perl v5.42.3, dated 2026-08-19 β€” and the manual name up top was Boost:...:Utils(3pm) in case you forgot where you were. mwah πŸ’‹

πŸ“¦ where this page comes from