ZIntCuboidFaceArray ZIntCuboidFace::cropBy(const ZIntCuboidFace &face) const { ZIntCuboidFaceArray faceArray; if (hasOverlap(face)) { if (isWithin(face)) { return faceArray; } else { ZIntCuboidFace subface(getAxis(), isNormalPositive()); subface.setZ(getPlanePosition()); subface.set(getFirstCorner(), Corner(getUpperBound(0), face.getLowerBound(1) - 1)); faceArray.appendValid(subface); subface.set(Corner(getLowerBound(0), imax2(getLowerBound(1), face.getLowerBound(1))), Corner(face.getLowerBound(0) - 1, getUpperBound(1))); faceArray.appendValid(subface); subface.set(Corner(face.getUpperBound(0) + 1, imax2(getLowerBound(1), face.getLowerBound(1))), getLastCorner()); faceArray.appendValid(subface); subface.set(Corner(imax2(getLowerBound(0), face.getLowerBound(0)), face.getUpperBound(1) + 1), Corner(imin2(getUpperBound(0), face.getUpperBound(0)), getUpperBound(1))); faceArray.appendValid(subface); } #if 0 else if (face.isWithin(*this)) { ZIntCuboidFace subface(getAxis(), isNormalPositive()); secondCorner.set(getUpperBound(0), face.getLowerBound(1)); subface.set(getFirstCorner(), secondCorner); faceArray.appendValid(subface); subface.set(Corner(getLowerBound(0), face.getLowerBound(1)), face.getCorner(2)); faceArray.appendValid(subface); subface.set(Corner(getLowerBound(0), face.getUpperBound(1)), getLastCorner()); faceArray.appendValid(subface); } else { } #endif } else {
ZIntCuboidFaceArray ZIntCuboidFace::cropBy( const ZIntCuboidFaceArray &faceArray) const { ZIntCuboidFaceArray result; result.appendValid(*this); for (ZIntCuboidFaceArray::const_iterator iter = faceArray.begin(); iter != faceArray.end(); ++iter) { const ZIntCuboidFace &face = *iter; result = result.cropBy(face); if (result.empty()) { //No need to continue on empty face break; } } return result; }