|
@@ -187,7 +187,8 @@ export class SRect {
|
|
return (
|
|
return (
|
|
x >= this.left &&
|
|
x >= this.left &&
|
|
x <= this.right &&
|
|
x <= this.right &&
|
|
- (y >= this.top && y <= this.bottom)
|
|
|
|
|
|
+ y >= this.top &&
|
|
|
|
+ y <= this.bottom
|
|
);
|
|
);
|
|
} // Function contains()
|
|
} // Function contains()
|
|
|
|
|
|
@@ -283,5 +284,38 @@ export class SRect {
|
|
let right = Math.max(this.right, rect.right);
|
|
let right = Math.max(this.right, rect.right);
|
|
let bottom = Math.max(this.bottom, rect.bottom);
|
|
let bottom = Math.max(this.bottom, rect.bottom);
|
|
return new SRect(left, top, right - left, bottom - top);
|
|
return new SRect(left, top, right - left, bottom - top);
|
|
- } // Function union()
|
|
|
|
|
|
+ } // Function unioned()
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成相交矩形
|
|
|
|
+ *
|
|
|
|
+ * @param rect 合并的矩形
|
|
|
|
+ * @return 返回合并后的矩形
|
|
|
|
+ */
|
|
|
|
+ intersected(rect: SRect): SRect {
|
|
|
|
+ let minX = this.left < rect.left ? this.left : rect.left;
|
|
|
|
+ let minY = this.top < rect.top ? this.top : rect.top;
|
|
|
|
+ let maxX = this.right > rect.right ? this.right : rect.right;
|
|
|
|
+ let maxY = this.bottom > rect.bottom ? this.bottom : rect.bottom;
|
|
|
|
+ if (
|
|
|
|
+ this.width + rect.width > maxX - minX &&
|
|
|
|
+ this.height + rect.height > maxY - minY
|
|
|
|
+ ) {
|
|
|
|
+ return new SRect();
|
|
|
|
+ }
|
|
|
|
+ return new SRect();
|
|
|
|
+ } // Function Intersected()
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 相交矩形
|
|
|
|
+ *
|
|
|
|
+ * @param rect 合并的矩形
|
|
|
|
+ */
|
|
|
|
+ intersect(rect: SRect): SRect {
|
|
|
|
+ let left = Math.min(this.left, rect.left);
|
|
|
|
+ let top = Math.min(this.top, rect.top);
|
|
|
|
+ let right = Math.max(this.right, rect.right);
|
|
|
|
+ let bottom = Math.max(this.bottom, rect.bottom);
|
|
|
|
+ return new SRect(left, top, right - left, bottom - top);
|
|
|
|
+ } // Function intersect()
|
|
} // Class SRect
|
|
} // Class SRect
|