@dartbot/dartboard
Version:
Dartboard implemented as a vanilla web component
46 lines (45 loc) • 1.99 kB
TypeScript
import { PolarPoint } from '../utils/polar-point';
export interface Board {
radius: number;
rings: number[];
sectors: number[];
}
export declare const createBoard: () => {
radius: number;
rings: number[];
sectors: number[];
};
export declare const radiansToDegrees: (radians: number) => number;
/** Gets the size of the angle in radians for a single board sector */
export declare const getSectorWidth: (b: Board) => number;
/** Gets the point value for the sector at the given index */
export declare const getSectorValue: (board: Board, i: number) => number;
/** Get the index of the sector that has the given value */
export declare const getSectorIndex: (board: Board, sectorValue: number) => number | undefined;
/** Gets the distance from center that is the center point of the ring */
export declare const getRingCenter: (board: Board, ring: number) => number;
/**
* Gets the point coordinate of the center of a given area
* of the board defined by the sector and ring
*/
export declare const getTargetPoint: (board: Board, sectorIndex: number, ringIndex: number) => PolarPoint;
/**
* Creates a random point within a given sector and ring
* @param board Board object containing rings and sectors
* @param sectorIndex Sector the point should lie within
* @param ringIndex Ring the point should lie within
* @param rng Random number generator
*/
export declare const getRandomPoint: (board: Board, sectorIndex: number, ringIndex: number, rng?: () => number) => PolarPoint;
/**
* Gets the index of the sector the point is in
* @param board Board object containing rings and sectors
* @param p PolarPoint on the board
*/
export declare const getSectorIndexFromPoint: (board: Board, p: PolarPoint) => number;
/**
* Gets the index of the ring the point is in
* @param board Board object containing rings and sectors
* @param p PolarPoint on the board
*/
export declare const getRingIndexFromPoint: (board: Board, p: PolarPoint) => number | undefined;