Beispiel #1
0
        private myPolygon GetUnionWithIntersectedPolygons(myPolygon polygon, Graphics graphics, Pen pen, bool paint_or_not)
        {
            myPolygon copy_of_this_with_intersected_points = this.GetIntersectionWith(polygon);
            myPolygon copy_of_second_with_intersected_points = polygon.GetIntersectionWith(this);

            Boolean[] points_of_this_which_are_in_result = new Boolean[copy_of_this_with_intersected_points.vertexes.Count];
            for (int i = 0; i < copy_of_this_with_intersected_points.vertexes.Count; i++ )
                if(copy_of_second_with_intersected_points.ContainInAreaONLY(copy_of_this_with_intersected_points.vertexes[i]))
                    points_of_this_which_are_in_result[i] = true;

            int count_vertexes_in_second = copy_of_second_with_intersected_points.vertexes.Count;
            for (int i = 1; i < count_vertexes_in_second; i++)
                copy_of_second_with_intersected_points.vertexes.Add(copy_of_second_with_intersected_points.vertexes[i]);
            copy_of_second_with_intersected_points.vertexes.Add(copy_of_second_with_intersected_points.vertexes[0]);

            //основной обход
            myPolygon result = copy_of_this_with_intersected_points.Round_ver(copy_of_second_with_intersected_points, 0, graphics, pen);
            for (int i = 0; i < copy_of_this_with_intersected_points.vertexes.Count; i++)
                for (int j = 0; j < result.vertexes.Count; j++)
                    if (copy_of_this_with_intersected_points.vertexes[i].Equals(result.vertexes[j]))
                        points_of_this_which_are_in_result[i] = true;

            pen = new Pen(Color.BlueViolet, 4);
            //выкалываем дыры
            List<myPolygon> holes = new List<myPolygon>();
            Boolean i_can_go_away = false;
            while (!i_can_go_away)
            {
                for (int i = 0; i < copy_of_this_with_intersected_points.vertexes.Count; i++)
                    if (points_of_this_which_are_in_result[i] == false)
                    {
                        myPolygon Hole = copy_of_this_with_intersected_points.Round_ver(copy_of_second_with_intersected_points, i, graphics, pen);
                        holes.Add(new myPolygon(Hole));
                        for (int k = 0; k < copy_of_this_with_intersected_points.vertexes.Count; k++)
                            for (int j = 0; j < Hole.vertexes.Count; j++)
                                if (copy_of_this_with_intersected_points.vertexes[k].Equals(Hole.vertexes[j]))
                                    points_of_this_which_are_in_result[k] = true;
                        i_can_go_away = false;
                    }
                    else
                        i_can_go_away = true;
            }

            if (paint_or_not)
                result.Fill(graphics, Color.Brown, Color.White, holes);
            return result;
        }