File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @author Richard Davey <rich@photonstorm.com>
3+ * @copyright 2019 Photon Storm Ltd.
4+ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License }
5+ */
6+
7+ /**
8+ * Checks if two rectangle bodies are intersecting, either with or without the optional padding.
9+ *
10+ * @function Phaser.Physics.Arcade.IntersectsRect
11+ * @since 3.17.0
12+ *
13+ * @param {Phaser.Physics.Arcade.Body } body1 - The first Body to separate.
14+ * @param {Phaser.Physics.Arcade.Body } body2 - The second Body to separate.
15+ * @param {number } [padding] -
16+ *
17+ * @return {boolean }
18+ */
19+ var IntersectsRect = function ( body1 , body2 , padding )
20+ {
21+ if ( padding === undefined ) { padding = 0 ; }
22+
23+ if ( padding === 0 )
24+ {
25+ return ! (
26+ body1 . right <= body2 . x ||
27+ body1 . bottom <= body2 . y ||
28+ body1 . x >= body2 . right ||
29+ body1 . y >= body2 . bottom
30+ ) ;
31+ }
32+ else
33+ {
34+ // Rect vs. Rect with extra padding for touching / blocked checks
35+ var b1r = body1 . right + padding ;
36+ var b1b = body1 . bottom + padding ;
37+ var b1x = body1 . x - padding ;
38+ var b1y = body1 . y - padding ;
39+
40+ var b2r = body2 . right + padding ;
41+ var b2b = body2 . bottom + padding ;
42+ var b2x = body2 . x - padding ;
43+ var b2y = body2 . y - padding ;
44+
45+ return ! (
46+ b1r <= b2x ||
47+ b1b <= b2y ||
48+ b1x >= b2r ||
49+ b1y >= b2b
50+ ) ;
51+ }
52+ } ;
53+
54+ module . exports = IntersectsRect ;
You can’t perform that action at this time.
0 commit comments