|
@@ -0,0 +1,168 @@
|
|
|
+/*
|
|
|
+ * *********************************************************************************************************************
|
|
|
+ *
|
|
|
+ * !!
|
|
|
+ * .F88X
|
|
|
+ * X8888Y
|
|
|
+ * .}888888N;
|
|
|
+ * i888888N; .:! .I$WI:
|
|
|
+ * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
|
|
|
+ * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
|
|
|
+ * +888888N; .8888888Y "&&8Y.}8,
|
|
|
+ * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
|
|
|
+ * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
|
|
|
+ * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
|
|
|
+ * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
|
|
|
+ * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
|
|
|
+ * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
|
|
|
+ * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
|
|
|
+ * .:R888888I
|
|
|
+ * .&888888I Copyright (c) 2009-2020. 博锐尚格科技股份有限公司
|
|
|
+ * ~8888'
|
|
|
+ * .!88~ All rights reserved.
|
|
|
+ *
|
|
|
+ * *********************************************************************************************************************
|
|
|
+ */
|
|
|
+
|
|
|
+import { SPoint } from "../../src";
|
|
|
+import { SRect, SSize } from "../../src";
|
|
|
+import { SMatrix } from "@persagy-web/base";
|
|
|
+import expect from "expect"
|
|
|
+
|
|
|
+/**
|
|
|
+ * 矩形测试
|
|
|
+ *
|
|
|
+ * @author 韩耀龙 han_yao_long@163.com
|
|
|
+ */
|
|
|
+
|
|
|
+test("构造函数", () => {
|
|
|
+ // 无参数
|
|
|
+ let rect = new SRect()
|
|
|
+ expect(rect.leftTop).toStrictEqual(new SPoint(0, 0));
|
|
|
+ expect(rect.size).toStrictEqual(new SSize(0, 0));
|
|
|
+
|
|
|
+ // 两个参数
|
|
|
+ const leftPoint = new SPoint(0, 0);
|
|
|
+ const rightPoint = new SPoint(2, 2)
|
|
|
+ let rect1 = new SRect(leftPoint, rightPoint)
|
|
|
+ expect(rect1.leftTop).toStrictEqual(new SPoint(0, 0));
|
|
|
+ expect(rect1.size).toStrictEqual(new SSize(2, 2));
|
|
|
+
|
|
|
+ // 四个参数
|
|
|
+ let rect2 = new SRect(0, 0, 4, 4)
|
|
|
+ expect(rect2.leftTop).toStrictEqual(new SPoint(0, 0));
|
|
|
+ expect(rect2.size).toStrictEqual(new SSize(4, 4));
|
|
|
+});
|
|
|
+
|
|
|
+test("isEmpty", () => {
|
|
|
+ // false
|
|
|
+ let rect = new SRect()
|
|
|
+ expect(rect.isEmpty()).toBeTruthy();
|
|
|
+ // true
|
|
|
+ let rect1 = new SRect(0, 0, 4, 4)
|
|
|
+ expect(rect1.isEmpty()).toBeFalsy();
|
|
|
+});
|
|
|
+
|
|
|
+test("isNull", () => {
|
|
|
+ // false
|
|
|
+ let rect = new SRect()
|
|
|
+ expect(rect.isNull()).toBeTruthy();
|
|
|
+ // true
|
|
|
+ let rect1 = new SRect(0, 0, 4, 4)
|
|
|
+ expect(rect1.isNull()).toBeFalsy();
|
|
|
+});
|
|
|
+
|
|
|
+test("isValid,", () => {
|
|
|
+ // width 与 height 都大于 0,返回 true,否则返回 false。
|
|
|
+ // ture
|
|
|
+ let rect = new SRect()
|
|
|
+ expect(rect.isValid()).toBeFalsy();
|
|
|
+ // true
|
|
|
+ let rect1 = new SRect(0, 0, 4, 4)
|
|
|
+ expect(rect1.isValid()).toBeTruthy();
|
|
|
+});
|
|
|
+
|
|
|
+test("isIn", () => {
|
|
|
+ // width 与 height 都大于 0,返回 true,否则返回 false。
|
|
|
+ // ture
|
|
|
+ let rect: SRect = new SRect(0, 0, 4, 4)
|
|
|
+ const inRect = new SRect()
|
|
|
+ expect(rect.isIn(inRect)).toBeTruthy();
|
|
|
+ // false
|
|
|
+ const inRect1 = new SRect(0, 0, 5, 5)
|
|
|
+ expect(rect.isIn(inRect1)).toBeFalsy();
|
|
|
+});
|
|
|
+
|
|
|
+test("contains", () => {
|
|
|
+ // ture
|
|
|
+ let rect = new SRect(0, 0, 4, 4)
|
|
|
+ expect(rect.contains(2, 2)).toBeTruthy();
|
|
|
+ // false
|
|
|
+ expect(rect.contains(5, 5)).toBeFalsy();
|
|
|
+});
|
|
|
+
|
|
|
+test("center", () => {
|
|
|
+ let rect = new SRect(0, 0, 4, 4)
|
|
|
+ expect(rect.center()).toStrictEqual(new SPoint(2, 2));
|
|
|
+});
|
|
|
+
|
|
|
+test("translate", () => {
|
|
|
+ let rect = new SRect(0, 0, 4, 4);
|
|
|
+ rect.translate(2, 2)
|
|
|
+ expect(rect.x).toBe(2);
|
|
|
+ expect(rect.y).toBe(2);
|
|
|
+});
|
|
|
+
|
|
|
+test("translated", () => {
|
|
|
+ let rect = new SRect(0, 0, 4, 4);
|
|
|
+ expect(rect.translated(2, 2)).toStrictEqual(new SRect(2, 2, 4, 4));
|
|
|
+});
|
|
|
+
|
|
|
+test("adjust", () => {
|
|
|
+ let rect = new SRect(0, 0, 4, 4);
|
|
|
+ rect.adjust(2, 2, 2, 2)
|
|
|
+ expect(rect.x).toBe(2);
|
|
|
+ expect(rect.x).toBe(2);
|
|
|
+ expect(rect.width).toBe(6);
|
|
|
+ expect(rect.height).toBe(6);
|
|
|
+});
|
|
|
+
|
|
|
+test("adjusted", () => {
|
|
|
+ let rect = new SRect(0, 0, 4, 4);
|
|
|
+ expect(rect.adjusted(2, 2, 2, 2)).toStrictEqual(new SRect(2, 2, 6, 6));
|
|
|
+});
|
|
|
+
|
|
|
+test("union", () => {
|
|
|
+ let rect = new SRect(0, 0, 4, 4);
|
|
|
+ let rect1 = new SRect(2, 2, 4, 4);
|
|
|
+ rect.union(rect1)
|
|
|
+ expect(rect.x).toBe(0);
|
|
|
+ expect(rect.x).toBe(0);
|
|
|
+ expect(rect.width).toBe(6);
|
|
|
+ expect(rect.height).toBe(6);
|
|
|
+});
|
|
|
+
|
|
|
+test("unioned", () => {
|
|
|
+ let rect = new SRect(0, 0, 4, 4);
|
|
|
+ let rect1 = new SRect(2, 2, 4, 4);
|
|
|
+ expect(rect.unioned(rect1)).toStrictEqual(new SRect(0, 0, 6, 6));
|
|
|
+});
|
|
|
+
|
|
|
+test("intersected", () => {
|
|
|
+ let rect = new SRect(0, 0, 4, 4);
|
|
|
+ let rect1 = new SRect(2, 2, 4, 4);
|
|
|
+ expect(rect.intersected(rect1)).toStrictEqual(new SRect(2, 2, 2, 2));
|
|
|
+ let rect2 = new SRect(5, 5, 4, 4);
|
|
|
+ expect(rect.intersected(rect2)).toStrictEqual(new SRect());
|
|
|
+});
|
|
|
+
|
|
|
+test("intersect", () => {
|
|
|
+ let rect = new SRect(0, 0, 4, 4);
|
|
|
+ let rect1 = new SRect(2, 2, 4, 4);
|
|
|
+ rect.intersected(rect1)
|
|
|
+ expect(rect).toStrictEqual(new SRect(2, 2, 2, 2));
|
|
|
+ let rect2 = new SRect(5, 5, 4, 4);
|
|
|
+ let rect3 = new SRect(1, 1, 1, 1);
|
|
|
+ rect2.intersected(rect3)
|
|
|
+ expect(rect2).toStrictEqual(new SRect());
|
|
|
+});
|