File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
app/src/core/stage/stageObject/collisionBox Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,11 @@ export class CollisionBox {
3838 return false ;
3939 }
4040
41+ /**
42+ * 非完全覆盖框选
43+ * @param rectangle
44+ * @returns
45+ */
4146 public isIntersectsWithRectangle ( rectangle : Rectangle ) : boolean {
4247 for ( const shape of this . shapeList ) {
4348 if ( shape . isCollideWithRectangle ( rectangle ) ) {
@@ -47,6 +52,36 @@ export class CollisionBox {
4752 return false ;
4853 }
4954
55+ /**
56+ * 完全覆盖框选
57+ * @param rectangle
58+ * @returns
59+ */
60+ public isContainedByRectangle ( rectangle : Rectangle ) : boolean {
61+ for ( const shape of this . shapeList ) {
62+ const shapeRectangle = shape . getRectangle ( ) ;
63+ const shapeLeftTop = shapeRectangle . location ;
64+ const shapeRightBottom = new Vector (
65+ shapeLeftTop . x + shapeRectangle . size . x ,
66+ shapeLeftTop . y + shapeRectangle . size . y ,
67+ ) ;
68+
69+ const rectLeftTop = rectangle . location ;
70+ const rectRightBottom = new Vector ( rectLeftTop . x + rectangle . size . x , rectLeftTop . y + rectangle . size . y ) ;
71+
72+ // 判断每个形状的最小外接矩形是否完全在给定矩形内
73+ if (
74+ shapeLeftTop . x < rectLeftTop . x ||
75+ shapeLeftTop . y < rectLeftTop . y ||
76+ shapeRightBottom . x > rectRightBottom . x ||
77+ shapeRightBottom . y > rectRightBottom . y
78+ ) {
79+ return false ;
80+ }
81+ }
82+ return true ;
83+ }
84+
5085 public isIntersectsWithLine ( line : Line ) : boolean {
5186 for ( const shape of this . shapeList ) {
5287 if ( shape . isCollideWithLine ( line ) ) {
You can’t perform that action at this time.
0 commit comments