-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
GetRectangleToTriangle.js
42 lines (36 loc) · 1.33 KB
/
GetRectangleToTriangle.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
/**
* @author Florian Vazelle
* @author Geoffrey Glaive
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var RectangleToTriangle = require('./RectangleToTriangle');
var GetLineToRectangle = require('./GetLineToRectangle');
/**
* Checks for intersection between Rectangle shape and Triangle shape,
* and returns the intersection points as a Point object array.
*
* @function Phaser.Geom.Intersects.GetRectangleToTriangle
* @since 3.0.0
*
* @param {Phaser.Geom.Rectangle} rect - Rectangle object to test.
* @param {Phaser.Geom.Triangle} triangle - Triangle object to test.
* @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 GetRectangleToTriangle = function (rect, triangle, out)
{
if (out === undefined) { out = []; }
if (RectangleToTriangle(rect, triangle))
{
var lineA = triangle.getLineA();
var lineB = triangle.getLineB();
var lineC = triangle.getLineC();
GetLineToRectangle(lineA, rect, out);
GetLineToRectangle(lineB, rect, out);
GetLineToRectangle(lineC, rect, out);
}
return out;
};
module.exports = GetRectangleToTriangle;