MCPcopy Create free account
hub / github.com/phaserjs/phaser / RectangleToTriangle

Function RectangleToTriangle

src/geom/intersects/RectangleToTriangle.js:29–91  ·  view source on GitHub ↗
(rect, triangle)

Source from the content-addressed store, hash-verified

27 * @return {boolean} A value of `true` if objects intersect; otherwise `false`.
28 */
29var RectangleToTriangle = function (rect, triangle)
30{
31 // First the cheapest ones:
32
33 if (
34 triangle.left > rect.right ||
35 triangle.right < rect.left ||
36 triangle.top > rect.bottom ||
37 triangle.bottom < rect.top)
38 {
39 return false;
40 }
41
42 var triA = triangle.getLineA();
43 var triB = triangle.getLineB();
44 var triC = triangle.getLineC();
45
46 // Are any of the triangle points within the rectangle?
47
48 if (Contains(rect, triA.x1, triA.y1) || Contains(rect, triA.x2, triA.y2))
49 {
50 return true;
51 }
52
53 if (Contains(rect, triB.x1, triB.y1) || Contains(rect, triB.x2, triB.y2))
54 {
55 return true;
56 }
57
58 if (Contains(rect, triC.x1, triC.y1) || Contains(rect, triC.x2, triC.y2))
59 {
60 return true;
61 }
62
63 // Cheap tests over, now to see if any of the lines intersect ...
64
65 var rectA = rect.getLineA();
66 var rectB = rect.getLineB();
67 var rectC = rect.getLineC();
68 var rectD = rect.getLineD();
69
70 if (LineToLine(triA, rectA) || LineToLine(triA, rectB) || LineToLine(triA, rectC) || LineToLine(triA, rectD))
71 {
72 return true;
73 }
74
75 if (LineToLine(triB, rectA) || LineToLine(triB, rectB) || LineToLine(triB, rectC) || LineToLine(triB, rectD))
76 {
77 return true;
78 }
79
80 if (LineToLine(triC, rectA) || LineToLine(triC, rectB) || LineToLine(triC, rectC) || LineToLine(triC, rectD))
81 {
82 return true;
83 }
84
85 // None of the lines intersect, so are any rectangle points within the triangle?
86

Callers 2

GetRectangleToTriangleFunction · 0.85

Calls 4

LineToLineFunction · 0.85
ContainsArrayFunction · 0.85
ContainsFunction · 0.50
DecomposeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…