IsNumber() статический приватный Метод

static private IsNumber ( float x ) : bool
x float
Результат bool
Пример #1
0
        public static unsafe ColorBgra GetBilinearSampleWrapped(ISurface src, ColorBgra *srcDataPtr, int srcWidth, int srcHeight, float x, float y)
        {
            if (!Utility.IsNumber(x) || !Utility.IsNumber(y))
            {
                return(ColorBgra.Transparent);
            }

            float u = x;
            float v = y;

            unchecked {
                int  iu        = (int)Math.Floor(u);
                uint sxfrac    = (uint)(256 * (u - (float)iu));
                uint sxfracinv = 256 - sxfrac;

                int  iv        = (int)Math.Floor(v);
                uint syfrac    = (uint)(256 * (v - (float)iv));
                uint syfracinv = 256 - syfrac;

                uint wul = (uint)(sxfracinv * syfracinv);
                uint wur = (uint)(sxfrac * syfracinv);
                uint wll = (uint)(sxfracinv * syfrac);
                uint wlr = (uint)(sxfrac * syfrac);

                int sx = iu;
                if (sx < 0)
                {
                    sx = (srcWidth - 1) + ((sx + 1) % srcWidth);
                }
                else if (sx > (srcWidth - 1))
                {
                    sx = sx % srcWidth;
                }

                int sy = iv;
                if (sy < 0)
                {
                    sy = (srcHeight - 1) + ((sy + 1) % srcHeight);
                }
                else if (sy > (srcHeight - 1))
                {
                    sy = sy % srcHeight;
                }

                int sleft = sx;
                int sright;

                if (sleft == (srcWidth - 1))
                {
                    sright = 0;
                }
                else
                {
                    sright = sleft + 1;
                }

                int stop = sy;
                int sbottom;

                if (stop == (srcHeight - 1))
                {
                    sbottom = 0;
                }
                else
                {
                    sbottom = stop + 1;
                }

                ColorBgra cul = src.GetPoint(sleft, stop);
                ColorBgra cur = src.GetPoint(sright, stop);
                ColorBgra cll = src.GetPoint(sleft, sbottom);
                ColorBgra clr = src.GetPoint(sright, sbottom);

                ColorBgra c = ColorBgra.BlendColors4W16IP(cul, wul, cur, wur, cll, wll, clr, wlr);

                return(c);
            }
        }
Пример #2
0
        public static unsafe ColorBgra GetBilinearSampleClamped(ISurface src, float x, float y)
        {
            if (!Utility.IsNumber(x) || !Utility.IsNumber(y))
            {
                return(ColorBgra.Transparent);
            }

            float u = x;
            float v = y;

            if (u < 0)
            {
                u = 0;
            }
            else if (u > src.Width - 1)
            {
                u = src.Width - 1;
            }

            if (v < 0)
            {
                v = 0;
            }
            else if (v > src.Height - 1)
            {
                v = src.Height - 1;
            }

            unchecked {
                int  iu        = (int)Math.Floor(u);
                uint sxfrac    = (uint)(256 * (u - (float)iu));
                uint sxfracinv = 256 - sxfrac;

                int  iv        = (int)Math.Floor(v);
                uint syfrac    = (uint)(256 * (v - (float)iv));
                uint syfracinv = 256 - syfrac;

                uint wul = (uint)(sxfracinv * syfracinv);
                uint wur = (uint)(sxfrac * syfracinv);
                uint wll = (uint)(sxfracinv * syfrac);
                uint wlr = (uint)(sxfrac * syfrac);

                int sx    = iu;
                int sy    = iv;
                int sleft = sx;
                int sright;

                if (sleft == (src.Width - 1))
                {
                    sright = sleft;
                }
                else
                {
                    sright = sleft + 1;
                }

                int stop = sy;
                int sbottom;

                if (stop == (src.Height - 1))
                {
                    sbottom = stop;
                }
                else
                {
                    sbottom = stop + 1;
                }

                ColorBgra *cul = src.GetPointAddress(sleft, stop);
                ColorBgra *cur = cul + (sright - sleft);
                ColorBgra *cll = src.GetPointAddress(sleft, sbottom);
                ColorBgra *clr = cll + (sright - sleft);

                ColorBgra c = ColorBgra.BlendColors4W16IP(*cul, wul, *cur, wur, *cll, wll, *clr, wlr);
                return(c);
            }
        }