use strict; use warnings; use feature 'say'; use Data::Dump 'dd'; my @sets = ( [[0,0],[0,2],[2,2],[2,0],[0,0]], [[0,0],[3,0],[3,1],[0,1],[0,0]], [[3,0],[3,2],[4,2],[4,0],[3,0]], [[0,2],[0,3],[1,3],[1,2],[0,2]], ); ######################################## #use Math::Geometry::Planar::GPC::PolygonXS; # ... skipped, don't need it ######################################## use Math::Geometry::Planar; my $poly = Math::Geometry::Planar-> new; $poly-> points( $sets[ 0 ]); for ( 1 .. 3 ) { say "********* case #$_:"; my $clip = Math::Geometry::Planar-> new; $clip-> points( $sets[ $_ ]); my $gpc = GpcClip( 'UNION', $poly-> convert2gpc, $clip-> convert2gpc, ); my @pgons = Gpc2Polygons( $gpc ); dd $pgons[ 0 ]-> cleanup unless $#pgons } __END__ ********* case #1: [[[2, 2], [0, 2], [0, 0], [3, 0], [3, 1], [2, 1]]] ********* case #2: ********* case #3: [[[1, 3], [0, 3], [0, 0], [2, 0], [2, 2], [1, 2]]]