1include <BOSL2/std.scad>
 2
 3$fn = 36;
 4
 5rgn1 = [
 6    square(100),
 7    move([50,50], p=circle(d=60)),
 8    [[35,35],[35,65],[65,65]]
 9];
10
11rgn2 = [
12    [[0,0], [100,100], [100,0]],
13    [[27,10], [90,73], [90,10]],
14    move([70,30], p=circle(d=25))
15];
16
17
18polycolor=[0.5,1,0.5];
19outlinecolor="black";
20
21
22module showit(label, rgn, poly=polycolor, outline=outlinecolor, width=0.5) {
23    move([-50,-50]) {
24        if(outline) color(outline) linear_extrude(height=max(0.1,1-width)) for(path=rgn) stroke(path, width=width, closed=true);
25        if(poly) color(poly) linear_extrude(height=0.1) region(rgn);
26        color("black") right(50) fwd(7) linear_extrude(height=0.1) text(text=label, size=8, halign="center", valign="center");
27    }
28}
29
30
31ydistribute(-125) {
32    xdistribute(120) {
33        showit("Region A", rgn1, poly=[1,0,0,0.5]);
34        showit("Region B", rgn2, poly=[0,0,1,0.5]);
35        union() {
36            showit("A and B Overlaid", rgn1, poly=[1,0,0,0.5]);
37            showit("", rgn2, poly=[0,0,1,0.5]);
38        }
39    }
40    xdistribute(120) {
41        showit("Union A+B", union(rgn1, rgn2));
42        showit("Difference A-B", difference(rgn1, rgn2));
43        showit("Intersection A&B", intersection(rgn1, rgn2));
44        showit("Exclusive OR A^B", exclusive_or(rgn1, rgn2));
45    }
46}
47
48// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap