Пример #1
0
        public static Polygon Xor(Polygon first, Polygon second)
        {
            var firstPolygonRegions  = PolyBool.Segments(first);
            var secondPolygonRegions = PolyBool.Segments(second);
            var combinedSegments     = PolyBool.Combine(firstPolygonRegions, secondPolygonRegions);

            var xor = Select(combinedSegments.Combined, new[] { 0, 2, 1, 0,
                                                                2, 0, 0, 1,
                                                                1, 0, 0, 2,
                                                                0, 1, 2, 0 });

            return(new Polygon(PolyBool.SegmentChainer(xor), first.Inverted != second.Inverted));
        }
Пример #2
0
        public static Polygon DifferenceRev(Polygon first, Polygon second)
        {
            var firstPolygonRegions  = PolyBool.Segments(first);
            var secondPolygonRegions = PolyBool.Segments(second);
            var combinedSegments     = PolyBool.Combine(firstPolygonRegions, secondPolygonRegions);

            var difference = Select(combinedSegments.Combined, new[] { 0, 2, 1, 0,
                                                                       0, 0, 1, 1,
                                                                       0, 2, 0, 2,
                                                                       0, 0, 0, 0 });

            return(new Polygon(PolyBool.SegmentChainer(difference), !first.Inverted && second.Inverted));
        }
Пример #3
0
        public static Polygon Intersect(Polygon first, Polygon second)
        {
            var firstPolygonRegions  = PolyBool.Segments(first);
            var secondPolygonRegions = PolyBool.Segments(second);
            var combinedSegments     = PolyBool.Combine(firstPolygonRegions, secondPolygonRegions);

            var intersection = Select(combinedSegments.Combined, new[] { 0, 0, 0, 0,
                                                                         0, 2, 0, 2,
                                                                         0, 0, 1, 1,
                                                                         0, 2, 1, 0 });


            foreach (var s in intersection)
            {
                Console.WriteLine("{0},{1} -> {2},{3}", s.Start.X, s.Start.Y, s.End.X, s.End.Y);
            }
            return(new Polygon(PolyBool.SegmentChainer(intersection), first.Inverted && second.Inverted));
        }