UNPKG

toosoon-utils

Version:
78 lines (77 loc) 2.51 kB
/** * Convert a radians value into degrees * * @param {number} radians Angle in radians * @returns {number} Angle in degrees */ export declare function toDegrees(radians: number): number; /** * Convert a degrees value into radians * * @param {number} degrees Angle in degrees * @returns {number} Angle in radians */ export declare function toRadians(degrees: number): number; /** * Calculate the angle 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} Angle */ export declare function angle(x1: number, y1: number, x2: number, y2: number): number; /** * Find the closest angle between to angles * * @param {number} source Source angle (in radians) * @param {number} target Target angle (in radians) * @returns {number} Closest angle */ export declare function closestAngle(source: number, target: number): number; /** * Calculate the distance between two points * * @param {number} x1 X-axis coordinate of the first point * @param {number} y1 Y-axis coordinate of the first point * @param {number} x2 X-axis coordinate of the second point * @param {number} y2 Y-axis coordinate of the second point * @returns {number} Computed distance */ export declare function distance(x1: number, y1: number, x2: number, y2: number): number; /** * Calculate 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;