Example #1
0
            public Polygon CreatePolygon()
            {
                Polygon result = new Polygon();

                LinkedListNode <PointChain> current = closedPolygons.First;

                while (current != null)
                {
                    SimpleClosedPath path = new SimpleClosedPath(result);

                    LinkedListNode <Vector2> innerCurrent = current.Value.First;

                    while (innerCurrent != null)
                    {
                        path.Add(innerCurrent.Value);

                        innerCurrent = innerCurrent.Next;
                    }

                    result.Add(path);

                    current = current.Next;
                }

                return(result);
            }
Example #2
0
    void Start()
    {
        Triangulator tri = new Triangulator();

        // Vector2 p0 = new Vector2( 0.0f, 0.0f);
        // Vector2 p1 = new Vector2( 0.0f, 1.0f);
        // Vector2 p2 = new Vector2(-0.5f, 0.0f);

        // Debug.Log("Orientation of [" + p0 + p1 + "] [" + p2 + "] : " + Orientation(p0, p1, p2));

        // p0 = new Vector2( 0.0f,  0.0f);
        // p1 = new Vector2( 0.0f,  1.0f);
        // p2 = new Vector2(+4.5f, -1.0f);

        // Debug.Log("Orientation of [" + p0 + p1 + "] [" + p2 + "] : " + Orientation(p0, p1, p2));

        MartinezClipping clippingAlgo = new MartinezClipping();

        Polygon subject = new Polygon();
        Polygon clipper = new Polygon();

        SimpleClosedPath subjectContour = new SimpleClosedPath(subject);
        SimpleClosedPath clipperContour = new SimpleClosedPath(clipper);

        foreach (Vector2 vertex in subjectVerts)
        {
            subjectContour.Add(vertex);
        }
        foreach (Vector2 vertex in clipperVerts)
        {
            clipperContour.Add(vertex);
        }

        subject.Add(subjectContour);
        clipper.Add(clipperContour);

        subject.ComputeHoles();
        clipper.ComputeHoles();

        clippingAlgo.subject = subject;
        clippingAlgo.clipper = clipper;

        Polygon result = clippingAlgo.Compute(operationType);

        result.ComputeHoles();

        //result = tri.Simplify(result);

        polyRenderer.AddPolygon(subject, Color.red);
        polyRenderer.AddPolygon(clipper, Color.blue);
        polyRenderer.AddPolygon(result, Color.green);
        polyRenderer.AddEdges(clippingAlgo.DebugLines);
    }