Ejemplo n.º 1
0
 public Bounds(FastBounds2D bb, float time, params T[] args)
 {
     this.bb     = bb;
     this.center = bb.Center;
     this.time   = time;
     this.args   = args;
 }
Ejemplo n.º 2
0
        public static Vector2 SampleIn(this FastBounds2D fb, float uv_x, float uv_y)
        {
            var min  = fb.Min;
            var max  = fb.Max;
            var size = fb.Size;

            return(new Vector2(
                       Mathf.Lerp(min.x, max.x, uv_x),
                       Mathf.Lerp(min.y, max.y, uv_y)));
        }
Ejemplo n.º 3
0
        public static Vector2 ClosestPoint(this FastBounds2D fb, Vector2 point)
        {
            var min = fb.Min;
            var max = fb.Max;
            var x0  = min.x;
            var y0  = min.y;
            var x1  = max.x;
            var y1  = max.y;

            var xp = point.x;
            var yp = point.y;

            if (yp < y0)
            {
                return(new Vector2((xp < x0 ? x0 : (xp < x1 ? xp : x1)), y0));
            }
            else if (yp < y1)
            {
                if (xp < x0)
                {
                    return(new Vector2(x0, yp));
                }
                if (x1 < xp)
                {
                    return(new Vector2(x1, yp));
                }

                var minDist = xp - x0;
                var result  = new Vector2(x0, yp);
                if (x1 - xp < minDist)
                {
                    minDist = x1 - xp;
                    result  = new Vector2(x1, yp);
                }
                if (yp - y0 < minDist)
                {
                    minDist = yp - y0;
                    result  = new Vector2(xp, y0);
                }
                if (y1 - yp < minDist)
                {
                    minDist = y1 - yp;
                    result  = new Vector2(xp, y1);
                }
                return(result);
            }
            else
            {
                return(new Vector2((xp < x0 ? x0 : (xp < x1 ? xp : x1)), y1));
            }
        }
Ejemplo n.º 4
0
 public Bounds(FastBounds2D bb, params T[] args) : this(bb, Time.timeSinceLevelLoad, args)
 {
 }
Ejemplo n.º 5
0
 public static Vector2 SampleIn(this FastBounds2D fb)
 {
     return(fb.SampleIn(Random.value, Random.value));
 }