diff --git a/src/srf/boolean.cpp b/src/srf/boolean.cpp index 17e9d15c..296d6428 100644 --- a/src/srf/boolean.cpp +++ b/src/srf/boolean.cpp @@ -454,49 +454,48 @@ SSurface SSurface::MakeCopyTrimAgainst(SShell *parent, SEdgeList inter = {}; SSurface *ss; - for(ss = agnst->surface.First(); ss; ss = agnst->surface.NextAfter(ss)) { - SCurve *sc; - for(sc = into->curve.First(); sc; sc = into->curve.NextAfter(sc)) { - if(sc->source != SCurve::Source::INTERSECTION) continue; - if(opA) { - if(sc->surfA != h || sc->surfB != ss->h) continue; - } else { - if(sc->surfB != h || sc->surfA != ss->h) continue; - } + SCurve *sc; + for(sc = into->curve.First(); sc; sc = into->curve.NextAfter(sc)) { + if(sc->source != SCurve::Source::INTERSECTION) continue; + if(opA) { + if(sc->surfA != h) continue; + ss = shb->surface.FindById(sc->surfB); + } else { + if(sc->surfB != h) continue; + ss = sha->surface.FindById(sc->surfA); + } + int i; + for(i = 1; i < sc->pts.n; i++) { + Vector a = sc->pts[i-1].p, + b = sc->pts[i].p; - int i; - for(i = 1; i < sc->pts.n; i++) { - Vector a = sc->pts[i-1].p, - b = sc->pts[i].p; + Point2d auv, buv; + ss->ClosestPointTo(a, &(auv.x), &(auv.y)); + ss->ClosestPointTo(b, &(buv.x), &(buv.y)); - Point2d auv, buv; - ss->ClosestPointTo(a, &(auv.x), &(auv.y)); - ss->ClosestPointTo(b, &(buv.x), &(buv.y)); + SBspUv::Class c = (ss->bsp) ? ss->bsp->ClassifyEdge(auv, buv, ss) : SBspUv::Class::OUTSIDE; + if(c != SBspUv::Class::OUTSIDE) { + Vector ta = Vector::From(0, 0, 0); + Vector tb = Vector::From(0, 0, 0); + ret.ClosestPointTo(a, &(ta.x), &(ta.y)); + ret.ClosestPointTo(b, &(tb.x), &(tb.y)); - SBspUv::Class c = (ss->bsp) ? ss->bsp->ClassifyEdge(auv, buv, ss) : SBspUv::Class::OUTSIDE; - if(c != SBspUv::Class::OUTSIDE) { - Vector ta = Vector::From(0, 0, 0); - Vector tb = Vector::From(0, 0, 0); - ret.ClosestPointTo(a, &(ta.x), &(ta.y)); - ret.ClosestPointTo(b, &(tb.x), &(tb.y)); + Vector tn = ret.NormalAt(ta.x, ta.y); + Vector sn = ss->NormalAt(auv.x, auv.y); - Vector tn = ret.NormalAt(ta.x, ta.y); - Vector sn = ss->NormalAt(auv.x, auv.y); - - // We are subtracting the portion of our surface that - // lies in the shell, so the in-plane edge normal should - // point opposite to the surface normal. - bool bkwds = true; - if((tn.Cross(b.Minus(a))).Dot(sn) < 0) bkwds = !bkwds; - if((type == SSurface::CombineAs::DIFFERENCE && !opA) || - (type == SSurface::CombineAs::INTERSECTION)) { // Invert all newly created edges for intersection - bkwds = !bkwds; - } - if(bkwds) { - inter.AddEdge(tb, ta, sc->h.v, 1); - } else { - inter.AddEdge(ta, tb, sc->h.v, 0); - } + // We are subtracting the portion of our surface that + // lies in the shell, so the in-plane edge normal should + // point opposite to the surface normal. + bool bkwds = true; + if((tn.Cross(b.Minus(a))).Dot(sn) < 0) bkwds = !bkwds; + if((type == SSurface::CombineAs::DIFFERENCE && !opA) || + (type == SSurface::CombineAs::INTERSECTION)) { // Invert all newly created edges for intersection + bkwds = !bkwds; + } + if(bkwds) { + inter.AddEdge(tb, ta, sc->h.v, 1); + } else { + inter.AddEdge(ta, tb, sc->h.v, 0); } } }