public List <BoundIntersection> intersectionsLeft;  // Пересечения с левой границей диаграммы

    public VoronoiDiagram(Vector2[] points, Vector2 point1, Vector2 point2)
    {
        // 1.Сортировка массива вершин
        IComparer <Vector2> comparer = new Vector2Comparer();

        Array.Sort(points, comparer);

        // 2.Образование элементарных подмножеств
        cells      = new List <VoronoiCell>();
        edges      = new List <VoronoiEdge>();
        shortEdges = new List <VoronoiEdge>();

        intersectionsUp    = new List <BoundIntersection>();
        intersectionsRight = new List <BoundIntersection>();
        intersectionsDown  = new List <BoundIntersection>();
        intersectionsLeft  = new List <BoundIntersection>();

        if (points.Length < 1)
        {
            return;
        }

        for (int i = 0; i < points.Length; ++i)
        {
            cells.Add(new VoronoiCell(points[i]));
        }

        // 3. Установка границ
        SetBounds(point1, point2);

        // 4. Построение диаграммы методом "Разделяй и властвуй"
        int c   = cells.Count / 2;
        int top = -1;

        Voronoi_DivideAndConquer_Recursive(0, c, cells.Count, ref top, true);
        // 5. Вписывание диаграммы в установленные границы
        FitInBounds();
        Debug.Log("Diagram for " + cells.Count + " points completed.");
    }
        public static WallData[][] FindRooms(Walls walls)
        {
            var pointWallsMap = new PointWallsMap();
            var uniqueWalls   = new HashSet <WallData> ();

            foreach (var point in walls.Points)
            {
                foreach (var wall in walls.GetPointWalls(point))
                {
                    uniqueWalls.Add(wall);
                }
            }

            var wallCounterMap = new Dictionary <WallData, WallUseCounter> ();

            foreach (var wall in uniqueWalls)
            {
                wallCounterMap.Add(wall, new WallUseCounter(wall));
            }

            uniqueWalls.Clear();

            foreach (var point in walls.Points)
            {
                pointWallsMap.Add(
                    point,
                    walls
                    .GetPointWalls(point)
                    .ConvertAll(x => wallCounterMap[x])
                    .ToArray());
            }

            var rooms               = new List <WallData[]> ();
            var vector2Comparer     = new Vector2Comparer();
            var orderedWallCounters = wallCounterMap
                                      .Values
                                      .OrderBy(x => vector2Comparer.GetMin(x.Wall.Start, x.Wall.End), vector2Comparer)
                                      .ToArray();

            var i = 0;

            do
            {
                Assert.IsTrue(++i < 10);
                var startWall = orderedWallCounters
                                .FirstOrDefault(x => x.Counter == 0);

                if (startWall == null)
                {
                    break;
                }

                WallUseCounter[] path = null;
                var room = FindRoom(startWall, false, pointWallsMap, ref path);
                Assert.IsNotNull(room);
                rooms.Add(room);
            } while (true);

            /**
             * Remove 'superroom', ie room which includes all rooms in this group.
             * Such room include only 'shared' walls, ie walls with UseCount == 2.
             */
/*            if (rooms.Count > 1) {
 *              var sorterRooms = rooms
 *                  .OrderByDescending (x => x.Length)
 *                  .ToArray ();
 *              for (int j = 0; j < sorterRooms.Length; j++) {
 *                  if (rooms[j].All (x => wallCounterMap[x].Counter == 2)) {
 *                      rooms.RemoveAt (j);
 *                      break;
 *                  }
 *              }
 *          }*/

            return(rooms.ToArray());
        }