{"version":3,"file":"squaredDistanceToLineSegment.mjs","sources":["../../../src/maths/misc/squaredDistanceToLineSegment.ts"],"sourcesContent":["/**\n * Calculates the squared distance from a point to a line segment defined by two endpoints.\n * @param x - x coordinate of the point\n * @param y - y coordinate of the point\n * @param x1 - x coordinate of the first endpoint of the line segment\n * @param y1 - y coordinate of the first endpoint of the line segment\n * @param x2 - x coordinate of the second endpoint of the line segment\n * @param y2 - y coordinate of the second endpoint of the line segment\n * @returns The squared distance from the point to the line segment\n * @category maths\n * @internal\n */\nexport function squaredDistanceToLineSegment(\n    x: number, y: number,\n    x1: number, y1: number,\n    x2: number, y2: number\n): number\n{\n    const a = x - x1;\n    const b = y - y1;\n    const c = x2 - x1;\n    const d = y2 - y1;\n\n    const dot = (a * c) + (b * d);\n    const lenSq = (c * c) + (d * d);\n    let param = -1;\n\n    if (lenSq !== 0)\n    {\n        param = dot / lenSq;\n    }\n\n    let xx; let\n        yy;\n\n    if (param < 0)\n    {\n        xx = x1;\n        yy = y1;\n    }\n    else if (param > 1)\n    {\n        xx = x2;\n        yy = y2;\n    }\n\n    else\n    {\n        xx = x1 + (param * c);\n        yy = y1 + (param * d);\n    }\n\n    const dx = x - xx;\n    const dy = y - yy;\n\n    return (dx * dx) + (dy * dy);\n}\n"],"names":[],"mappings":";AAYO,SAAS,6BACZ,CAAA,EAAW,CAAA,EACX,EAAA,EAAY,EAAA,EACZ,IAAY,EAAA,EAEhB;AACI,EAAA,MAAM,IAAI,CAAA,GAAI,EAAA;AACd,EAAA,MAAM,IAAI,CAAA,GAAI,EAAA;AACd,EAAA,MAAM,IAAI,EAAA,GAAK,EAAA;AACf,EAAA,MAAM,IAAI,EAAA,GAAK,EAAA;AAEf,EAAA,MAAM,GAAA,GAAO,CAAA,GAAI,CAAA,GAAM,CAAA,GAAI,CAAA;AAC3B,EAAA,MAAM,KAAA,GAAS,CAAA,GAAI,CAAA,GAAM,CAAA,GAAI,CAAA;AAC7B,EAAA,IAAI,KAAA,GAAQ,CAAA,CAAA;AAEZ,EAAA,IAAI,UAAU,CAAA,EACd;AACI,IAAA,KAAA,GAAQ,GAAA,GAAM,KAAA;AAAA,EAClB;AAEA,EAAA,IAAI,EAAA;AAAI,EAAA,IACJ,EAAA;AAEJ,EAAA,IAAI,QAAQ,CAAA,EACZ;AACI,IAAA,EAAA,GAAK,EAAA;AACL,IAAA,EAAA,GAAK,EAAA;AAAA,EACT,CAAA,MAAA,IACS,QAAQ,CAAA,EACjB;AACI,IAAA,EAAA,GAAK,EAAA;AACL,IAAA,EAAA,GAAK,EAAA;AAAA,EACT,CAAA,MAGA;AACI,IAAA,EAAA,GAAK,KAAM,KAAA,GAAQ,CAAA;AACnB,IAAA,EAAA,GAAK,KAAM,KAAA,GAAQ,CAAA;AAAA,EACvB;AAEA,EAAA,MAAM,KAAK,CAAA,GAAI,EAAA;AACf,EAAA,MAAM,KAAK,CAAA,GAAI,EAAA;AAEf,EAAA,OAAQ,EAAA,GAAK,KAAO,EAAA,GAAK,EAAA;AAC7B;;;;"}