UNPKG

toosoon-utils

Version:
78 lines (77 loc) 2.57 kB
/** * Convert a radians angle into degrees * * @param {number} radians Angle in radians * @returns {number} Angle in degrees */ export declare function toDegrees(radians: number): number; /** * Convert a degrees angle into radians * * @param {number} degrees Angle in degrees * @returns {number} Angle in radians */ export declare function toRadians(degrees: number): number; /** * Compute the angle (in radians) from a point to another * * @param {number} x1 X-axis coordinate of the start point * @param {number} y1 Y-axis coordinate of the start point * @param {number} x2 X-axis coordinate of the end point * @param {number} y2 Y-axis coordinate of the end point * @returns {number} Computed angle (in radians) */ export declare function angle(x1: number, y1: number, x2: number, y2: number): number; /** * Compute the closest angle (in radians) between two angles * * @param {number} startAngle Start angle (in radians) * @param {number} endAngle End angle (in radians) * @returns {number} Closest angle (in radians) */ export declare function closestAngle(startAngle: number, endAngle: number): number; /** * Compute the distance between two points * * @param {number} x1 X-axis coordinate of the start point * @param {number} y1 Y-axis coordinate of the start point * @param {number} x2 X-axis coordinate of the end point * @param {number} y2 Y-axis coordinate of the end point * @returns {number} Computed distance */ export declare function distance(x1: number, y1: number, x2: number, y2: number): number; /** * Compute the length of the diagonal of a rectangle * * @param {number} width Width of the rectangle * @param {number} height Height of the rectangle * @returns {number} Diagonal length */ export declare function diagonal(width: number, height: number): number; export type FitInput = { width: number; height: number; }; export type FitOutput = { left: number; top: number; width: number; height: number; scale: number; }; /** * Make a target fit a container (cover mode) * * @param {FitInput} target Dimensions of the target * @param {FitInput} container Dimensions of the container * @returns {FitOutput} */ export declare function cover(target: FitInput, container: FitInput): FitOutput; /** * Make a target fit a container (contain mode) * * @param {FitInput} target Dimensions of the target * @param {FitInput} container Dimensions of the container * @returns {FitOutput} */ export declare function contain(target: FitInput, container: FitInput): FitOutput;