summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2014-01-16 03:23:50 (GMT)
committerMarius Kintel <marius@kintel.net>2014-01-16 03:23:50 (GMT)
commitbf0d9edf38132049a2d8a8f5de4d6e70657a8870 (patch)
tree5559625acd9496f855fd7e377b75ce5318cf7d21
parent1fc52f8cd47213131e0eb76ccf184b5c7388c6b9 (diff)
Change behavior of intersection: intersecting something with an empty object will be empty
-rw-r--r--src/CGALEvaluator.cc5
-rw-r--r--testdata/scad/features/intersection-tests.scad19
-rw-r--r--tests/regression/cgalpngtest/intersection-tests-expected.pngbin7455 -> 7853 bytes
-rw-r--r--tests/regression/dumptest/intersection-tests-expected.csg19
-rw-r--r--tests/regression/opencsgtest/intersection-tests-expected.pngbin7273 -> 7519 bytes
-rw-r--r--tests/regression/throwntogethertest/intersection-tests-expected.pngbin11327 -> 12180 bytes
6 files changed, 43 insertions, 0 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc
index 37d4fd8..60d98b8 100644
--- a/src/CGALEvaluator.cc
+++ b/src/CGALEvaluator.cc
@@ -61,6 +61,11 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr
if (target.dim != 2 && target.dim != 3) {
assert(false && "Dimension of Nef polyhedron must be 2 or 3");
}
+ // Intersecting something with nothing results in nothing
+ if (src.isEmpty() && op == CGE_INTERSECTION) {
+ target = src;
+ return;
+ }
if (src.isEmpty()) return; // Empty polyhedron. This can happen for e.g. square([0,0])
if (target.isEmpty() && op != CGE_UNION) return; // empty op <something> => empty
if (target.dim != src.dim) return; // If someone tries to e.g. union 2d and 3d objects
diff --git a/testdata/scad/features/intersection-tests.scad b/testdata/scad/features/intersection-tests.scad
index 4a1d7e3..d4e32db 100644
--- a/testdata/scad/features/intersection-tests.scad
+++ b/testdata/scad/features/intersection-tests.scad
@@ -39,3 +39,22 @@ translate([-12,12,0]) intersection() {
cube([10,10,10], center=true);
translate([0,-9.99,-9.99]) cube([10,10,10], center=true);
}
+
+// Intersecting something with nothing
+translate([0,-12,0]) intersection() {
+ cylinder(r=4, h=5, center=true);
+ cube(0);
+}
+
+// Intersecting 2D with 3D
+translate([12,-12,0]) intersection() {
+ cube([5,5,5], center=true);
+ circle(r=2);
+}
+
+// Non-geometry (echo) statement as first child should be ignored
+translate([24,-12,0]) intersection() {
+ echo("difference-tests");
+ cube([5,5,5], center=true);
+ cylinder(r=2, h=20, center=true);
+}
diff --git a/tests/regression/cgalpngtest/intersection-tests-expected.png b/tests/regression/cgalpngtest/intersection-tests-expected.png
index d287e5f..0d40a99 100644
--- a/tests/regression/cgalpngtest/intersection-tests-expected.png
+++ b/tests/regression/cgalpngtest/intersection-tests-expected.png
Binary files differ
diff --git a/tests/regression/dumptest/intersection-tests-expected.csg b/tests/regression/dumptest/intersection-tests-expected.csg
index bfb5077..1091c8d 100644
--- a/tests/regression/dumptest/intersection-tests-expected.csg
+++ b/tests/regression/dumptest/intersection-tests-expected.csg
@@ -54,4 +54,23 @@ group() {
}
}
}
+ multmatrix([[1, 0, 0, 0], [0, 1, 0, -12], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ intersection() {
+ cylinder($fn = 0, $fa = 12, $fs = 2, h = 5, r1 = 4, r2 = 4, center = true);
+ cube(size = [0, 0, 0], center = false);
+ }
+ }
+ multmatrix([[1, 0, 0, 12], [0, 1, 0, -12], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ intersection() {
+ cube(size = [5, 5, 5], center = true);
+ circle($fn = 0, $fa = 12, $fs = 2, r = 2);
+ }
+ }
+ multmatrix([[1, 0, 0, 24], [0, 1, 0, -12], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ intersection() {
+ group();
+ cube(size = [5, 5, 5], center = true);
+ cylinder($fn = 0, $fa = 12, $fs = 2, h = 20, r1 = 2, r2 = 2, center = true);
+ }
+ }
}
diff --git a/tests/regression/opencsgtest/intersection-tests-expected.png b/tests/regression/opencsgtest/intersection-tests-expected.png
index 772e2dc..3cc588f 100644
--- a/tests/regression/opencsgtest/intersection-tests-expected.png
+++ b/tests/regression/opencsgtest/intersection-tests-expected.png
Binary files differ
diff --git a/tests/regression/throwntogethertest/intersection-tests-expected.png b/tests/regression/throwntogethertest/intersection-tests-expected.png
index f6cc56f..6dee3c6 100644
--- a/tests/regression/throwntogethertest/intersection-tests-expected.png
+++ b/tests/regression/throwntogethertest/intersection-tests-expected.png
Binary files differ
contact: Jan Huwald // Impressum