pointscape
Version:
Points manipulation: distance & angle helpers, collisions, shapes, array & math utilities — 2D coordinate system
205 lines (157 loc) • 8.85 kB
text/typescript
interface Point$1$1 {
x: number;
y: number;
}
type Coordinate$1 = "x" | "y";
type Direction$1 = "left" | "right" | "up" | "down";
interface Bounds$1 {
min: number;
max: number;
}
interface Line$1 {
start: Point$1$1;
end: Point$1$1;
}
interface Point$1 {
x: number;
y: number;
}
type Coordinate = "x" | "y";
type Direction = "left" | "right" | "up" | "down";
interface Bounds {
min: number;
max: number;
}
interface Line {
start: Point$1;
end: Point$1;
}
declare const distance: (point1: Point$1, point2: Point$1) => number;
declare const collision: (point1: Point$1, point2: Point$1, collisionDistance: number, callback?: () => void) => boolean;
declare const middle: (point1: Point$1, point2: Point$1) => Point$1;
declare const pointWithoutCollision: (xBounds: Bounds, yBounds: Bounds, distanceBetweenPoints: number, others: Point$1[], currentTryCount?: number) => Point$1 | string;
declare const collisionInArray: (initialPoint: Point$1, arr: Point$1[], radius: number) => Point$1[];
declare const angle: (point1: Point$1, point2: Point$1) => number;
declare const randomPoints: (xBounds: Bounds, yBounds: Bounds, quantity: number) => Point$1[];
declare const area: (points: Point$1[]) => number;
declare const triangleArea: ({ x: x1, y: y1 }: Point$1, { x: x2, y: y2 }: Point$1, { x: x3, y: y3 }: Point$1) => number;
declare const randomPointInDistance: (point: Point$1, distance: number) => Point$1;
declare const nearest: (initialPoint: Point$1, points: Point$1[]) => Point$1 | null;
declare const perimeter: (points: Point$1[]) => number;
declare const positionInCircle: (centerPoint: Point$1, radius: number, angleInRadians: number) => Point$1;
declare const possibleConnections: (pointsCount: number) => number;
declare const circleArea: (radius: number) => number;
declare const center: (points: Point$1[]) => Point$1;
declare const farthest: (initialPoint: Point$1, points: Point$1[]) => Point$1 | null;
declare const randomPoint: (xBounds?: Bounds, yBounds?: Bounds) => Point$1;
declare const move: (initialPoint: Point$1, xStep: number, yStep: number) => Point$1;
declare const scale: (points: Point$1[], scaleFactorX: number, scaleFactorY: number) => {
x: number;
y: number;
}[];
declare const inLine: (point: Point$1, line: Line) => boolean;
declare const getLine: (point1: Point$1, point2: Point$1) => Line;
declare const cross: (line1: Line, line2: Line) => boolean;
declare const rotate: (points: Point$1[], centerPoint: Point$1, angleInRadians: number) => {
x: number;
y: number;
}[];
declare const sort: (points: Point$1[], coordinate?: Coordinate) => Point$1[];
declare const square: (initialPoint: Point$1, size: number, direction?: Direction) => Point$1[];
declare const rectangle: (initialPoint: Point$1, width: number, height: number, direction?: Direction) => Point$1[];
declare const triangle: (initialPoint: Point$1, size: number, direction?: Direction) => Point$1[];
declare const pentagon: (centerPoint: Point$1, radius: number, angle?: number) => {
x: number;
y: number;
}[];
declare const lerp: (point1: Point$1, point2: Point$1, t: number) => Point$1;
declare const inRange: (number: number, minLimit: number, maxLimit: number) => boolean;
declare const roundToPrecision: (number: number, precision: number) => number;
declare const degreesToRadians: (degrees: number) => number;
declare const radiansToDegrees: (radians: number) => number;
declare const average: (numbers: number[]) => number;
declare const uniqueId: (others?: string[]) => string;
declare const randomBoolean: () => boolean;
declare const randomNumber: (min: number, max: number) => number;
declare const intersection: (arr1: unknown[], arr2: unknown[]) => unknown[];
declare const difference: (arr1: unknown[], arr2: unknown[]) => unknown[];
declare const chunk: (array: unknown[], perChunk: number) => unknown[][];
declare const removeDuplicates: (arr: unknown[]) => unknown[];
declare const sample: (arr: unknown[], size?: number) => unknown;
declare class Point implements Point$1 {
x: number;
y: number;
constructor(x: number, y: number);
static from(point: Point$1): Point;
clone(): Point;
equals(other: Point$1): boolean;
toString(): string;
distanceTo(other: Point$1): ReturnType<typeof distance>;
isCollidingWith(other: Point$1, collisionDistance: number): ReturnType<typeof collision>;
isCollidingWithAny(points: Point$1[], collisionDistance: number): ReturnType<typeof collisionInArray>;
middleTo(other: Point$1): Point;
angleTo(other: Point$1): ReturnType<typeof angle>;
move(x: number, y: number): Point;
lerp(other: Point$1, t: number): Point;
rotateAround(center: Point$1, angleRad: number): Point;
nearestFromPoints(points: Point$1[]): Point | null;
farthestFromPoints(points: Point$1[]): Point | null;
isInLine(line: Line): ReturnType<typeof inLine>;
buildLineWith(point: Point$1): ReturnType<typeof getLine>;
}
declare const _default: {
Point: typeof Point;
distance: (point1: Point$1, point2: Point$1) => number;
middle: (point1: Point$1, point2: Point$1) => Point$1;
collision: (point1: Point$1, point2: Point$1, collisionDistance: number, callback?: () => void) => boolean;
pointWithoutCollision: (xBounds: Bounds$1, yBounds: Bounds$1, distanceBetweenPoints: number, others: Point$1[], currentTryCount?: number) => Point$1 | string;
collisionInArray: (initialPoint: Point$1, arr: Point$1[], radius: number) => Point$1[];
angle: (point1: Point$1, point2: Point$1) => number;
randomPoint: (xBounds?: Bounds$1, yBounds?: Bounds$1) => Point$1;
randomPoints: (xBounds: Bounds$1, yBounds: Bounds$1, quantity: number) => Point$1[];
area: (points: Point$1[]) => number;
triangleArea: ({ x: x1, y: y1 }: Point$1, { x: x2, y: y2 }: Point$1, { x: x3, y: y3 }: Point$1) => number;
circleArea: (radius: number) => number;
randomPointInDistance: (point: Point$1, distance: number) => Point$1;
nearest: (initialPoint: Point$1, points: Point$1[]) => Point$1 | null;
farthest: (initialPoint: Point$1, points: Point$1[]) => Point$1 | null;
perimeter: (points: Point$1[]) => number;
positionInCircle: (centerPoint: Point$1, radius: number, angleInRadians: number) => Point$1;
possibleConnections: (pointsCount: number) => number;
center: (points: Point$1[]) => Point$1;
inLine: (point: Point$1, line: Line$1) => boolean;
getLine: (point1: Point$1, point2: Point$1) => Line$1;
rotate: (points: Point$1[], centerPoint: Point$1, angleInRadians: number) => {
x: number;
y: number;
}[];
sort: (points: Point$1[], coordinate?: Coordinate$1) => Point$1[];
move: (initialPoint: Point$1, xStep: number, yStep: number) => Point$1;
scale: (points: Point$1[], scaleFactorX: number, scaleFactorY: number) => {
x: number;
y: number;
}[];
cross: (line1: Line$1, line2: Line$1) => boolean;
square: (initialPoint: Point$1, size: number, direction?: Direction$1) => Point$1[];
rectangle: (initialPoint: Point$1, width: number, height: number, direction?: Direction$1) => Point$1[];
triangle: (initialPoint: Point$1, size: number, direction?: Direction$1) => Point$1[];
pentagon: (centerPoint: Point$1, radius: number, angle?: number) => {
x: number;
y: number;
}[];
lerp: (point1: Point$1, point2: Point$1, t: number) => Point$1;
uniqueId: (others?: string[]) => string;
randomNumber: (min: number, max: number) => number;
randomBoolean: () => boolean;
average: (numbers: number[]) => number;
inRange: (number: number, minLimit: number, maxLimit: number) => boolean;
degreesToRadians: (degrees: number) => number;
radiansToDegrees: (radians: number) => number;
roundToPrecision: (number: number, precision: number) => number;
intersection: (arr1: unknown[], arr2: unknown[]) => unknown[];
difference: (arr1: unknown[], arr2: unknown[]) => unknown[];
chunk: (array: unknown[], perChunk: number) => unknown[][];
removeDuplicates: (arr: unknown[]) => unknown[];
sample: (arr: unknown[], size?: number) => unknown;
};
export { type Bounds, type Coordinate, type Direction, type Line, Point, Point as PointType, angle, area, average, center, chunk, circleArea, collision, collisionInArray, cross, _default as default, degreesToRadians, difference, distance, farthest, getLine, inLine, inRange, intersection, lerp, middle, move, nearest, pentagon, perimeter, pointWithoutCollision, positionInCircle, possibleConnections, radiansToDegrees, randomBoolean, randomNumber, randomPoint, randomPointInDistance, randomPoints, rectangle, removeDuplicates, rotate, roundToPrecision, sample, scale, sort, square, triangle, triangleArea, uniqueId };