import type { CanvasElement, Point, Vector } from "@hylimo/diagram-common"; import { type Matrix } from "transformation-matrix"; import type { SElement } from "../../model/sElement.js"; import type { InclusiveRange, SnapState } from "./model.js"; /** * Computes the corners of the given element in the target coordinate system. * * @param elementToTargetMatrix the transformation matrix from the element to the target coordinate system * @param element the element to compute the corners for * @returns the corners of the element in the target coordinate system */ export declare function getCanvasElementCorners(elementToTargetMatrix: Matrix, element: Pick): [topLeft: Point, topRight: Point, bottomLeft: Point, bottomRight: Point]; /** * Computes the center point of a canvas element in the target coordinate system. * * @param elementToTargetMatrix - The transformation matrix from the element's local coordinate system to the target coordinate system. * @param element - The canvas element for which the center point is to be calculated. * @returns The center point of the canvas element in the target coordinate system. */ export declare function getCanvasElementCenter(elementToTargetMatrix: Matrix, element: SElement & CanvasElement): Point; /** * Round a number to a fixed number of decimal places. * * @param x The number to round. * @returns The rounded number. */ export declare function round(x: number): number; /** * Deduplicates points in an array by their x and y coordinates. * * @param points The array of points to deduplicate. * @returns A new array with unique points. */ export declare function dedupePoints(points: Point[]): Point[]; /** * Given two ranges, return if the two ranges overlap with each other e.g. * [1, 3] overlaps with [2, 4] while [1, 3] does not overlap with [4, 5]. * * @param param0 One of the ranges to compare * @param param1 The other range to compare against * @returns TRUE if the ranges overlap */ export declare function rangesOverlap([a0, a1]: InclusiveRange, [b0, b1]: InclusiveRange): boolean; /** * Given two ranges,return ther intersection of the two ranges if any e.g. the * intersection of [1, 3] and [2, 4] is [2, 3]. * * @param param0 The first range to compare * @param param1 The second range to compare * @returns The inclusive range intersection or NULL if no intersection */ export declare function rangeIntersection([a0, a1]: InclusiveRange, [b0, b1]: InclusiveRange): InclusiveRange | null; /** * Helper function to compute the intersection of two sorted arrays. * * @param a The first sorted array. * @param b The second sorted array. * @param compare A comparison function for the elements. * @returns The intersection of the two arrays. */ export declare function intersectSortedArrays(a: T[], b: T[], compare: (x: T, y: T) => number): T[]; /** * Determines if a snap offset should be added to the X-direction snap collection. * Manages the nearest snap tracking state by comparing the current offset against the minimum. * If the offset is significantly better than current minimum, it clears existing snaps. * If it's close enough to the minimum (within precision), it allows adding multiple snaps. * Note that cleanupNearestSnaps() should be called eventually to remove snaps that are too far. * * @param state The current snap state tracking minimum offsets and snap collections * @param offset The offset value to evaluate * @returns True if the offset should be added to the snap collection, false otherwise */ export declare function shouldAddSnapX(state: SnapState, offset: number): boolean; /** * Determines if a snap offset should be added to the Y-direction snap collection. * Manages the nearest snap tracking state by comparing the current offset against the minimum. * If the offset is significantly better than current minimum, it clears existing snaps. * If it's close enough to the minimum (within precision), it allows adding multiple snaps. * Note that cleanupNearestSnaps() should be called eventually to remove snaps that are too far. * * @param state The current snap state tracking minimum offsets and snap collections * @param offset The offset value to evaluate * @returns True if the offset should be added to the snap collection, false otherwise */ export declare function shouldAddSnapY(state: SnapState, offset: number): boolean; /** * Removes snaps from the nearest snap collections that are too far from the minimum offset. * This ensures that only snaps within the acceptable precision range are kept. * Used to filter out snaps that may have been valid during collection but are now outside * the threshold when considering the element's current offset. * * @param state The snap state containing snap collections to clean up * @param elementOffset The current offset of the element being snapped */ export declare function cleanupNearestSnaps(state: SnapState, elementOffset: Vector): void; //# sourceMappingURL=util.d.ts.map