-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathpolygon-ellipse.js
More file actions
27 lines (26 loc) · 831 Bytes
/
polygon-ellipse.js
File metadata and controls
27 lines (26 loc) · 831 Bytes
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
var polygonPoint = require('./polygon-point')
var lineEllipse = require('./line-ellipse')
/**
* polygon-ellipse collision
* @param {number[]} points [x1, y1, x2, y2, ... xn, yn] of polygon
* @param {number} xe center of ellipse
* @param {number} ye center of ellipse
* @param {number} rex radius-x of ellipse
* @param {number} rey radius-y of ellipse
*/
module.exports = function polygonEllipse(points, xe, ye, rex, rey)
{
if (polygonPoint(points, xe, ye))
{
return true
}
var count = points.length
for (var i = 0; i < count - 2; i += 2)
{
if (lineEllipse(points[i], points[i + 1], points[i + 2], points[i + 3], xe, ye, rex, rey))
{
return true
}
}
return lineEllipse(points[0], points[1], points[count - 2], points[count - 1], xe, ye, rex, rey)
}