declare function defineGrid>(Hex?: HexFactory): GridFactory> export interface GridFactory { (arrayOrHex?: T[] | T, ...hexes: T[]): Grid isValidHex(value: any): boolean pointToHex(pointOrX?: PointCoordinates, y?: number): T parallelogram(options: { width: number, height: number, start?: HexCoordinates, direction?: 1 | 3 | 5, onCreate?: onCreateCallback }): Grid triangle(options: { size: number, start?: HexCoordinates, direction?: 1 | 5, onCreate?: onCreateCallback }): Grid hexagon(options: { radius: number, center?: HexCoordinates, onCreate?: onCreateCallback }): Grid rectangle(options: { width: number, height: number, start?: HexCoordinates, direction?: CompassDirection | number, onCreate?: onCreateCallback }): Grid } export type onCreateCallback = (hex: Hex, grid: Grid) => void interface ConcatArray { readonly length: number readonly [n: number]: T join(separator?: string): string slice(start?: number, end?: number): T[] } export class Grid> extends Array { // defined in class: fill(): never includes(point: PointCoordinates, fromIndex?: number): boolean indexOf(point: PointCoordinates, fromIndex?: number): number lastIndexOf(point: PointCoordinates, fromIndex?: number): number push(...hexes: T[]): number splice(start: number, deleteCount: number, ...hexes: T[]): Grid unshift(...hexes: T[]): number // inherited from Array.prototype: concat(...items: Array>): Grid filter(callbackfn: (hex: T, index: number, grid: Grid) => any, thisArg?: any): Grid find(predicate: (hex: T, index: number, grid: Grid) => any, thisArg?: any): T | undefined findIndex(predicate: (hex: T, index: number, grid: Grid) => any, thisArg?: any): number forEach(callbackfn: (hex: T, index: number, grid: Grid) => void, thisArg?: any): void map(callbackfn: (hex: T, index: number, grid: Grid) => U, thisArg?: any): Grid reduce(callbackfn: (previousValue: U, hex: T, index: number, grid: Grid) => U, initialValue?: U): U reduceRight(callbackfn: (previousValue: U, hex: T, index: number, grid: Grid) => U, initialValue?: U): U reverse(): Grid some(callbackfn: (hex: T, index: number, grid: Grid) => any, thisArg?: any): boolean // defined in prototype: get(keyOrPoint: number | PointCoordinates): T | undefined hexesBetween(firstHex: T, lastHex: T): T[] neighborsOf( hex: T, directions?: CompassDirection[] | number[] | CompassDirection | number | 'all', diagonal?: boolean ): T[] set(keyOrPoint: number | PointCoordinates, newHex?: T): this } export enum PointyCompassDirection { E, SE, SW, W, NW, NE } export enum FlatCompassDirection { SE, S, SW, NW, N, NE } export type CompassDirection = PointyCompassDirection | FlatCompassDirection declare function extendHex

(prototype?: P): HexFactory

export interface HexFactory

{ (xOrProps?: HexCoordinates | P, y?: number, customProps?: P): Hex

thirdCoordinate(firstCoordinate: number, secondCoordinate: number): number } export type HexCoordinates = PointCoordinates | CubeCoordinates export type Hex = { [P in keyof T]: T[P] } & BaseHex export interface BaseHex extends PointLike { __isHoneycombHex: true orientation: 'pointy' | 'flat' origin: number size: number offset: number q: number r: number s: number add(point: PointCoordinates): Hex cartesian(): PointLike cartesianToCube(pointOrX?: PointCoordinates, y?: number): CubeCoordinates center(): Point coordinates(): PointLike corners(): Point[] cube(): CubeCoordinates cubeToCartesian(cubeCoordinates: { q: number, r: number, s?: number }): PointLike distance(hex: CubeCoordinates): number equals(point: PointCoordinates): boolean fromPoint(pointOrX?: PointCoordinates, y?: number): Hex height(): number isFlat(): boolean isPointy(): boolean lerp(hex: { q: number, r: number, s?: number }, t: number): Hex nudge(): Hex oppositeCornerDistance(): number oppositeSideDistance(): number round(): Hex set(): Hex subtract(point: PointCoordinates): Hex toCartesian(cubeCoordinates: { q: number, r: number, s?: number }): PointLike toCube(pointOrX?: PointCoordinates, y?: number): CubeCoordinates toPoint(): Point toString(): string width(): number } export interface CubeCoordinates { q: number r: number s: number } declare function PointFactory(pointOrX?: PointCoordinates, y?: number): Point export interface Point extends PointLike { add(pointOrX?: PointCoordinates, y?: number): Point subtract(pointOrX?: PointCoordinates, y?: number): Point multiply(pointOrX?: PointCoordinates, y?: number): Point divide(pointOrX?: PointCoordinates, y?: number): Point } export interface PointLike { x: number y: number } export type PointCoordinates = number | [number, number] | Partial type Partial = { [P in keyof T]?: T[P] } export { defineGrid, extendHex, PointFactory as Point }