isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
67 lines • 3.46 kB
TypeScript
import { Direction } from "isaac-typescript-definitions";
/**
* Helper function to normalize a number, ensuring that it is within a certain range.
*
* - If `num` is less than `min`, then it will be clamped to `min`.
* - If `num` is greater than `max`, then it will be clamped to `max`.
*/
export declare function clamp(num: number, min: number, max: number): number;
export declare function getAngleDifference(angle1: float, angle2: float): float;
/**
* Helper function to get an array of equidistant points on the circumference around a circle.
* Useful for equally distributing things in a circle pattern.
*
* @param centerPos A position that represents the center of the center to get the points from.
* @param radius The length of the radius of the circle.
* @param numPoints The number of points on the circumference of the circle to get.
* @param xMultiplier An optional multiplier to get the points around an oval. Default is 1.
* @param yMultiplier An optional multiplier to get the points around an oval. Default is 1.
* @param initialDirection By default, the first point on the circle will be on the top center, but
* this can be optionally changed by specifying this argument.
*/
export declare function getCircleDiscretizedPoints(centerPos: Vector, radius: float, numPoints: int, xMultiplier?: number, yMultiplier?: number, initialDirection?: Direction): ReadonlyArray<Readonly<Vector>>;
/**
* Helper function to check if a given position is within a given rectangle.
*
* This is an inclusive check, meaning that it will return true if the position is on the border of
* the rectangle.
*/
export declare function inRectangle(position: Vector, topLeft: Vector, bottomRight: Vector): boolean;
/**
* From: https://www.geeksforgeeks.org/check-if-any-point-overlaps-the-given-circle-and-rectangle/
*/
export declare function isCircleIntersectingRectangle(circleCenter: Vector, circleRadius: float, rectangleTopLeft: Vector, rectangleBottomRight: Vector): boolean;
export declare function isEven(num: int): boolean;
export declare function isOdd(num: int): boolean;
export declare function lerp(a: number, b: number, pos: float): number;
export declare function lerpAngleDegrees(aStart: number, aEnd: number, percent: float): number;
/**
* If rounding fails, this function returns 0.
*
* From: http://lua-users.org/wiki/SimpleRound
*
* @param num The number to round.
* @param numDecimalPlaces Optional. Default is 0.
*/
export declare function round(num: float, numDecimalPlaces?: number): float;
/** @returns 1 if n is positive, -1 if n is negative, or 0 if n is 0. */
export declare function sign(n: number): int;
/**
* Breaks a number into chunks of a given size. This is similar to the `String.split` method, but
* for a number instead of a string.
*
* For example, `splitNumber(90, 25)` would return an array with four elements:
*
* - [1, 25]
* - [26, 50]
* - [51, 75]
* - [76, 90]
*
* @param num The number to split into chunks. This must be a positive integer.
* @param size The size of each chunk. This must be a positive integer.
* @param startAtZero Whether to start at 0. Defaults to false. If true, the chunks will start at 0
* instead of 1.
*/
export declare function splitNumber(num: int, size: int, startAtZero?: boolean): ReadonlyArray<readonly [min: int, max: int]>;
export declare function tanh(x: number): number;
//# sourceMappingURL=math.d.ts.map