Simplify UNION and DIFFERENCE boolean operations.

Union and difference are optimized by replacing the expression
  (!inShell && !inFace)
which is equivqlent to
  (!inShell && !inSame && !inOpp)
with
  outSide
which is equivalent, since SShell::Class::OUTSIDE is the only remaining possibility.
This commit is contained in:
ruevs 2019-11-23 15:22:15 +02:00 committed by whitequark
parent b5ccf5acf5
commit ec3056773e

View File

@ -193,28 +193,24 @@ void SSurface::TrimFromEdgeList(SEdgeList *el, bool asUv) {
static bool KeepRegion(SSurface::CombineAs type, bool opA, SShell::Class shell, SShell::Class orig) static bool KeepRegion(SSurface::CombineAs type, bool opA, SShell::Class shell, SShell::Class orig)
{ {
bool inShell = (shell == SShell::Class::INSIDE), bool inShell = (shell == SShell::Class::INSIDE),
outSide = (shell == SShell::Class::OUTSIDE),
inSame = (shell == SShell::Class::COINC_SAME), inSame = (shell == SShell::Class::COINC_SAME),
inOpp = (shell == SShell::Class::COINC_OPP),
inOrig = (orig == SShell::Class::INSIDE); inOrig = (orig == SShell::Class::INSIDE);
bool inFace = inSame || inOpp;
// If these are correct, then they should be independent of inShell
// if inFace is true.
if(!inOrig) return false; if(!inOrig) return false;
switch(type) { switch(type) {
case SSurface::CombineAs::UNION: case SSurface::CombineAs::UNION:
if(opA) { if(opA) {
return (!inShell && !inFace); return outSide;
} else { } else {
return (!inShell && !inFace) || inSame; return outSide || inSame;
} }
case SSurface::CombineAs::DIFFERENCE: case SSurface::CombineAs::DIFFERENCE:
if(opA) { if(opA) {
return (!inShell && !inFace); return outSide;
} else { } else {
return (inShell && !inFace) || inSame; return inShell || inSame;
} }
default: ssassert(false, "Unexpected combine type"); default: ssassert(false, "Unexpected combine type");