Пример #1
0
 internal Rectangle(int x, int y, int w, int h)
 {
     X = x;
     Y = y;
     W = w;
     H = h;
 }
Пример #2
0
 internal Rectangle(double x, double y, double w, double h)
 {
     X = (FixedPoint)x;
     Y = (FixedPoint)y;
     W = (FixedPoint)w;
     H = (FixedPoint)h;
 }
Пример #3
0
 internal Rectangle(double x, double y, double w, double h)
 {
     X = (FixedPoint)x;
     Y = (FixedPoint)y;
     W = (FixedPoint)w;
     H = (FixedPoint)h;
 }
Пример #4
0
        private static int GetIndex(FixedPoint center, FixedPoint winSz, FixedPoint offset)
        {
            //Find ideal coordinate
            var coord = center - winSz / 2;

            //Snap to grid
            return((coord / offset).Round());
        }
Пример #5
0
 private FixedPoint GetPixelValue(int x, int y, FixedPoint zoom, FixedPoint xBase, FixedPoint yBase)
 {
     var xloc = xBase + x * zoom - 1;
     var yloc = yBase + y * zoom - 1;
     var topLeft = Interpolate(xloc, yloc);
     var lowLeft = Interpolate(xloc, yloc + zoom);
     var topRight = Interpolate(xloc + zoom, yloc);
     var lowRight = Interpolate(xloc + zoom, yloc + zoom);
     return lowRight - topRight - lowLeft + topLeft;
 }
Пример #6
0
 //Note that this is the opposite of normal bounds checking: the region between lowBound and highBound
 //must fit entirely within the region from location to location+width.
 private static bool CheckContains(FixedPoint location, FixedPoint winSz, FixedPoint lowBound, FixedPoint highBound)
 {
     if (location > lowBound)
     {
         return(false);
     }
     if (location + winSz < highBound)
     {
         return(false);
     }
     return(true);
 }
Пример #7
0
        //private FixedPoint WinSize(int size)
        //{
        //    var sz = WinSizes().GetEnumerator();
        //    for (var i = 0; i < size; i++)
        //    {
        //        sz.MoveNext();
        //    }
        //    return sz.Current;
        //}

        //C# doesn't allow to set floating point modes, but we require absolute repeatability...
        private IEnumerable <FixedPoint> WinSizes()
        {
            FixedPoint sz = _szMin;

            while (sz < Math.Min(_w, _h))
            {
                yield return(sz);

                var multiplier = (1 << _szExp) + 1;
                //int divisor = 1 << stepExp;
                sz = (sz * multiplier) >> _szExp;
            }
        }
Пример #8
0
        private int GetNumWindows(FixedPoint winSz, int length)
        {
            //double availableWidth = (length - winSz);
            //double offset = (winSz / Math.Pow(2, offsetExp));
            //return checked((int)Math.Floor(availableWidth / offset) + 1);

            if (winSz < 0)
            {
                throw new ArgumentOutOfRangeException("winSz");
            }
            if (length < winSz)
            {
                throw new ArgumentOutOfRangeException("length");
            }
            return(((length / winSz - 1) << _offsetExp).Floor() + 1);
        }
Пример #9
0
 internal static Rectangle Rectangle(this Canvas canvas, Rectangle rect)
 {
     if (canvas.Background is ImageBrush && ((ImageBrush)canvas.Background).ImageSource is BitmapImage)
     {
         var image = (BitmapImage)((ImageBrush)canvas.Background).ImageSource;
         rect.X = FixedPoint.Min(FixedPoint.Max(rect.X, 0), image.PixelWidth - 1);
         rect.W = FixedPoint.Min(rect.W, image.PixelWidth - rect.X - 1);
         rect.Y = FixedPoint.Min(FixedPoint.Max(rect.Y, 0), image.PixelHeight - 1);
         rect.H = FixedPoint.Min(rect.H, image.PixelHeight - rect.Y - 1);
         rect.H = rect.W = FixedPoint.Min(rect.W, rect.H);
     }
     else
     {
         rect.X = FixedPoint.Max(rect.X, 0);
         rect.Y = FixedPoint.Max(rect.Y, 0);
         rect.H = rect.W = FixedPoint.Min(rect.H, rect.W);
     }
     return(rect);
 }
Пример #10
0
        private FixedPoint Interpolate(FixedPoint x, FixedPoint y)
        {
            var wholeX = x.Floor();
            var wholeY = y.Floor();
            var fracX = x - wholeX;
            var fracY = y - wholeY;

            /*           Key:
             * +++++^    +: sum
             * +++++^    ^: rt
             * +++++^    ~: lo
             * ~~~~~&    &: lr
             * 
             */

            var sum = InImage(wholeX, wholeY) ? _integralImage[wholeX, wholeY] : 0;
            var rt = InImage(wholeX, wholeY + 1) ? _integralImage[wholeX, wholeY + 1] - sum : 0;
            var lo = InImage(wholeX + 1, wholeY) ? _integralImage[wholeX + 1, wholeY] - sum : 0;
            var lr = InImage(wholeX + 1, wholeY + 1) ? _integralImage[wholeX + 1, wholeY + 1] - (sum + rt + lo) : 0;

            return sum + rt * fracX + lo * fracY + lr * fracX * fracY;
        }
Пример #11
0
 private int GetNumWindows(FixedPoint winSz)
 {
     return GetNumWindows(winSz, _w) * GetNumWindows(winSz, _h);
 }
Пример #12
0
 private FixedPoint GetSurroundingPixVal(int n, int x, int y, FixedPoint zoom, FixedPoint xBase, FixedPoint yBase)
 {
     return GetPixelValue(x + Configuration.XOffsets[n], y + Configuration.YOffsets[n], zoom, xBase, yBase);
 }
Пример #13
0
 public static FixedPoint Max(FixedPoint left, FixedPoint right)
 {
     return(left > right ? left : right);
 }
Пример #14
0
 public static FixedPoint Max(FixedPoint left, FixedPoint right)
 {
     return left > right ? left : right;
 }
Пример #15
0
 public static FixedPoint Min(FixedPoint left, FixedPoint right)
 {
     return left > right ? right : left;
 }
Пример #16
0
 private int GetNumWindows(FixedPoint winSz)
 {
     return(GetNumWindows(winSz, _w) * GetNumWindows(winSz, _h));
 }
Пример #17
0
 public static FixedPoint Min(FixedPoint left, FixedPoint right)
 {
     return(left > right ? right : left);
 }
Пример #18
0
 public void OperatorMinusTest(FixedPoint number, FixedPoint subtrahend)
 {
     Assert.AreEqual(4 - (FixedPoint)3, 1);
 }
Пример #19
0
 public void OperatorLShiftTest(FixedPoint number, int shift)
 {
     Assert.AreEqual((FixedPoint)4 << 3, 4*8);
 }
Пример #20
0
        private int GetNumWindows(FixedPoint winSz, int length)
        {
            //double availableWidth = (length - winSz);
            //double offset = (winSz / Math.Pow(2, offsetExp));
            //return checked((int)Math.Floor(availableWidth / offset) + 1);

            if (winSz < 0)
            {
                throw new ArgumentOutOfRangeException("winSz");
            }
            if (length < winSz)
            {
                throw new ArgumentOutOfRangeException("length");
            }
            return ((length / winSz - 1) << _offsetExp).Floor() + 1;
        }
Пример #21
0
 //Note that this is the opposite of normal bounds checking: the region between lowBound and highBound
 //must fit entirely within the region from location to location+width.
 private static bool CheckContains(FixedPoint location, FixedPoint winSz, FixedPoint lowBound, FixedPoint highBound)
 {
     if (location > lowBound) return false;
     if (location + winSz < highBound) return false;
     return true;
 }
Пример #22
0
 private static int GetIndex(FixedPoint center, FixedPoint winSz, FixedPoint offset)
 {
     //Find ideal coordinate
     var coord = center - winSz / 2;
     //Snap to grid
     return (coord / offset).Round();
 }