aboutsummaryrefslogtreecommitdiff
path: root/src/paperflight/static/util.js
blob: 3f1418224065f1e1c8dd871b0cb2cd27c09f4f71 (plain)
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
/**
 * General purpose functions
 */
function isPointInRamp(x, y, ramp) {
    var yDelta = (x - ramp.x) * ramp.slope
    return ramp.x < x && x < ramp.x + ramp.width && ramp.y < y + yDelta && y + yDelta < ramp.y + ramp.height
}
function isPointInBox(x, y, box) {
    return box.x <= x && x <= box.x + box.width && box.y <= y && y <= box.y + box.height
}
function isPlaneInBox(box) {
    return isPointInBox(plane.x, plane.y, box)
        || isPointInBox(plane.x + plane.width, plane.y, box)
        || isPointInBox(plane.x + plane.width, plane.y + plane.height, box)
        || isPointInBox(plane.x, plane.y + plane.height, box)
}
function isPointInCircle(x, y, circle) {
    return Math.sqrt(Math.pow(x - circle.x, 2) + Math.pow(y - circle.y, 2)) < circle.radius
}
function isPlaneInCircle(circle) {
    return isPointInCircle(plane.x, plane.y, circle)
        || isPointInCircle(plane.x + plane.width, plane.y, circle)
        || isPointInCircle(plane.x + plane.width, plane.y + plane.height, circle)
        || isPointInCircle(plane.x, plane.y + plane.height, circle)
}