This project is read-only.

Fill region intersections

Mar 4, 2015 at 4:08 PM
First of wall, thanks for great library!

I have two questions related to this case:

Result Polygon is constructed using the following code:
            var polygon = new Polygon();

            // tile borders
            polygon.Add(new Vertex(0.0, 0.0, 1));
            polygon.Add(new Vertex(0, 100, 1));
            polygon.Add(new Vertex(100, 100, 1));
            polygon.Add(new Vertex(100, 0, 1));

            polygon.Add(new Edge(0, 1));
            polygon.Add(new Edge(1, 2));
            polygon.Add(new Edge(2, 3));
            polygon.Add(new Edge(3, 0));

            polygon.AddContour(new List<Vertex>()
                new Vertex(30, -20),
                new Vertex(50, -20),
                new Vertex(50, 70),
                new Vertex(30, 70)
            }, 2);

            polygon.AddContour(new List<Vertex>()
                new Vertex(15, 20),
                new Vertex(17, 31),
                new Vertex(45, 30),
                new Vertex(55, 15)
            }, 3);

            polygon.Regions.Add(new RegionPointer(1, 1, 1));
            polygon.Regions.Add(new RegionPointer(40, 20, 2));

            return polygon;
Here I have three regions. I want to do with them the following:
  1. Restrict resulting mesh to be in first (big square) region. So, this bottom square should be removed from result.
  2. Process these regions separately (e.g. fill with different color, last one wins). I can do it with RegionIterator, but if they intersects, only one part of region is processed (for example, yellow area for the query):
            var regionIterator = new RegionIterator(mesh);
            var tree = new QuadTree(mesh);
            var start = tree.Query(<coords of point inside yellow area>) as Triangle;
            regionIterator.Process(start, triangle =>
                // fill triangles with color for this region
Is it possible to tweak somehow source code to achieve that?
Mar 4, 2015 at 8:36 PM
Sorry, but this won't work. The region iterator will stop at any subsegment it finds.

You should probably have a look at polygon clipping. There's a nice library called Clipper:
Mar 4, 2015 at 9:16 PM
Know about it. So will try to clip polygons using clipper before triangulation.

Thanks for your help!