Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        //float sweepLine = 5.0f;

        Vector2 intersection;

        if (GetValidIntersection(out intersection, leftArc, leftEdge))
        {
            // Set bounds on arc and edge
            leftEdge.SetEndpoint(intersection);
            //leftArc.SetNext(leftEdge);
            leftArc.Draw(Color.green);
            leftEdge.Draw(Color.cyan);
        }
        if (GetValidIntersection(out intersection, newArc, rightEdge))
        {
            // Set bounds on arc and edge
            rightEdge.SetEndpoint(intersection);
            //leftArc.SetNext(leftEdge);
            newArc.Draw(Color.yellow);
            rightEdge.Draw(Color.blue);
            rightArc.Draw(Color.magenta);
        }



        //newArc.Draw(sweepLine);
    }
Esempio n. 2
0
    public List <BeachLineEdge> Squeeze(out BeachLineEdge newEdge)
    {
        // These are the output edges
        BeachLineEdge leftEdge  = (BeachLineEdge)Prev;
        BeachLineEdge rightEdge = (BeachLineEdge)Next;
        BeachLineArc  leftArc   = (BeachLineArc)leftEdge.Prev;
        BeachLineArc  rightArc  = (BeachLineArc)rightEdge.Next;

        // Create new edge
        // To create it, we need the intersection point of the two output edges plus the
        // focuses of the two arcs.
        Vector2 intersection;

        leftEdge.CheckIntersection(rightEdge, out intersection);
        Vector2 focus1           = leftArc.Focus;
        Vector2 focus2           = rightArc.Focus;
        Vector2 perpendicular    = focus2 - focus1;
        Vector2 newEdgeDirection = new Vector2(perpendicular.y, -perpendicular.x);

        if (Vector2.Dot(leftEdge.Direction.normalized + rightEdge.Direction.normalized, -newEdgeDirection) > 0)
        //if (newEdgeDirection.y < 0)
        {
            newEdgeDirection = -newEdgeDirection;
        }

        newEdge = new BeachLineEdge(intersection, newEdgeDirection.normalized);


        BeachLineEdge edgeToReplace = leftEdge == Parent ? rightEdge : leftEdge;

        //newEdge.SetLeftArc(LeftArc);
        //newEdge.SetRightArc(RightArc);
        // Replace other edge with new edge
        edgeToReplace.ReplaceWithSingleNode(newEdge);

        // Replace parent with sibling

        BeachLineElement sibling = Sibling;

        sibling.SetParent(null);
        bool iAmLeftChild = this == Parent.LeftChild;

        if (iAmLeftChild)
        {
            Parent.SetRightChild(null);
        }
        else
        {
            Parent.SetLeftChild(null);
        }

        BeachLineElement parentsParent     = Parent.Parent;
        bool             parentIsLeftChild = Parent == parentsParent.LeftChild;

        if (parentIsLeftChild)
        {
            parentsParent.SetLeftChild(sibling);
        }
        else
        {
            parentsParent.SetRightChild(sibling);
        }
        sibling.SetParent(parentsParent);

        //Parent.ReplaceWith(Sibling);

        //Parent.SetLeftChild(null);
        //Parent.SetRightChild(null);

        // Set next/prev for altered nodes
        leftArc.SetNext(newEdge);
        newEdge.SetPrev(leftArc);
        newEdge.SetNext(rightArc);
        rightArc.SetPrev(newEdge);

        // Remove this node from tree
        SetParent(null);
        SetLeftChild(null);
        SetRightChild(null);
        SetNext(null);
        SetPrev(null);
        leftEdge.SetParent(null);
        leftEdge.SetLeftChild(null);
        leftEdge.SetRightChild(null);
        leftEdge.SetNext(null);
        leftEdge.SetPrev(null);
        rightEdge.SetParent(null);
        rightEdge.SetLeftChild(null);
        rightEdge.SetRightChild(null);
        rightEdge.SetNext(null);
        rightEdge.SetPrev(null);

        leftEdge.SetEndpoint(intersection);
        rightEdge.SetEndpoint(intersection);

        List <BeachLineEdge> outputList = new List <BeachLineEdge>
        {
            leftEdge,
            rightEdge
        };

        return(outputList);
    }