示例#1
0
/*private*/
void
MonotoneChain::computeOverlaps(size_t start0, size_t end0,
                               MonotoneChain& mc,
                               size_t start1, size_t end1,
                               MonotoneChainOverlapAction& mco)
{
    //Debug.println("computeIntersectsForChain:"+p00+p01+p10+p11);
    // terminating condition for the recursion
    if (end0-start0==1 && end1-start1==1)
    {
        mco.overlap(*this, start0, mc, start1);
        return;
    }

    const Coordinate& p00 = pts[start0];
    const Coordinate& p01 = pts[end0];
    const Coordinate& p10 = mc.pts[start1];
    const Coordinate& p11 = mc.pts[end1];

    // nothing to do if the envelopes of these chains don't overlap
    mco.tempEnv1.init(p00, p01);
    mco.tempEnv2.init(p10, p11);
    if (!mco.tempEnv1.intersects(mco.tempEnv2)) return;

    // the chains overlap,so split each in half and iterate (binary search)
    size_t mid0=(start0+end0)/2;
    size_t mid1=(start1+end1)/2;

    // Assert: mid != start or end (since we checked above for
    // end-start <= 1)
    // check terminating conditions before recursing
    if (start0<mid0)
    {
        if (start1<mid1)
            computeOverlaps(start0, mid0, mc, start1, mid1, mco);
        if (mid1<end1)
            computeOverlaps(start0, mid0, mc, mid1, end1, mco);
    }
    
    if (mid0<end0)
    {
        if (start1<mid1)
            computeOverlaps(mid0, end0, mc, start1, mid1, mco);
        if (mid1<end1)
            computeOverlaps(mid0, end0, mc, mid1, end1, mco);
    }
}
示例#2
0
/*private*/
void
MonotoneChain::computeOverlaps(size_t start0, size_t end0,
                               MonotoneChain& mc,
                               size_t start1, size_t end1,
                               MonotoneChainOverlapAction& mco)
{
    // terminating condition for the recursion
    if(end0 - start0 == 1 && end1 - start1 == 1) {
        mco.overlap(*this, start0, mc, start1);
        return;
    }

    // nothing to do if the envelopes of these subchains don't overlap
    if(!overlaps(start0, end0, mc, start1, end1)) {
        return;
    }

    // the chains overlap,so split each in half and iterate (binary search)
    size_t mid0 = (start0 + end0) / 2;
    size_t mid1 = (start1 + end1) / 2;

    // Assert: mid != start or end (since we checked above for
    // end-start <= 1)
    // check terminating conditions before recursing
    if(start0 < mid0) {
        if(start1 < mid1) {
            computeOverlaps(start0, mid0, mc, start1, mid1, mco);
        }
        if(mid1 < end1) {
            computeOverlaps(start0, mid0, mc, mid1, end1, mco);
        }
    }

    if(mid0 < end0) {
        if(start1 < mid1) {
            computeOverlaps(mid0, end0, mc, start1, mid1, mco);
        }
        if(mid1 < end1) {
            computeOverlaps(mid0, end0, mc, mid1, end1, mco);
        }
    }
}