Beispiel #1
0
        private int HasVertexesInside(myPolygon polygon)
        {
            //выбираем полигон с которого начать обход
            //"0" - текущий
            //"1" - передаваемый
            //"2" - они совпадают
            //"3" - они не пересекаются

            int polygon_vertexes_count_which_is_not_in_first = 0;
            for (int i = 0; i < polygon.vertexes.Count; i++)
                if (!this.ContainInArea(polygon.vertexes[i]))
                    polygon_vertexes_count_which_is_not_in_first++;

            int this_vertexes_count_which_is_not_in_second = 0;
            for (int i = 0; i < this.vertexes.Count; i++)
                if (!polygon.ContainInArea(this.vertexes[i]))
                    this_vertexes_count_which_is_not_in_second++;

            if (polygon_vertexes_count_which_is_not_in_first == polygon.vertexes.Count && this_vertexes_count_which_is_not_in_second == this.vertexes.Count)
            {
                Boolean there_is_no_intersection = true;
                for (int i = 1; i < this.vertexes.Count; i++)
                    for (int j = 1; j < polygon.vertexes.Count; j++)
                    {
                        if (new mySection(this.vertexes[i - 1], this.vertexes[i]).Intersect(new mySection(polygon.vertexes[j - 1], polygon.vertexes[j])) != null)
                        {
                            there_is_no_intersection = false;
                            break;
                        }
                    }

                        if (there_is_no_intersection)
                            return 3;
            }

            //проверяем, является ли хотя бы одна точка вершина первого вне второго
            int pos_of_vertex_in_first_which_is_not_in_second = -1;

            for (int i = 0; i < this.vertexes.Count; i++)
                if (!polygon.ContainInArea(this.vertexes[i]))
                {
                    pos_of_vertex_in_first_which_is_not_in_second = i;
                    break;
                }

            //если да - возвращаем 0
            if (pos_of_vertex_in_first_which_is_not_in_second != -1)
            {
                this.vertexes.RemoveAt(this.vertexes.Count - 1);
                for (int i = 0; i < pos_of_vertex_in_first_which_is_not_in_second; i++)
                {
                    this.vertexes.Add(this.vertexes[0]);
                    this.vertexes.RemoveAt(0);
                }
                this.vertexes.Add(this.vertexes[0]);
                return 0;
            }

            //если нет - проворачиваем всё то же самое со вторым полигоном
            int pos_of_vertex_in_second_which_is_not_in_first = -1;
            for (int i = 0; i < polygon.vertexes.Count; i++)
                if (!this.ContainInArea(polygon.vertexes[i]))
                {
                    pos_of_vertex_in_second_which_is_not_in_first = i;
                    break;
                }

            //если да - возвращаем 1
            if (pos_of_vertex_in_second_which_is_not_in_first != -1)
            {
                polygon.vertexes.RemoveAt(polygon.vertexes.Count - 1);
                for (int i = 0; i < pos_of_vertex_in_second_which_is_not_in_first; i++)
                {
                    polygon.vertexes.Add(polygon.vertexes[0]);
                    polygon.vertexes.RemoveAt(0);
                }
                polygon.vertexes.Add(polygon.vertexes[0]);
                return 1;
            }

            //смотрим, совпадает ли количество вершин "вне" с количеством вершин вообще
            //если да - они не имеют пересечения
            return 2;
        }