(points: Readonly<Array<P>>)
| 75 | |
| 76 | // Returns the convex hull, assuming that each points[i] <= points[i + 1]. Runs in O(n) time. |
| 77 | function getHullPresorted<P extends Point>(points: Readonly<Array<P>>): Array<P> { |
| 78 | if (points.length <= 1) return points.slice() |
| 79 | |
| 80 | const upperHull: Array<P> = [] |
| 81 | for (let i = 0; i < points.length; i++) { |
| 82 | const p = points[i] |
| 83 | while (upperHull.length >= 2) { |
| 84 | const q = upperHull[upperHull.length - 1] |
| 85 | const r = upperHull[upperHull.length - 2] |
| 86 | if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) upperHull.pop() |
| 87 | else break |
| 88 | } |
| 89 | upperHull.push(p) |
| 90 | } |
| 91 | upperHull.pop() |
| 92 | |
| 93 | const lowerHull: Array<P> = [] |
| 94 | for (let i = points.length - 1; i >= 0; i--) { |
| 95 | const p = points[i] |
| 96 | while (lowerHull.length >= 2) { |
| 97 | const q = lowerHull[lowerHull.length - 1] |
| 98 | const r = lowerHull[lowerHull.length - 2] |
| 99 | if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) lowerHull.pop() |
| 100 | else break |
| 101 | } |
| 102 | lowerHull.push(p) |
| 103 | } |
| 104 | lowerHull.pop() |
| 105 | |
| 106 | if ( |
| 107 | upperHull.length === 1 && |
| 108 | lowerHull.length === 1 && |
| 109 | upperHull[0].x === lowerHull[0].x && |
| 110 | upperHull[0].y === lowerHull[0].y |
| 111 | ) { |
| 112 | return upperHull |
| 113 | } else { |
| 114 | return upperHull.concat(lowerHull) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | export const usePointerInTransit = ({ |
| 119 | triggerEl, |
no outgoing calls
no test coverage detected
searching dependent graphs…