mirror of https://github.com/vitalif/openscad
Regression fix: n-ary 2d intersection() with n != 2
parent
b05eb736a0
commit
c25ead11ff
|
@ -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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
Loading…
Reference in New Issue