示例#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
//--------------------------------------------------------------
// circleCenter = from.getInterpolated(to, ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 1));
void testApp::draw(){
    from1X,from1Y,to1X,to1Y=int(ofRandom(0,ofGetHeight()));
    
      from1.set(from1X, from1Y);
    
    to1.set(ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, ofGetWidth()-10), ofMap(cos(ofGetElapsedTimef()), -1, 1, 0, ofGetHeight()-10));
    
    from = pointOnLine(ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 1), from1, to1);

    to.set  (ofGetWidth()/2, ofGetHeight()/2);
    
    float t = ofGetElapsedTimef() - ((int)ofGetElapsedTimef());
    
    t = powf(1 - t, 2);
    
    circleCenter = pointOnLine(ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 1), from, to);
    
    // draw circle
    ofCircle(circleCenter, 1);
    ofCircle(-circleCenter, 1);
    
    ofCircle(from, 2);
    //ofCircle(to, 2);
    //ofLine(from, to);
    
    //ofCircle(from1, 2);
    //ofCircle(to1, 2);
    //ofLine(from1, to1);
    
    
}
示例#3
0
 void Edge::nodePath(vector<Node*>& nodes) {
     list<unsigned> ds(dummyNodes.size());
     copy(dummyNodes.begin(),dummyNodes.end(),ds.begin());
     //printf("Edge::nodePath: (%d,%d) dummyNodes:%d\n",startNode,endNode,ds.size());
     path.clear();
     path.push_back(startNode);
     for(unsigned i=1;i<route->n;i++) {
         //printf("  checking segment %d-%d\n",i-1,i);
         set<pair<double,unsigned> > pntsOnLineSegment;
         for(list<unsigned>::iterator j=ds.begin();j!=ds.end();) {
             double px=nodes[*j]->x;
             double py=nodes[*j]->y;
             double ax=route->xs[i-1];
             double ay=route->ys[i-1];
             double bx=route->xs[i];
             double by=route->ys[i];
             double t=0;
             list<unsigned>::iterator copyit=j++;
             //printf("     px=%f, py=%f, ax=%f, ay=%f, bx=%f, by=%f\n",px,py,ax,ay,bx,by);
             if(pointOnLine(px,py,ax,ay,bx,by,t)) {
                 //printf(" got node %d\n",*copyit);
                 pntsOnLineSegment.insert(make_pair(t,*copyit));
                 ds.erase(copyit);
             }
         }
         for(set<pair<double,unsigned> >::iterator j=pntsOnLineSegment.begin();j!=pntsOnLineSegment.end();j++) {
             path.push_back(j->second);
         }
         //printf("\n");
     }
     path.push_back(endNode);
     assert(ds.empty());
 }
示例#4
0
//--------------------------------------------------------------
void testApp::draw(){

    ofPoint from, to, circleCenter;

//    from.set(50,            ofGetHeight()/2);
    from.set(50,            ofGetHeight()/2 * sin(  ofGetElapsedTimef() ) );

    to.set(ofGetWidth()-50, ofGetHeight()/2);
    
//    circleCenter = pointOnLine(0.25, from, to);
    
//    circleCenter = pointOnLine( sin(ofGetElapsedTimef()), from, to);

    circleCenter = pointOnLine( ofMap(  sin(ofGetElapsedTimef()), -1, 1, 0, 1), from, to);

    
    //drawline
    ofCircle(circleCenter, 10);
    
    //Drawcontrol points
    ofCircle(from, 2);
    ofCircle(to, 2);
    ofLine(from, to);
    
    //interpolate();
    
}
//--------------------------------------------------------------
// circleCenter = from.getInterpolated(to, ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 1));
void testApp::draw(){
    ofPoint from, to, circleCenter, from1, to1;
    from1.set(0, 0);
    to1.set(ofGetWidth(), 0);
    
    // from = pointOnLine( ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 1), from1, to1);
    from.set(300,                ofGetHeight()/2);
    to.set  (ofGetWidth() - 300, ofGetHeight()/2);
    
    //float t = decimal of elapsed time - int of elapsed time
    //returns a value between 0 and 1
    float t = ofGetElapsedTimef() - ((int)ofGetElapsedTimef());
    
    //print to serial
    //cout << ((int)ofGetElapsedTimef()) << endl;
    
    
    t = sqrt(1 - powf(1 - t, 2));
    
    circleCenter = pointOnLine( t, from, to);
    
    // draw circle
    ofCircle(circleCenter, 10);
    
    // draw control points and line
    ofCircle(from, 2);
    ofCircle(to, 2);
    ofLine(from, to);

    ofCircle(from1, 2);
    ofCircle(to1, 2);
    ofLine(from1, to1);
    
    
}
void testApp::draw(){
    ofPoint from, to, circleCenter, from1, to1;
    from1.set(0, 0);
    to1.set(ofGetWidth(), 0);
    
    // from = pointOnLine( ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 1), from1, to1);
    from.set(300, ofGetHeight()/2);
    to.set  (ofGetWidth() - 300, ofGetHeight()/2);
    
    float t = ofGetElapsedTimef() - ((int)ofGetElapsedTimef());
    
    t = sqrt(1 - powf(1 - t, 2));
    
    circleCenter = pointOnLine( t, from, to);
    
    // draw circle
    ofCircle(circleCenter, 10);
    
    // draw control points and line
    ofCircle(from, 2);
    ofCircle(to, 2);
    ofLine(from, to);
    
    ofCircle(from1, 2);
    ofCircle(to1, 2);
    ofLine(from1, to1);
    
}
示例#7
0
//--------------------------------------------------------------
void testApp::draw(){
    
    
    ofSetBackgroundAuto(false);
   

    // these are your points that you'll either be moving between or moving from a to b
    ofPoint from, to, circleCenter, from2, to2, circleCenter2;
    
    float t = ofGetElapsedTimef() - ((int)ofGetElapsedTimef()); //creates movement
    //t = sqrt(1 - powf(1 - t, 2)); // creates easing
    
    float a = ofGetHeight()/2 *ofGetElapsedTimef(); //amplitude of the wave!
    
    from.x = ofGetElapsedTimef()* 20; // moves your x along the screen to the right
    from.y = ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 1) * a; // mapping the sin of the wave to between 0 and 1 because otherwise you'd go offscreen
    
    to.set(ofGetWidth(), ofGetHeight()); // where you're heading
    
    circleCenter = pointOnLine(t, from, to); // the circle center of the circles moving down the lines // calls the function above //interpolation
    ofSetColor(0, 0, 200);
    ofCircle(circleCenter, 5); // moves your circle center
    //ofNoFill();
    ofSetColor(255);
    ofLine(from, to);
    
    from2.x = 100 * ofGetElapsedTimef();
    from2.y = 100 * ofGetElapsedTimef();
    to2.x = ofGetWidth();
    to2.y = ofGetHeight(); 
    
    
    //circleCenter2 = drawTwoPointsOnTwoLine(from, to, from2, to2, t);
    circleCenter2 = pointOnLine(t, from2, to2);
    ofSetColor(255, 0, 255);
    ofCircle(circleCenter2, 6);
    ofSetColor(255);
    ofLine(from2, to2);
    
    
    

    if (flip == false){
        drawSine(2);
    }
    
}
示例#8
0
void TestSnapStrategy::testSquareDistanceToLine()
{
    BoundingBoxSnapStrategy toTestOne;

    const QPointF lineA(4,1);
    const QPointF lineB(6,3);
    const QPointF point(5,8);
    QPointF pointOnLine(0,0);

    qreal result = toTestOne.squareDistanceToLine(lineA, lineB, point, pointOnLine);
    //Should be HUGE_VAL because scalar > diffLength
    QVERIFY(result == HUGE_VAL);

    BoundingBoxSnapStrategy toTestTwo;
    QPointF lineA2(4,4);
    QPointF lineB2(4,4);
    QPointF point2(5,8);
    QPointF pointOnLine2(0,0);

    qreal result2 = toTestTwo.squareDistanceToLine(lineA2, lineB2, point2, pointOnLine2);
    //Should be HUGE_VAL because lineA2 == lineB2
    QVERIFY(result2 == HUGE_VAL);

    BoundingBoxSnapStrategy toTestThree;
    QPointF lineA3(6,4);
    QPointF lineB3(8,6);
    QPointF point3(2,2);
    QPointF pointOnLine3(0,0);

    qreal result3 = toTestThree.squareDistanceToLine(lineA3, lineB3, point3, pointOnLine3);
    //Should be HUGE_VAL because scalar < 0.0
    QVERIFY(result3 == HUGE_VAL);

    BoundingBoxSnapStrategy toTestFour;
    QPointF lineA4(2,2);
    QPointF lineB4(8,6);
    QPointF point4(3,4);
    QPointF pointOnLine4(0,0);

    QPointF diff(6,4);
    //diff = lineB3 - point3 = 6,4
    //diffLength = sqrt(52)
    //scalar = (1*(6/sqrt(52)) + 2*(4/sqrt(52)));

    //pointOnLine = lineA + scalar / diffLength * diff;  lineA + ((1*(6/sqrt(52)) + 2*(4/sqrt(52))) / sqrt(52)) * 6,4;
    QPointF distToPointOnLine = (lineA4 + ((1*(6/sqrt(52.0)) + 2*(4/sqrt(52.0))) / sqrt(52.0)) * diff)-point4;
    qreal toCompWithFour = distToPointOnLine.x()*distToPointOnLine.x()+distToPointOnLine.y()*distToPointOnLine.y();

    qreal result4 = toTestFour.squareDistanceToLine(lineA4, lineB4, point4, pointOnLine4);
    //Normal case with example data
    QVERIFY(qFuzzyCompare(result4, toCompWithFour));

}
//--------------------------------------------------------------
void testApp::draw(){
    
    //make from and to points to pass the circle back and fourth
    ofPoint from1, to1, from2, to2;
    
    //setting bounds of drawing & halfway points
    ofPoint upLeftCorner, upRightCorner, lowerLeftCorner, lowerRightCorner, half2, half3;
    upLeftCorner.set(0, 0);
    upRightCorner.set(ofGetWidth(), 0);
    lowerLeftCorner.set(0, ofGetHeight());
    lowerRightCorner.set(ofGetWidth(), ofGetHeight());
    half2.set(ofGetWidth()/2, ofGetHeight());
    half3.set(ofGetWidth(), ofGetHeight()/2);
    
    float t = ofMap(cos(ofGetElapsedTimef()), -1, 1, 0, 1);
    
    //start center, move down vertically
    from1 = pointOnLine(half2, lowerRightCorner/2, t);
    //ofCircle(from1, 10);
    
    //start lower right corner; move horizontally to the lower left corner
    to1 = pointOnLine(half3, lowerRightCorner/2, t);
    //ofCircle(to1, 10);
    
    //start at center, move up vertically
    from2 = pointOnLine(upRightCorner/2, lowerRightCorner/2, t);
    //ofCircle(from2, 10);
    
    
    to2 = pointOnLine(lowerLeftCorner/2, lowerRightCorner/2, t);
    //ofCircle(to2, 10);
    
    //move points along the path of a diamond
    drawTwoPointsOnTwoLines(half2, to2, from2, to2, t);
    drawTwoPointsOnTwoLines(half2, to1, from1, to2, t);
    drawTwoPointsOnTwoLines(upRightCorner/2, to2, from2, to1, t);
    drawTwoPointsOnTwoLines(upRightCorner/2, to1, from1, to1, t);
}
示例#10
0
void buildConnectorRouteCheckpointCache(Router *router)
{
    for (ConnRefList::const_iterator curr = router->connRefs.begin(); 
            curr != router->connRefs.end(); ++curr) 
    {
        ConnRef *conn = *curr;
        if (conn->routingType() != ConnType_Orthogonal)
        {
            continue;
        }

        PolyLine& displayRoute = conn->displayRoute();
        std::vector<Point> checkpoints = conn->routingCheckpoints();
       
        // Initialise checkpoint vector and set to false.  There will be
        // one entry for each *segment* in the path, and the value indicates
        // whether the segment is affected by a checkpoint.
        displayRoute.segmentHasCheckpoint = 
                std::vector<bool>(displayRoute.size() - 1, false);
        size_t nCheckpoints = displayRoute.segmentHasCheckpoint.size();

        for (size_t cpi = 0; cpi < checkpoints.size(); ++cpi)
        {
            for (size_t ind = 0; ind < displayRoute.size(); ++ind)
            {
                if (displayRoute.ps[ind].equals(checkpoints[cpi]))
                {
                    // The checkpoint is at a bendpoint, so mark the edge
                    // before and after and being affected by checkpoints.
                    if (ind > 0)
                    {
                        displayRoute.segmentHasCheckpoint[ind - 1] = true;
                    }

                    if (ind < nCheckpoints)
                    {
                        displayRoute.segmentHasCheckpoint[ind] = true;
                    }
                }
                else if ((ind > 0) && pointOnLine(displayRoute.ps[ind - 1], 
                         displayRoute.ps[ind], checkpoints[cpi]) )
                {
                    // If the checkpoint is on a segment, only that segment is
                    // affected.
                    displayRoute.segmentHasCheckpoint[ind - 1] = true;
                }
            }
        }
    }
}
示例#11
0
void buildConnectorRouteCheckpointCache(Router *router)
{
    for (ConnRefList::const_iterator curr = router->connRefs.begin();
            curr != router->connRefs.end(); ++curr)
    {
        ConnRef *conn = *curr;
        if (conn->routingType() != ConnType_Orthogonal)
        {
            continue;
        }

        PolyLine& displayRoute = conn->displayRoute();
        std::vector<Checkpoint> checkpoints = conn->routingCheckpoints();

        // Initialise checkpoint vector and set to false.  There will be
        // one entry for each *segment* in the path, and the value indicates
        // whether the segment is affected by a checkpoint.
        displayRoute.checkpointsOnRoute =
            std::vector<std::pair<size_t, Point> >();

        for (size_t ind = 0; ind < displayRoute.size(); ++ind)
        {
            if (ind > 0)
            {
                for (size_t cpi = 0; cpi < checkpoints.size(); ++cpi)
                {
                    if (pointOnLine(displayRoute.ps[ind - 1],
                                    displayRoute.ps[ind], checkpoints[cpi].point) )
                    {
                        // The checkpoint is on a segment.
                        displayRoute.checkpointsOnRoute.push_back(
                            std::make_pair((ind * 2) - 1,
                                           checkpoints[cpi].point));
                    }
                }
            }

            for (size_t cpi = 0; cpi < checkpoints.size(); ++cpi)
            {
                if (displayRoute.ps[ind].equals(checkpoints[cpi].point))
                {
                    // The checkpoint is at a bendpoint.
                    displayRoute.checkpointsOnRoute.push_back(
                        std::make_pair(ind * 2, checkpoints[cpi].point));
                }
            }
        }
    }
}
//--------------------------------------------------------------
void testApp::draw(){
    float mouseX01 = ofClamp((float)mouseX / ofGetWidth(), 0, 1);
    cout << mouseX01 << endl;
    
    int minimumGrey = 128;
    int maximumGrey = 220;
    
    float g = (maximumGrey - minimumGrey) * mouseX01 + minimumGrey;
    
    // ofBackground(g, g, g);

    // float circleX = xCoordinateOnLine(mouseX01, 50, 350);
    // float circleY = yCoordinateOnLine(mouseX01, 100, 300);
    
    // ofCircle(circleX, circleY, 2);
    
    ofPoint circleCenter = pointOnLine(mouseX01, ofPoint(50, 100), ofPoint(350, 300));
    ofCircle(circleCenter, 2);
}
示例#13
0
// This method moves the junction at the given node along any shared paths
// (so long as this action would not create any additional shared paths),
// while also removing and freeing merged edges and nodes in the process.
// It returns the new node where the junction is now located.
//
HyperEdgeTreeNode *HyperEdgeTreeNode::moveJunctionAlongCommonEdge(
        HyperEdgeTreeNode *self)
{
    COLA_ASSERT(self->junction);

    HyperEdgeTreeNode *newSelf = NULL;
    std::vector<HyperEdgeTreeEdge *> commonEdges;
    std::vector<HyperEdgeTreeEdge *> otherEdges;

    // Consider each edge from this node in turn.
    for (std::list<HyperEdgeTreeEdge *>::iterator curr = self->edges.begin();
            curr != self->edges.end(); ++curr)
    {
        HyperEdgeTreeEdge *currEdge = *curr;
        HyperEdgeTreeNode *currNode = currEdge->followFrom(self);
        commonEdges.clear();
        otherEdges.clear();

        if (currNode->junction)
        {
            // Don't shift junctions onto other junctions.
            continue;
        }

        // The current edge is a common edge we are looking to shift along.
        commonEdges.push_back(currEdge);

        // Consider each of the other edges.
        for (std::list<HyperEdgeTreeEdge *>::iterator curr2 = 
                self->edges.begin(); curr2 != self->edges.end(); ++curr2)
        {
            if (curr == curr2)
            {
                // Except the current (curr) one.
                continue;
            }
            
            HyperEdgeTreeEdge *otherEdge = *curr2;
            HyperEdgeTreeNode *otherNode = otherEdge->followFrom(self);
            if (otherNode->point == currNode->point)
            {
                // A common edge can be at the same point, but can't have
                // a junction at it.
                if (otherNode->junction)
                {
                    otherEdges.push_back(otherEdge);
                }
                else
                {
                    commonEdges.push_back(otherEdge);
                }
            }
            else if (pointOnLine(self->point, otherNode->point, 
                    currNode->point))
            {
                // A common edge can be a (longer) collinear line, but we
                // need to split the longer line at the other end of curr.
                otherEdge->splitFromNodeAtPoint(self, currNode->point);
                commonEdges.push_back(otherEdge);
            }
            else
            {
                // If the edge goes in another direction it is not common.
                otherEdges.push_back(otherEdge);
            }
        }

        if ((commonEdges.size() > 1) && (otherEdges.size() <= 1))
        {
            // One of the common nodes becomes the target node, we move 
            // all connections from the other common nodes to this node.
            // We also move the junction there and remove it from the 
            // current node.
            HyperEdgeTreeNode *targetNode = commonEdges[0]->followFrom(self);
            for (size_t i = 1; i < commonEdges.size(); ++i)
            {
                HyperEdgeTreeNode *thisNode = commonEdges[i]->followFrom(self);
                commonEdges[i]->disconnectEdge();
                targetNode->spliceEdgesFrom(thisNode);
                delete thisNode;
                delete commonEdges[i];
            }
            targetNode->junction = self->junction;
            self->junction = NULL;

            if (otherEdges.empty())
            {
                // Nothing else connected to this node, so remove the node
                // and the edge to the target node.
                commonEdges[0]->disconnectEdge();

                delete commonEdges[0];
                delete self;
            }
            else
            {
                // We need to mark commonEdges[0] as being from the connector
                // of the otherEdges[0].
                commonEdges[0]->conn = otherEdges[0]->conn;
            }
            newSelf = targetNode;

            break;
        }
    }

    return newSelf;
}
示例#14
0
//--------------------------------------------------------------
void testApp::draw(){
    
    
    
    ofSetColor(255, randomColor, 9, 15);


    fish.draw(circleCenter);

    ofSetColor(0, ofRandom(34, 200), 255, 5);

    ofFill();
    ofDrawBitmapString(ofToString(circleCenter.distance(destination)), 10, 10);
    ofCircle(destination, 5);
    

  
    
    from2.set(ofGetWidth()/2, ofGetHeight());//(0, y)
    to2.set(ofGetWidth()/2, ofGetHeight());
    from1.set(0, ofGetHeight());
    to1.set(0,0);
    from.set(0, ofGetHeight()/2);
    //to.set(ofGetWidth()-100, ofGetHeight()/2);
    
    from = pointOnLine(ofMap(sin(ofGetElapsedTimef()*2), -1, 1, 0, 1), from1, to1, from2, to2);
    to.set(ofGetWidth(), ofGetHeight()/2);    
    //float t = ofMap(sin(ofGetElapsedTimef()));
    
    //circleCenter = pointOnLine(ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 1), from, to, from2, from1);
    circleCenter2 = pointOnLine(ofMap(sin(ofGetElapsedTimef()-.1), -1, 1, 0, 1), from, to, from1, from2);
    circleCenter3 = pointOnLine(ofMap(sin(ofGetElapsedTimef()-.2), -1, 1, 0, 1), from, to, from2, from1);
    
    circleCenter4 = pointOnLine(ofMap(sin(ofGetElapsedTimef()-.3), -1, 1, 0, 1), from, to, from2, from1);
    circleCenter5 = pointOnLine(ofMap(sin(ofGetElapsedTimef()-.5), -1, 1, 0, 1), from, to, from2, from1);
//    
//    ofCircle(circleCenter, 10);
//    ofCircle(circleCenter2, 10);

    
    //ofCircle(circleCenter, 40);
//    ofSetColor(0, 34, 255, 50);
    //ofLine(circleCenter2, circleCenter3);
//    ofCircle(circleCenter2, 30);
//    ofSetColor(0, 56, 255, 50);
//    ofCircle(circleCenter3, 20);
//    ofSetColor(0, 32, 255, 50);
//    ofCircle(circleCenter4, 10);
    
    
//    ofCircle(startPoint.x,startPoint.y,6);
    ofCircle(cP1.x,cP1.y,3);
    ofCircle(cP2.x,cP2.y,3);
//    ofCircle(endPoint.x,endPoint.y,6);
    
    
    
    glBegin(GL_LINE_STRIP);
    
    for( int i = 0; i < 101; i++)
    {
//        ofSetColor(0, ofRandom(34, 200), 255, 5);
//        ofPoint pt = getBezier4Pt( startPoint,cP1, cP2,endPoint, i / 100.f );
//        glVertex3f(pt.x,pt.y,0);
//        glVertex3f(pt.x,pt.y,0);
        
    }
    
    glEnd();
    
    
    ofCircle(getBezier4Pt( startPoint,cP1, cP2,endPoint, ofMap(sin(ofGetElapsedTimef()-.1), -1, 1, 0, 1)), 10);
        
}