Regression fix: n-ary 2d intersection() with n != 2

translation1
Oskar Linde 2014-01-27 15:07:30 +01:00 committed by Oskar Linde
parent b05eb736a0
commit c25ead11ff
1 changed files with 28 additions and 1 deletions

View File

@ -342,6 +342,14 @@ Polygon2d *GeometryEvaluator::applyToChildren2D(const AbstractNode &node, OpenSC
std::vector<const Polygon2d *> children = collectChildren2D(node);
if (children.empty()) {
return NULL;
}
if (children.size() == 1) {
return new Polygon2d(*children[0]); // Copy
}
ClipperLib::ClipType clipType;
switch (op) {
case OPENSCAD_UNION:
@ -359,7 +367,26 @@ Polygon2d *GeometryEvaluator::applyToChildren2D(const AbstractNode &node, OpenSC
break;
}
return ClipperUtils::apply(children, clipType);
if (clipType == ClipperLib::ctIntersection && !children.empty()) {
// intersection operations must be split into a sequence of binary operations
std::vector<const Polygon2d *> operands(2);
operands[0] = children[0];
for (int i = 1; i < children.size(); i++) {
operands[1] = children[i];
Polygon2d * result = ClipperUtils::apply(operands, clipType);
if (operands[0] != children[0]) delete operands[0];
operands[0] = result;
}
assert(children.size() >= 2);
// We know that this is ok
return const_cast<Polygon2d *>(operands[0]);
}
else {
return ClipperUtils::apply(children, clipType);
}
}
/*!