import { rotate } from "../../map/utils";
const PERFORATION_WIDTH = 1.5;
const PERFORATION_OFFSET = 7;
const PERFORATION_HEIGHT = 18;
const SCREEN_HEIGHT = 10;
const SCREEN_INDENT = 3;
/**
 * Returns two-dimensional geometry positions for different types of trajectory markers.
 *
 * **Note:** If a 3D anchor point is provided, the returned geometry will include the anchor's Z position for *each
 * point*. The resulting geometry is a object in 3D space that lays flat on the XY-plane
 * @param markerType The marker type to build
 * @param anchorPoint The world position to place the anchor at
 * @param angle The angle of the marker
 * @returns A GeoJson geometry object
 */
export function buildMarkerPath2D(markerType, anchorPoint, angle) {
    switch (markerType) {
        case "perforation":
            return buildPerforationTrianglePolygonCoordinates(anchorPoint, angle);
        case "screen-start":
            return buildScreenMarkerLineCoordinates2D(anchorPoint, angle, "start");
        case "screen-end":
            return buildScreenMarkerLineCoordinates2D(anchorPoint, angle, "end");
        default:
            throw new Error(`Unknown marker type: ${markerType}`);
    }
}
function getRotatedPoint2D(point, pivotPoint, rotation) {
    return rotate(point[0], point[1], pivotPoint[0], pivotPoint[1], rotation);
}
function buildPerforationTrianglePolygonCoordinates(anchorPoint, rotation) {
    const point1 = [
        anchorPoint[0],
        anchorPoint[1] + (PERFORATION_HEIGHT + PERFORATION_OFFSET),
    ];
    const point2 = [
        anchorPoint[0] - PERFORATION_WIDTH,
        anchorPoint[1] + PERFORATION_OFFSET,
    ];
    const point3 = [
        anchorPoint[0] + PERFORATION_WIDTH,
        anchorPoint[1] + PERFORATION_OFFSET,
    ];
    const rotatedPoint1 = getRotatedPoint2D(point1, anchorPoint, rotation);
    const rotatedPoint2 = getRotatedPoint2D(point2, anchorPoint, rotation);
    const rotatedPoint3 = getRotatedPoint2D(point3, anchorPoint, rotation);
    // Keep the z coordinate the same so the marker still follows the path if this happens to be used in 3d (the marker will look "flat")
    rotatedPoint1.push(anchorPoint[2]);
    rotatedPoint2.push(anchorPoint[2]);
    rotatedPoint3.push(anchorPoint[2]);
    return [rotatedPoint1, rotatedPoint2, rotatedPoint3, rotatedPoint1];
}
function buildScreenMarkerLineCoordinates2D(anchorPoint, rotation, type) {
    if (type === "end")
        rotation += Math.PI;
    const pointCenter = [...anchorPoint];
    const pointAbove = [
        anchorPoint[0] + SCREEN_INDENT,
        anchorPoint[1] + SCREEN_HEIGHT,
    ];
    const pointBelow = [
        anchorPoint[0] + SCREEN_INDENT,
        anchorPoint[1] - SCREEN_HEIGHT,
    ];
    const rotatedPointAbove = getRotatedPoint2D(pointAbove, anchorPoint, rotation);
    const rotatedPointBelow = getRotatedPoint2D(pointBelow, anchorPoint, rotation);
    // Keep the z coordinate the same so the marker still follows the path if this happens to be used in 3d (the marker will look "flat")
    rotatedPointAbove.push(anchorPoint[2]);
    rotatedPointBelow.push(anchorPoint[2]);
    return [rotatedPointAbove, pointCenter, rotatedPointBelow];
}
//# sourceMappingURL=markers.js.map