示例#1
0
        public Vec2i GetDistanceTo(Rect2i rect)
        {
            int vecX;
            int vecY;

            if (rect.br.X < this.tl.X)
            {
                vecX = rect.br.X - this.tl.X;
            }
            else if (rect.tl.X > this.br.X)
            {
                vecX = rect.tl.X - this.br.X;
            }
            else
            {
                vecX = 0;
            }

            if (rect.br.Y > this.tl.Y)
            {
                vecY = rect.br.Y - this.tl.Y;
            }
            else if (rect.tl.Y < this.br.Y)
            {
                vecY = rect.tl.Y - this.br.Y;
            }
            else
            {
                vecY = 0;
            }

            return(new Vec2i(vecX, vecY));
        }
示例#2
0
 public bool IsTouching(Rect2i rect)
 {
     return((this.tl.X == rect.br.X && this.tl.X > rect.tl.X) ||
            (this.br.X == rect.tl.X && this.br.X < rect.br.X) ||
            (this.tl.Y == rect.br.Y && this.tl.Y < rect.tl.Y) ||
            (this.br.Y == rect.tl.Y && this.br.Y > rect.br.Y));
 }
示例#3
0
        /// <summary>
        /// Trims the rect in a way that its fully contained in the other rect
        /// </summary>
        public void ForceInside(Rect2i other)
        {
            if (this.bl.X < other.bl.X)
            {
                this.TrimWest(other.bl.X - this.bl.X);
            }

            if (this.bl.Y < other.bl.Y)
            {
                this.TrimSouth(other.bl.Y - this.bl.Y);
            }

            if (this.tr.X > other.tr.X)
            {
                this.TrimEast(this.tr.X - other.tr.X);
            }

            if (this.tr.Y > other.tr.Y)
            {
                this.TrimNorth(this.tr.Y - other.tr.Y);
            }
        }
示例#4
0
        public void setInsideRatio_Expanding(double ratio, Rect2i other)
        {
            double real_r = GetRatio();

            if (real_r < ratio)             // Expand Width
            {
                double old = real_r;
                while (real_r < ratio)
                {
                    TrimHorizontal(-1);
                    ForceInside(other);
                    real_r = GetRatio();

                    if (old == real_r)
                    {
                        return;
                    }
                    old = real_r;
                }
            }
            else             // Expand Height
            {
                double old = real_r;
                while (real_r > ratio)
                {
                    TrimVertical(-1);
                    ForceInside(other);
                    real_r = GetRatio();

                    if (old == real_r)
                    {
                        return;
                    }
                    old = real_r;
                }
            }
        }
示例#5
0
 public Rect2i(Rect2i r)
 {
     position = new Vec2i(r.position);
     Width    = r.Width;
     Height   = r.Height;
 }
示例#6
0
 public bool IsColldingWith(Rect2i rect)
 {
     return(!(this.tl.X >= rect.br.X || this.br.X <= rect.tl.X || this.tl.Y <= rect.br.Y || this.br.Y >= rect.tl.Y));
 }