public SingleThreadDrawer(int length, int width)
 {
     graph_size    = new SizeStruct(length, width);
     position_pool = new CachedPositonPool(Math.Max(length, width));
     max_x         = (int)(0.6 * length);
     max_y         = (int)(0.6 * length);
 }
Пример #2
0
        public void TestAlloc()
        {
            int TEST_TIMES         = 1000;
            int MIN_SIZE           = 32;
            int MAX_SIZE           = 512;
            CachedPositonPool pool = new CachedPositonPool(16);

            for (int i = 0; i < TEST_TIMES; i++)
            {
                int size = rnd.Next(MIN_SIZE, MAX_SIZE);
                for (int j = 0; j < size; j++)
                {
                    int            x         = rnd.Next(MIN_POSITION, MAX_POSITION);
                    int            y         = rnd.Next(MIN_POSITION, MAX_POSITION);
                    Position       sample_p  = new Position(x, y);
                    PositionStruct sample_ps = new PositionStruct(x, y);
                    Position       answer    = pool.AllocPosition(x, y);
                    Assert.IsTrue(sample_p.GetHashCode() == answer.GetHashCode());
                    Assert.IsTrue(sample_p.Equals(answer));
                    Assert.IsTrue(answer.Equals(sample_p));
                    Assert.IsTrue(sample_ps.GetHashCode() == answer.GetHashCode());
                    Assert.IsTrue(sample_ps.Equals(answer));
                    Assert.IsTrue(answer.Equals(sample_ps));
                }
                pool.FreeAllPosition();
            }
            pool.FreeAllPosition();
        }
Пример #3
0
        public void TestLargeAlloc()
        {
            int TEST_SIZE          = 1000000;
            int TEST_TIMES         = 10;
            CachedPositonPool pool = new CachedPositonPool();

            for (int i = 0; i < TEST_TIMES; i++)
            {
                int size = TEST_SIZE + (int)((2 * rnd.NextDouble() - 1) * (0.01 * TEST_SIZE));
                for (int j = 0; j < size; j++)
                {
                    int       x        = rnd.Next(MIN_POSITION, MAX_POSITION);
                    int       y        = rnd.Next(MIN_POSITION, MAX_POSITION);
                    IPosition position = pool.AllocPosition(x, y);
                    Assert.IsTrue(position.X == x);
                    Assert.IsTrue(position.Y == y);
                }
            }
        }