-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathellipse-box.js
More file actions
22 lines (21 loc) · 855 Bytes
/
ellipse-box.js
File metadata and controls
22 lines (21 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var ellipseLine = require('./ellipse-line')
var boxPoint = require('./box-point')
/**
* ellipse-box (axis-oriented rectangle) collision
* @param {number} xe center of ellipse
* @param {number} ye center of ellipse
* @param {radius} rex radius-x of ellipse
* @param {radius} rey radius-y of ellipse
* @param {number} xb top-left corner of box
* @param {number} yb top-left corner of box
* @param {number} wb width of box
* @param {number} hb height of box
*/
module.exports = function ellipseBox(xe, ye, rex, rey, xb, yb, wb, hb)
{
return boxPoint(xb, yb, wb, hb, xe, ye) ||
ellipseLine(xe, ye, rex, rey, xb, yb, xb + wb, yb) ||
ellipseLine(xe, ye, rex, rey, xb, yb + hb, xb + wb, yb + hb) ||
ellipseLine(xe, ye, rex, rey, xb, yb, xb, yb + hb) ||
ellipseLine(xe, ye, rex, rey, xb + wb, yb, xb + wb, yb + hb)
}