/// 交差判定
 public bool IntersectsWith(IntRect other)
 {
     return !(this.X > other.Right || other.X > this.Right ||
      this.Y > other.Bottom || other.Y > this.Bottom);
 }
        /// 含有判定
        /// @param other 判定対象のRect
        /// @return 含有しているか
        public bool Contains(IntRect other)
        {
            if (this.Width < 0 || this.Height < 0 ||
            other.Width < 0 || other.Height < 0) return false;

            // 開始点
            if (other.X < this.X || other.Y < this.Y) return false;
            // Right
            if (other.Right <= other.X) {
              // other.Widthが負の数
              if (this.X <= this.Right || this.Right < other.Right) return false;
            } else {
              if (this.X <= this.Right && this.Right < other.Right) return false;
            }
            // Bottom
            if (other.Bottom <= other.Y) {
              // other.Heightが負の数
              if (this.Y <= this.Bottom || this.Bottom < other.Bottom) return false;
            } else {
              if (this.Y <= this.Bottom && this.Bottom < other.Bottom) return false;
            }
            return true;
        }
 /// 交差
 public void Intersect(IntRect other)
 {
     if (!this.IntersectsWith(other)) return;
     var newX = Math.Max(this.X, other.X);
     var newY = Math.Max(this.Y, other.Y);
     var newRight = Math.Min(this.Right, other.Right);
     var newBottom = Math.Min(this.Bottom, other.Bottom);
     this.X = newX;
     this.Y = newY;
     this.Width = newRight - newX;
     this.Height = newBottom - newY;
 }
예제 #4
0
 /// 交差判定
 public bool IntersectsWith(IntRect other)
 {
     return(!(this.X > other.Right || other.X > this.Right ||
              this.Y > other.Bottom || other.Y > this.Bottom));
 }