MCPcopy
hub / github.com/apache/echarts / projectPointToLine

Function projectPointToLine

src/label/labelGuideHelper.ts:153–177  ·  view source on GitHub ↗
(
    x1: number, y1: number, x2: number, y2: number, x: number, y: number, out: number[], limitToEnds: boolean
)

Source from the content-addressed store, hash-verified

151}
152
153function 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
179function projectPointToRect(
180 x1: number, y1: number, width: number, height: number, x: number, y: number, out: number[]

Callers 3

nearestPointOnPathFunction · 0.85
limitTurnAngleFunction · 0.85
limitSurfaceAngleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…