Example #1
0
 public Line(int coordintae)
 {
     Coord  = coordintae;
     Points = new RedBlackTree <int>();
 }
Example #2
0
        private static void Initialize(Coordinate[] coords, out RedBlackTree <Line> vs, out RedBlackTree <Line> hors)
        {
            vs   = new RedBlackTree <Line>();
            hors = new RedBlackTree <Line>();

            Array.Sort(coords, (a, b) => a.X - b.X);
            var streak = 0;
            var x      = int.MinValue;

            var queue = new Queue <int>();

            for (int i = 0; i < coords.Length; i++)
            {
                if (x == coords[i].X)
                {
                    streak++;
                    queue.Enqueue(coords[i].Y);
                }
                else
                {
                    // 同じX座標に頂点が2個以上あるとき
                    if (streak >= 2)
                    {
                        var line = new Line(x);
                        while (queue.Count > 0)
                        {
                            // Y座標を追加
                            line.Points.Add(queue.Dequeue());
                        }
                        vs.Add(line);
                    }
                    else
                    {
                        queue.Clear();
                    }

                    x = coords[i].X;
                    queue.Enqueue(coords[i].Y);
                    streak = 1;
                }
            }

            if (streak >= 2)
            {
                var line = new Line(x);
                while (queue.Count > 0)
                {
                    // Y座標を追加
                    line.Points.Add(queue.Dequeue());
                }
                vs.Add(line);
            }

            queue.Clear();
            streak = 0;
            var y = int.MinValue;

            Array.Sort(coords, (a, b) => a.Y - b.Y);

            for (int i = 0; i < coords.Length; i++)
            {
                if (y == coords[i].Y)
                {
                    streak++;
                    queue.Enqueue(coords[i].X);
                }
                else
                {
                    // 同じX座標に頂点が2個以上あるとき
                    if (streak >= 2)
                    {
                        var line = new Line(y);
                        while (queue.Count > 0)
                        {
                            // X座標を追加
                            line.Points.Add(queue.Dequeue());
                        }
                        hors.Add(line);
                    }
                    else
                    {
                        queue.Clear();
                    }

                    y = coords[i].Y;
                    queue.Enqueue(coords[i].X);
                    streak = 1;
                }
            }

            if (streak >= 2)
            {
                var line = new Line(y);
                while (queue.Count > 0)
                {
                    // X座標を追加
                    line.Points.Add(queue.Dequeue());
                }
                hors.Add(line);
            }
        }