(
x1: number, y1: number, x2: number, y2: number, x: number, y: number, out: number[], limitToEnds: boolean
)
| 151 | } |
| 152 | |
| 153 | function projectPointToLine( |
| 154 | x1: number, y1: number, x2: number, y2: number, x: number, y: number, out: number[], limitToEnds: boolean |
| 155 | ) { |
| 156 | const dx = x - x1; |
| 157 | const dy = y - y1; |
| 158 | |
| 159 | let dx1 = x2 - x1; |
| 160 | let dy1 = y2 - y1; |
| 161 | |
| 162 | const lineLen = Math.sqrt(dx1 * dx1 + dy1 * dy1); |
| 163 | dx1 /= lineLen; |
| 164 | dy1 /= lineLen; |
| 165 | |
| 166 | // dot product |
| 167 | const projectedLen = dx * dx1 + dy * dy1; |
| 168 | let t = projectedLen / lineLen; |
| 169 | if (limitToEnds) { |
| 170 | t = Math.min(Math.max(t, 0), 1); |
| 171 | } |
| 172 | t *= lineLen; |
| 173 | const ox = out[0] = x1 + t * dx1; |
| 174 | const oy = out[1] = y1 + t * dy1; |
| 175 | |
| 176 | return Math.sqrt((ox - x) * (ox - x) + (oy - y) * (oy - y)); |
| 177 | } |
| 178 | |
| 179 | function projectPointToRect( |
| 180 | x1: number, y1: number, width: number, height: number, x: number, y: number, out: number[] |
no outgoing calls
no test coverage detected
searching dependent graphs…