/
GetCircleToRectangle.js
44 lines (38 loc) · 1.36 KB
/
GetCircleToRectangle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @author Florian Vazelle
* @author Geoffrey Glaive
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var GetLineToCircle = require('./GetLineToCircle');
var CircleToRectangle = require('./CircleToRectangle');
/**
* Checks for intersection between a circle and a rectangle,
* and returns the intersection points as a Point object array.
*
* @function Phaser.Geom.Intersects.GetCircleToRectangle
* @since 3.0.0
*
* @param {Phaser.Geom.Circle} circle - The circle to be checked.
* @param {Phaser.Geom.Rectangle} rect - The rectangle to be checked.
* @param {array} [out] - An optional array in which to store the points of intersection.
*
* @return {array} An array with the points of intersection if objects intersect, otherwise an empty array.
*/
var GetCircleToRectangle = function (circle, rect, out)
{
if (out === undefined) { out = []; }
if (CircleToRectangle(circle, rect))
{
var lineA = rect.getLineA();
var lineB = rect.getLineB();
var lineC = rect.getLineC();
var lineD = rect.getLineD();
GetLineToCircle(lineA, circle, out);
GetLineToCircle(lineB, circle, out);
GetLineToCircle(lineC, circle, out);
GetLineToCircle(lineD, circle, out);
}
return out;
};
module.exports = GetCircleToRectangle;