/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Angle } from "@vertexvis/geometry";
import * as Point from "../../../../geometry/src/point";
export function createArrowheadPoints(start, end, arrowSideLength, arrowHeadTheta) {
    const arrowOrthogonalVector = Point.orthogonalVector(start, end);
    const normalizedDirection = Point.normalDirectionVector(start, end);
    const arrowLeft = Point.subtract(end, Point.add(Point.scaleProportional(normalizedDirection, arrowSideLength * Math.cos(arrowHeadTheta)), Point.scaleProportional(arrowOrthogonalVector, arrowSideLength * Math.sin(arrowHeadTheta))));
    const arrowRight = Point.subtract(end, Point.subtract(Point.scaleProportional(normalizedDirection, arrowSideLength * Math.cos(arrowHeadTheta)), Point.scaleProportional(arrowOrthogonalVector, arrowSideLength * Math.sin(arrowHeadTheta))));
    return {
        leftPoint: arrowLeft,
        rightPoint: arrowRight,
    };
}
export function createLineAnchorStylePoints(start, end, triangleArrowAngle = 65, lineArrowAngle = 85) {
    // Adjust the size of the end style to the distance between the start and end points
    const distance = Point.distance(start, end);
    const arrowHeadHeight = Math.max(4, Math.min(16, distance * 0.25));
    const hashHeight = Math.max(4, Math.min(12, distance * 0.16));
    const radius = Math.min(5, distance * 0.1);
    // Triangle arrow position
    const triangleArrowRelativeHeight = arrowHeadHeight / distance;
    const triangleArrowBasePosition = Point.add(Point.scaleProportional(end, 1 - triangleArrowRelativeHeight), Point.scaleProportional(start, triangleArrowRelativeHeight));
    const triangleArrowTheta = Angle.toRadians(triangleArrowAngle / 2);
    const triangleArrowSideLength = arrowHeadHeight / Math.cos(triangleArrowTheta);
    const triangleArrow = createArrowheadPoints(start, end, triangleArrowSideLength, triangleArrowTheta);
    // Line arrow position
    const lineArrowTheta = Angle.toRadians(lineArrowAngle / 2);
    const lineArrowSideLength = arrowHeadHeight / Math.cos(lineArrowTheta);
    const lineArrow = createArrowheadPoints(start, end, lineArrowSideLength, lineArrowTheta);
    // Hash position
    // Setting the arrowHeadAngle to 90 degrees results in a
    // straight hash mark perpendicular to the direction of the line
    const hashLineTheta = Angle.toRadians(90);
    const hashLine = createArrowheadPoints(start, end, hashHeight, hashLineTheta);
    return {
        tip: end,
        base: triangleArrowBasePosition,
        arrowTriangle: triangleArrow,
        arrowLine: lineArrow,
        hash: hashLine,
        radius: radius,
    };
}
export function arrowheadPointsToPolygonPoints(points, scale = 1) {
    const scaledRight = scalePointProportional(points.tip, points.arrowTriangle.rightPoint, scale);
    const scaledLeft = scalePointProportional(points.tip, points.arrowTriangle.leftPoint, scale);
    const scaledBase = scalePointProportional(points.tip, points.base, scale);
    return [points.tip, scaledRight, scaledBase, scaledLeft]
        .map((pt) => `${pt.x},${pt.y}`)
        .join(' ');
}
export function arrowheadPointsToPathPoints(points, scale = 1) {
    const scaledRight = scalePointProportional(points.tip, points.arrowLine.rightPoint, scale);
    const scaledLeft = scalePointProportional(points.tip, points.arrowLine.leftPoint, scale);
    return `M${scaledRight.x} ${scaledRight.y} L${points.tip.x} ${points.tip.y} L${scaledLeft.x} ${scaledLeft.y} L${points.tip.x} ${points.tip.y} Z`;
}
export function arrowheadPointsToHashPoints(points, scale = 1) {
    const scaledRight = scalePointProportional(points.tip, points.hash.rightPoint, scale);
    const scaledLeft = scalePointProportional(points.tip, points.hash.leftPoint, scale);
    return {
        x1: scaledRight.x,
        y1: scaledRight.y,
        x2: scaledLeft.x,
        y2: scaledLeft.y,
    };
}
export function arrowheadPointsToCirclePoints(points, scale = 1) {
    return {
        cx: points.tip.x,
        cy: points.tip.y,
        r: points.radius * scale,
    };
}
export function isVertexViewerArrowMarkup(el) {
    return (el instanceof HTMLElement && el.nodeName === 'VERTEX-VIEWER-MARKUP-ARROW');
}
export function parsePoint(value) {
    return typeof value === 'string' ? Point.fromJson(value) : value;
}
export function scalePointProportional(basePoint, scaledPoint, scale) {
    return Point.add(basePoint, Point.scaleProportional(Point.subtract(scaledPoint, basePoint), scale));
}
//# sourceMappingURL=utils.js.map
