Пример #1
0
// Returns true if the segment e1-e2 intersects the shape boundary 
// segment s1-s2, blocking visibility.
//
bool segmentShapeIntersect(const Point& e1, const Point& e2, const Point& s1,
        const Point& s2, bool& seenIntersectionAtEndpoint)
{
    if (segmentIntersect(e1, e2, s1, s2))
    {
        // Basic intersection of segments.
        return true;
    }
    else if ( (((s2 == e1) || pointOnLine(s1, s2, e1)) && 
               (vecDir(s1, s2, e2) != 0)) 
              ||
              (((s2 == e2) || pointOnLine(s1, s2, e2)) &&
               (vecDir(s1, s2, e1) != 0)) )
    {
        // Segments intersect at the endpoint of one of the segments.  We
        // allow this once, but the second one blocks visibility.  Otherwise
        // shapes butted up against each other could have visibility through
        // shapes.
        if (seenIntersectionAtEndpoint)
        {
            return true;
        }
        seenIntersectionAtEndpoint = true;
    }
    return false;
}
Пример #2
0
int main()
{
    int x,y;
    BSTNode *root=0;
    Interval *interval=0;

    size_t len;
    char buf[4096];
    FILE *fi = fopen("TestOutput.out", "rb");
    FILE *fo=fopen("logs.txt","a");
    len = fread(buf, sizeof(char), sizeof(buf), fi);

    displayTime(fo);
    fprintf(fo,"Before execution:\n");
    fprintf(fo,"The checksum of %s is %#x\n","output.out", checkSum(buf, len, 0));

    fi=fopen("TestInput.in","r+");
    fo=fopen("TestOutput.out","w");

    //generateInput(nodeNr,intervalNr,pointNr,fi);

    fi=fopen("TestInput.in","r");
    for(int i=1; i<=nodeNr; i++)
    {
        interval=createNewInterval(interval,fi);
        root=insert(root,interval);
        free(interval);

    }
    fprintf(fo,"\n");
    for(int i=1; i<=intervalNr; i++) {
        interval=createNewInterval(interval,fi);
        fprintf(fo,"\n\nQuerry interval: [%d,%d] \n",interval->lo,interval->hi);
        fprintf(fo,"Intersected intervals:\n");
        segmentIntersect(root,interval,fo);
        free(interval);
    }
    for(int i=1; i<=pointNr; i++) {
        fprintf(fo,"\n");
        fscanf(fi,"%d",&x);
        fprintf(fo,"\n\nQuerry point:%d \n",x);
        searchPoint(root,x,fo);
        fprintf(fo,"\n");
    }
    fi = fopen("TestOutput.out", "rb");
    fo=fopen("logs.txt","a");
    len = fread(buf, sizeof(char), sizeof(buf), fi);
    fprintf(fo,"After execution:\n");
    fprintf(fo,"The checksum of %s is %#x\n\n","output.out", checkSum(buf, len, 0));
    return 0;
}
Пример #3
0
bool directVis(VertInf *src, VertInf *dst)
{
    ShapeSet ss = ShapeSet();

    Point& p = src->point;
    Point& q = dst->point;

    VertID& pID = src->id;
    VertID& qID = dst->id;

    // We better be part of the same instance of libavoid.
    Router *router = src->_router;
    COLA_ASSERT(router == dst->_router);

    ContainsMap& contains = router->contains;
    if (pID.isConnPt())
    {
        ss.insert(contains[pID].begin(), contains[pID].end());
    }
    if (qID.isConnPt())
    {
        ss.insert(contains[qID].begin(), contains[qID].end());
    }

    // The "beginning" should be the first shape vertex, rather
    // than an endpoint, which are also stored in "vertices".
    VertInf *endVert = router->vertices.end();
    for (VertInf *k = router->vertices.shapesBegin(); k != endVert;
            k = k->lstNext)
    {
        if ((ss.find(k->id.objID) == ss.end()))
        {
            if (segmentIntersect(p, q, k->point, k->shNext->point))
            {
                return false;
            }
        }
    }
    return true;
}