Exemplo n.º 1
0
 public void Fill(RectangleC rect)
 {
     if (rect.Width > 0)
     {
         int initialWord  = (int)((uint)rect.Left >> WordShift);
         int finalWord    = (rect.Right - 1) >> WordShift;
         int initialShift = (int)((uint)rect.Left & WordMask);
         int finalShift   = 32 - (int)((uint)rect.Right & WordMask);
         for (int xw = initialWord; xw <= finalWord; ++xw)
         {
             uint mask = ~0u;
             if (xw == initialWord && initialShift != 0)
             {
                 mask = mask << initialShift;
             }
             if (xw == finalWord && finalShift != WordSize)
             {
                 mask = (mask << finalShift) >> finalShift;
             }
             for (int y = rect.Bottom; y < rect.Top; ++y)
             {
                 Map[y, xw] |= mask;
             }
         }
     }
 }
Exemplo n.º 2
0
        void Combine(BinaryMap source, RectangleC area, Point at, CombineFunction function)
        {
            int shift      = (int)((uint)area.X & WordMask) - (int)((uint)at.X & WordMask);
            int vectorSize = (area.Width >> WordShift) + 2;

            Parallel.For(0, area.Height,
                         () => new CombineLocals {
                Vector = new uint[vectorSize], SrcVector = new uint[vectorSize]
            },
                         delegate(int y, ParallelLoopState state, CombineLocals locals)
            {
                LoadLine(locals.Vector, new Point(at.X, at.Y + y), area.Width);
                source.LoadLine(locals.SrcVector, new Point(area.X, area.Y + y), area.Width);
                if (shift >= 0)
                {
                    ShiftLeft(locals.SrcVector, shift);
                }
                else
                {
                    ShiftRight(locals.SrcVector, -shift);
                }
                function(locals.Vector, locals.SrcVector);
                SaveLine(locals.Vector, new Point(at.X, at.Y + y), area.Width);
                return(locals);
            }, locals => { });
        }
Exemplo n.º 3
0
 public RectangleC(RectangleC other)
 {
     X      = other.X;
     Y      = other.Y;
     Width  = other.Width;
     Height = other.Height;
 }
Exemplo n.º 4
0
        public RectangleC GetShifted(Point relative)
        {
            RectangleC result = new RectangleC(this);

            result.Shift(relative);
            return(result);
        }
Exemplo n.º 5
0
 public void AndNot(BinaryMap source, RectangleC area, Point at)
 {
     Combine(source, area, at, delegate(uint[] target, uint[] srcVector)
     {
         for (int i = 0; i < target.Length; ++i)
         {
             target[i] &= ~srcVector[i];
         }
     });
 }
Exemplo n.º 6
0
        public BlockMap(Size pixelSize, int maxBlockSize)
        {
            PixelCount = pixelSize;
            BlockCount = new Size(
                Calc.DivRoundUp(PixelCount.Width, maxBlockSize),
                Calc.DivRoundUp(PixelCount.Height, maxBlockSize));
            CornerCount = BlockToCornerCount(BlockCount);

            AllBlocks  = new RectangleC(BlockCount);
            AllCorners = new RectangleC(CornerCount);

            Corners      = InitCorners();
            BlockAreas   = new RectangleGrid(Corners);
            BlockCenters = InitBlockCenters();
            CornerAreas  = InitCornerAreas();
        }
Exemplo n.º 7
0
 public void Clip(RectangleC other)
 {
     if (Left < other.Left)
     {
         Left = other.Left;
     }
     if (Right > other.Right)
     {
         Right = other.Right;
     }
     if (Bottom < other.Bottom)
     {
         Bottom = other.Bottom;
     }
     if (Top > other.Top)
     {
         Top = other.Top;
     }
 }
Exemplo n.º 8
0
        public void Copy(BinaryMap source, RectangleC area, Point at)
        {
            int shift = (int)((uint)area.X & WordMask) - (int)((uint)at.X & WordMask);

            Parallel.For(0, area.Height,
                         () => new uint[(area.Width >> WordShift) + 2],
                         delegate(int y, ParallelLoopState state, uint[] vector)
            {
                source.LoadLine(vector, new Point(area.X, area.Y + y), area.Width);
                if (shift >= 0)
                {
                    ShiftLeft(vector, shift);
                }
                else
                {
                    ShiftRight(vector, -shift);
                }
                SaveLine(vector, new Point(at.X, at.Y + y), area.Width);
                return(vector);
            }, vector => { });
        }