/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Line3, Point } from "@vertexvis/geometry";
export function translateWorldLineToViewport(line, params) {
    const { camera, viewport } = params;
    const isStartBehindCamera = camera.isPointBehindNear(line.start);
    const isEndBehindCamera = camera.isPointBehindNear(line.end);
    // If either the start or end of the line is behind the camera, then we need
    // to truncate the line so it can be presented correctly. You cannot use a
    // projection matrix to compute a point behind the near plane.
    if (isStartBehindCamera || isEndBehindCamera) {
        const pt = camera.intersectLineWithNear(line);
        const newLine = Line3.create({
            start: isStartBehindCamera && pt != null ? pt : line.start,
            end: isEndBehindCamera && pt != null ? pt : line.end,
        });
        const ndc = Line3.transformMatrix(newLine, camera.projectionViewMatrix);
        return {
            start: viewport.transformVectorToViewport(ndc.start),
            end: viewport.transformVectorToViewport(ndc.end),
            hideStart: isStartBehindCamera,
            hideEnd: isEndBehindCamera,
        };
    }
    else {
        const ndc = Line3.transformMatrix(line, camera.projectionViewMatrix);
        return {
            start: viewport.transformVectorToViewport(ndc.start),
            end: viewport.transformVectorToViewport(ndc.end),
            hideStart: false,
            hideEnd: false,
        };
    }
}
export function getViewingElementPositions(line, interactingAnchor, params) {
    const { start: startPt, end: endPt, hideStart, hideEnd, } = translateWorldLineToViewport(line, params);
    const labelPt = Point.lerp(startPt, endPt, 0.5);
    const indicatorPt = interactingAnchor !== 'none'
        ? getIndicatorPtForAnchor(line, interactingAnchor, params)
        : undefined;
    return { startPt, endPt, labelPt, indicatorPt, hideStart, hideEnd };
}
export function isVertexViewerDistanceMeasurement(el) {
    return (el instanceof HTMLElement &&
        el.nodeName === 'VERTEX-VIEWER-MEASUREMENT-DISTANCE');
}
function getIndicatorPtForAnchor(line, anchor, params) {
    return params.viewport.transformWorldToViewport(anchor === 'start' ? line.start : line.end, params.camera.projectionViewMatrix);
}
//# sourceMappingURL=utils.js.map
