|
Last change
on this file since a762898 was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Prototype 1.1
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | export default function(a, b, x0, y0, x1, y1) {
|
|---|
| 2 | var ax = a[0],
|
|---|
| 3 | ay = a[1],
|
|---|
| 4 | bx = b[0],
|
|---|
| 5 | by = b[1],
|
|---|
| 6 | t0 = 0,
|
|---|
| 7 | t1 = 1,
|
|---|
| 8 | dx = bx - ax,
|
|---|
| 9 | dy = by - ay,
|
|---|
| 10 | r;
|
|---|
| 11 |
|
|---|
| 12 | r = x0 - ax;
|
|---|
| 13 | if (!dx && r > 0) return;
|
|---|
| 14 | r /= dx;
|
|---|
| 15 | if (dx < 0) {
|
|---|
| 16 | if (r < t0) return;
|
|---|
| 17 | if (r < t1) t1 = r;
|
|---|
| 18 | } else if (dx > 0) {
|
|---|
| 19 | if (r > t1) return;
|
|---|
| 20 | if (r > t0) t0 = r;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | r = x1 - ax;
|
|---|
| 24 | if (!dx && r < 0) return;
|
|---|
| 25 | r /= dx;
|
|---|
| 26 | if (dx < 0) {
|
|---|
| 27 | if (r > t1) return;
|
|---|
| 28 | if (r > t0) t0 = r;
|
|---|
| 29 | } else if (dx > 0) {
|
|---|
| 30 | if (r < t0) return;
|
|---|
| 31 | if (r < t1) t1 = r;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | r = y0 - ay;
|
|---|
| 35 | if (!dy && r > 0) return;
|
|---|
| 36 | r /= dy;
|
|---|
| 37 | if (dy < 0) {
|
|---|
| 38 | if (r < t0) return;
|
|---|
| 39 | if (r < t1) t1 = r;
|
|---|
| 40 | } else if (dy > 0) {
|
|---|
| 41 | if (r > t1) return;
|
|---|
| 42 | if (r > t0) t0 = r;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | r = y1 - ay;
|
|---|
| 46 | if (!dy && r < 0) return;
|
|---|
| 47 | r /= dy;
|
|---|
| 48 | if (dy < 0) {
|
|---|
| 49 | if (r > t1) return;
|
|---|
| 50 | if (r > t0) t0 = r;
|
|---|
| 51 | } else if (dy > 0) {
|
|---|
| 52 | if (r < t0) return;
|
|---|
| 53 | if (r < t1) t1 = r;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
|
|---|
| 57 | if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
|
|---|
| 58 | return true;
|
|---|
| 59 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.