Lorem...
25 | Lorem...
27 |
28 |
29 |
30 |
31 |
Yo 1!
32 |
33 |
34 |
35 |
36 |
37 | Lorem...
39 | Lorem...
41 | Lorem...
43 | Lorem...
45 | Kinetics is sure paused by now...
47 |
48 |
49 |
50 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/src/util/pointOnRect.js:
--------------------------------------------------------------------------------
1 | /**
2 | * See: https://stackoverflow.com/a/31254199
3 | *
4 | * Finds the intersection point between the rectangle
5 | * with parallel sides to the x and y axes
6 | * the half-line pointing towards (x,y)
7 | * originating from the middle of the rectangle
8 | *
9 | * Note: the function works given min[XY] <= max[XY],
10 | * even though minY may not be the "top" of the rectangle
11 | * because the coordinate system is flipped.
12 | * Note: if the input is inside the rectangle,
13 | * the line segment wouldn't have an intersection with the rectangle,
14 | * but the projected half-line does.
15 | * Warning: passing in the middle of the rectangle will return the midpoint itself
16 | * there are infinitely many half-lines projected in all directions,
17 | * so let's just shortcut to midpoint (GIGO).
18 | *
19 | * @param x:Number x coordinate of point to build the half-line from
20 | * @param y:Number y coordinate of point to build the half-line from
21 | * @param minX:Number the "left" side of the rectangle
22 | * @param minY:Number the "top" side of the rectangle
23 | * @param maxX:Number the "right" side of the rectangle
24 | * @param maxY:Number the "bottom" side of the rectangle
25 | * @param validate:boolean (optional) whether to treat point inside the rect as error
26 | * @return an object with x and y members for the intersection
27 | * @throws if validate == true and (x,y) is inside the rectangle
28 | * @author TWiStErRob
29 | * @see