Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 120x 60x 60x 60x 60x 18x 42x 8x 34x 34x | import { Types } from '@cornerstonejs/core';
function dist2(p1: Types.Point2, p2: Types.Point2): number {
return (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]);
}
/**
* Calculates the distance-squared of a point to a line
*
* @param lineStart - x,y coordinates of the start of the line
* @param lineEnd - x,y coordinates of the end of the line
* @param point - x,y of the point
* @returns distance-squared
*/
export default function distanceToPointSquared(
lineStart: Types.Point2,
lineEnd: Types.Point2,
point: Types.Point2
): number {
const d2 = dist2(lineStart, lineEnd);
Iif (d2 === 0) {
return dist2(point, lineStart);
}
const t =
((point[0] - lineStart[0]) * (lineEnd[0] - lineStart[0]) +
(point[1] - lineStart[1]) * (lineEnd[1] - lineStart[1])) /
d2;
if (t < 0) {
return dist2(point, lineStart);
}
if (t > 1) {
return dist2(point, lineEnd);
}
const pt: Types.Point2 = [
lineStart[0] + t * (lineEnd[0] - lineStart[0]),
lineStart[1] + t * (lineEnd[1] - lineStart[1]),
];
return dist2(point, pt);
}
|