示例#1
0
            public void CopyTo(int horizontalFactor, int verticalFactor)
            {
                Block8x8F block = CreateRandomFloatBlock(0, 100);

                var start = new Point(50, 50);

                using (Buffer2D <float> buffer = Configuration.Default.MemoryAllocator.Allocate2D <float>(100, 100, AllocationOptions.Clean))
                {
                    Buffer2DRegion <float> region = buffer.GetRegion(start.X, start.Y, 8 * horizontalFactor, 8 * verticalFactor);
                    block.ScaledCopyTo(region, horizontalFactor, verticalFactor);

                    for (int y = 0; y < 8 * verticalFactor; y++)
                    {
                        for (int x = 0; x < 8 * horizontalFactor; x++)
                        {
                            int yy = y / verticalFactor;
                            int xx = x / horizontalFactor;

                            float expected = block[xx, yy];
                            float actual   = region[x, y];

                            Assert.Equal(expected, actual);
                        }
                    }

                    VerifyAllZeroOutsideSubArea(buffer, start.X, start.Y, horizontalFactor, verticalFactor);
                }
            }
示例#2
0
        public void GetReferenceToOrigin(int bufferCapacity)
        {
            this.memoryAllocator.BufferCapacityInBytes = sizeof(int) * bufferCapacity;

            using Buffer2D <int> buffer = this.CreateTestBuffer(20, 30);
            Buffer2DRegion <int> area0  = buffer.GetRegion(6, 8, 10, 10);

            ref int r = ref area0.GetReferenceToOrigin();
示例#3
0
        public void Indexer(int bufferCapacity, int rx, int ry, int x, int y)
        {
            this.memoryAllocator.BufferCapacityInBytes = sizeof(int) * bufferCapacity;
            using Buffer2D <int> buffer = this.CreateTestBuffer(20, 30);
            var r = new Rectangle(rx, ry, 5, 6);

            Buffer2DRegion <int> region = buffer.GetRegion(r);

            int value    = region[x, y];
            int expected = ((ry + y) * 100) + rx + x;

            Assert.Equal(expected, value);
        }
示例#4
0
        public void GetSubArea()
        {
            using Buffer2D <int> buffer = this.CreateTestBuffer(20, 30);
            Buffer2DRegion <int> area0  = buffer.GetRegion(6, 8, 10, 10);

            Buffer2DRegion <int> area1 = area0.GetSubRegion(4, 4, 5, 5);

            var expectedRect = new Rectangle(10, 12, 5, 5);

            Assert.Equal(buffer, area1.Buffer);
            Assert.Equal(expectedRect, area1.Rectangle);

            int value00 = (12 * 100) + 10;

            Assert.Equal(value00, area1[0, 0]);
        }
示例#5
0
            public void Copy1x1Scale()
            {
                Block8x8F block = CreateRandomFloatBlock(0, 100);

                using (Buffer2D <float> buffer = Configuration.Default.MemoryAllocator.Allocate2D <float>(20, 20, AllocationOptions.Clean))
                {
                    Buffer2DRegion <float> region = buffer.GetRegion(5, 10, 8, 8);
                    block.Copy1x1Scale(ref region.GetReferenceToOrigin(), region.Stride);

                    Assert.Equal(block[0, 0], buffer[5, 10]);
                    Assert.Equal(block[1, 0], buffer[6, 10]);
                    Assert.Equal(block[0, 1], buffer[5, 11]);
                    Assert.Equal(block[0, 7], buffer[5, 17]);
                    Assert.Equal(block[63], buffer[12, 17]);

                    VerifyAllZeroOutsideSubArea(buffer, 5, 10);
                }
            }
示例#6
0
        public void GetRowSpan(int bufferCapacity, int rx, int ry, int y, int w, int h)
        {
            this.memoryAllocator.BufferCapacityInBytes = sizeof(int) * bufferCapacity;

            using Buffer2D <int> buffer = this.CreateTestBuffer(20, 30);
            var r = new Rectangle(rx, ry, w, h);

            Buffer2DRegion <int> region = buffer.GetRegion(r);

            Span <int> span = region.GetRowSpan(y);

            Assert.Equal(w, span.Length);

            for (int i = 0; i < w; i++)
            {
                int expected = ((ry + y) * 100) + rx + i;
                int value    = span[i];

                Assert.Equal(expected, value);
            }
        }