8 my $state = /^on / ? 1 : 0;
9 my ($xmin, $xmax, $ymin, $ymax, $zmin, $zmax) = /-?\d+/g;
10 ($xmin, $xmax) = ($xmax, $xmin) if $xmax < $xmin;
11 ($ymin, $ymax) = ($ymax, $ymin) if $ymax < $ymin;
12 ($zmin, $zmax) = ($zmax, $zmin) if $zmax < $zmin;
13 say "cuboid ", join(',', $xmin, $xmax, $ymin, $ymax, $zmin, $zmax, $state);
14 push @cuboids, [$xmin, $xmax, $ymin, $ymax, $zmin, $zmax, $state];
18 my ($min1, $max1, $min2, $max2) = @_;
19 return ($min1 >= $min2 && $min1 <= $max2)
20 || ($max1 >= $min2 && $max1 <= $max2)
21 || ($min1 <= $min2 && $max1 >= $max2)
22 || ($min1 >= $min2 && $max1 <= $max2);
26 my ($c1, $c2, $axis) = @_;
28 return overlaps_int($c1->[$axis], $c1->[$axis+1], $c2->[$axis], $c2->[$axis+1]);
32 for my $c1 (@cuboids) {
36 my $c2 = shift @nonint;
37 say "[", join(',', @$c1), "] and\n[", join(',', @$c2), "] test for overlap";
38 if (($c1->[0] > $c2->[0] && $c1->[0] <= $c2->[1])
39 && overlaps_axis($c1, $c2, 1)
40 && overlaps_axis($c1, $c2, 2)) {
47 say "split at xmin=$c1->[0] :\n", join(',', @{ $nonint[-2] }), "\n", join(',', @{ $nonint[-1] }) ;
50 if (($c1->[1] >= $c2->[0] && $c1->[1] < $c2->[1])
51 && overlaps_axis($c1, $c2, 1)
52 && overlaps_axis($c1, $c2, 2)) {
59 say "split at xmax=$c1->[1] :\n", join(',', @{ $nonint[-2] }), "\n", join(',', @{ $nonint[-1] }) ;
62 if (($c1->[2] > $c2->[2] && $c1->[2] <= $c2->[3])
63 && overlaps_axis($c1, $c2, 0)
64 && overlaps_axis($c1, $c2, 2)) {
71 say "split at ymin=$c1->[2] :\n", join(',', @{ $nonint[-2] }), "\n", join(',', @{ $nonint[-1] }) ;
74 if (($c1->[3] >= $c2->[2] && $c1->[3] < $c2->[3])
75 && overlaps_axis($c1, $c2, 0)
76 && overlaps_axis($c1, $c2, 2)) {
83 say "split at ymax=$c1->[3] :\n", join(',', @{ $nonint[-2] }), "\n", join(',', @{ $nonint[-1] }) ;
86 if (($c1->[4] > $c2->[4] && $c1->[4] <= $c2->[5])
87 && overlaps_axis($c1, $c2, 0)
88 && overlaps_axis($c1, $c2, 1)) {
95 say "split at zmin=$c1->[4] :\n", join(',', @{ $nonint[-2] }), "\n", join(',', @{ $nonint[-1] }) ;
98 if (($c1->[5] >= $c2->[4] && $c1->[5] < $c2->[5])
99 && overlaps_axis($c1, $c2, 0)
100 && overlaps_axis($c1, $c2, 1)) {
103 push @nonint, [ @c ];
106 push @nonint, [ @c ];
107 say "split at zmax=$c1->[5] :\n", join(',', @{ $nonint[-2] }), "\n", join(',', @{ $nonint[-1] }) ;
110 if (($c1->[0] <= $c2->[0] && $c1->[1] >= $c2->[1])
111 && ($c1->[2] <= $c2->[2] && $c1->[3] >= $c2->[3])
112 && ($c1->[4] <= $c2->[4] && $c1->[5] >= $c2->[5])) {
113 say "[", join(',', @$c1), "] fully encloses \n[", join(',', @$c2), "] = enclosed";
115 say "[", join(',', @$c1), "] and\n[", join(',', @$c2), "] do not overlap";
119 push @nonint2, $c1 if $c1->[6];
123 for my $c1 (@nonint) {
124 my $size = ($c1->[1] - $c1->[0] + 1)
125 * ($c1->[3] - $c1->[2] + 1)
126 * ($c1->[5] - $c1->[4] + 1);
127 say "final: [", join(',', @$c1), "] = $size";