Esempio n. 1
0
 internal Rectangle(int x, int y, int w, int h)
 {
     X = x;
     Y = y;
     W = w;
     H = h;
 }
Esempio n. 2
0
 internal Rectangle(double x, double y, double w, double h)
 {
     X = (FixedPoint)x;
     Y = (FixedPoint)y;
     W = (FixedPoint)w;
     H = (FixedPoint)h;
 }
Esempio n. 3
0
 internal Rectangle(double x, double y, double w, double h)
 {
     X = (FixedPoint)x;
     Y = (FixedPoint)y;
     W = (FixedPoint)w;
     H = (FixedPoint)h;
 }
Esempio n. 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());
        }
Esempio n. 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;
 }
Esempio n. 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);
 }
Esempio n. 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;
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
 }
Esempio n. 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;
        }
Esempio n. 11
0
 private int GetNumWindows(FixedPoint winSz)
 {
     return GetNumWindows(winSz, _w) * GetNumWindows(winSz, _h);
 }
Esempio n. 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);
 }
Esempio n. 13
0
 public static FixedPoint Max(FixedPoint left, FixedPoint right)
 {
     return(left > right ? left : right);
 }
Esempio n. 14
0
 public static FixedPoint Max(FixedPoint left, FixedPoint right)
 {
     return left > right ? left : right;
 }
Esempio n. 15
0
 public static FixedPoint Min(FixedPoint left, FixedPoint right)
 {
     return left > right ? right : left;
 }
Esempio n. 16
0
 private int GetNumWindows(FixedPoint winSz)
 {
     return(GetNumWindows(winSz, _w) * GetNumWindows(winSz, _h));
 }
Esempio n. 17
0
 public static FixedPoint Min(FixedPoint left, FixedPoint right)
 {
     return(left > right ? right : left);
 }
Esempio n. 18
0
 public void OperatorMinusTest(FixedPoint number, FixedPoint subtrahend)
 {
     Assert.AreEqual(4 - (FixedPoint)3, 1);
 }
Esempio n. 19
0
 public void OperatorLShiftTest(FixedPoint number, int shift)
 {
     Assert.AreEqual((FixedPoint)4 << 3, 4*8);
 }
Esempio n. 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;
        }
Esempio n. 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;
 }
Esempio n. 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();
 }