Exemplo n.º 1
0
        private static List<m.polygon> all(IList<m.polygon> a, IList<m.polygon> b, Func<bool, bool, bool> predicate)
        {
            var aPolygons = new Vector2[a.Count][];
            for (int i = 0; i < a.Count; i++)
                aPolygons[i] = a[i].points.Select(x => (Vector2) x).ToArray();

            var bPolygons = new Vector2[b.Count][];
            for (int i = 0; i < b.Count; i++)
                bPolygons[i] = b[i].points.Select(x => (Vector2) x).ToArray();

            var graph = new IntersectionGraph();
            foreach (var points in aPolygons)
                graph.Goto(true, points);
            foreach (var points in bPolygons)
                graph.Goto(true, points);
            var polygons = graph.CalculatePolygons(true);

            var result = new List<m.polygon>();
            for (int i = 0; i < polygons.Count; i++)
            {
                var points = polygons[i].points;
                var point = m.triangulation.getInsidePoint(points);
                var isA = aPolygons.Any(x => m.contain.nonzeroRule(x, point));
                var isB = bPolygons.Any(x => m.contain.nonzeroRule(x, point));
                if (predicate(isA, isB))
                    result.Add(polygons[i]);
            }
            return result;
        }
Exemplo n.º 2
0
        private static List<m.polygon> all(IList<m.polygon> a, IList<m.polygon> b, Func<bool, bool, bool> predicate, out List<m.line> outLines)
        {
            var aPolygons = new Vector2[a.Count][];
            for (int i = 0; i < a.Count; i++)
                aPolygons[i] = a[i].points.Select(x => (Vector2)x).ToArray();

            var bPolygons = new Vector2[b.Count][];
            for (int i = 0; i < b.Count; i++)
                bPolygons[i] = b[i].points.Select(x => (Vector2)x).ToArray();

            var graph = new IntersectionGraph();
            foreach (var points in aPolygons)
                graph.Goto(true, points);
            foreach (var points in bPolygons)
                graph.Goto(true, points);
            var polygons = graph.CalculatePolygons(true);

            var result = new List<m.polygon>();
            outLines = new List<line>();
            for (int i = 0; i < polygons.Count; i++)
            {
                var polygon = polygons[i];
                var dirs = ((polygon<List<IntersectionGraph.EdgeDirection>>)polygon).tag;
                var points = polygon.points;
                var point = m.triangulation.getInsidePoint(points);
                var isA = aPolygons.Any(x => m.contain.nonzeroRule(x, point));
                var isB = bPolygons.Any(x => m.contain.nonzeroRule(x, point));
                if (predicate(isA, isB))
                {
                    result.Add(polygons[i]);
                    for (int j = 0; j < dirs.Count; j++)
                        dirs[j].edge.conditionTouchCount++;
                }
            }
            for (int i = 0; i < polygons.Count; i++)
            {
                var polygon = polygons[i];
                var dirs = ((polygon<List<IntersectionGraph.EdgeDirection>>)polygon).tag;
                for (int j = 0; j < dirs.Count; j++)
                {
                    var dir = dirs[j];
                    if (dir.edge.conditionTouchCount == 1)
                        outLines.Add(new line(dir.a.value, dir.b.value));
                }
            }

            return result;
        }