UNPKG

@dominicstop/utils

Version:

Yet another event emitter written in typescript.

81 lines 3.09 kB
import { Rect } from "./Rect"; import { Angle, AngleValue } from "./Angle"; import { BoxedCircle } from "./BoxedCircle"; import { Point } from "./Point"; import { Line } from "./Line"; import { Vector2DValue } from "./Vector2D"; import { BoxedPolygon } from "./interfaces/BoxedPolygon"; import { UniformScaleConfig } from "./Scalelable"; export type HexagonType = 'pointyTopped' | 'flatTopped'; export type BoxedHexagonValue = { circumRadius: number; startAngleOffset?: AngleValue; center: Point; }; export type BoxedHexagonInit = (Pick<BoxedHexagonValue, 'circumRadius' | 'startAngleOffset'>) & ({ mode: 'relativeToCenter'; center: Point; } | { mode: 'relativeToOrigin'; origin: Point; }); export declare class BoxedHexagon implements BoxedPolygon<BoxedHexagonValue> { origin: Point; circumRadius: number; startAngleOffset: Angle; constructor(args: BoxedHexagonInit); get center(): Point; set center(newCenter: Point); get asValue(): BoxedHexagonValue; get sideLength(): number; get perimeter(): number; get inRadius(): number; get apothem(): number; get inCircle(): BoxedCircle; get circumCircle(): BoxedCircle; get boundingBox(): Rect; get cornerAngles(): Array<Angle>; get cornerPointsAsArray(): Array<Point>; get edgeLines(): Array<Line>; get area(): number; get edgeMidpoints(): Array<Point>; clone(): BoxedHexagon; computeTiledHexagonAlongsideEdge(args: { edgeLine: Line; extraPositionOffset?: number; }): BoxedHexagon; isPointInside(point: Point): boolean; rotatedByAngle(angle: Angle): BoxedHexagon; translatedByOffset(offset: Vector2DValue): BoxedHexagon; computeDistanceToOther(other: BoxedHexagon): number; /** * returns true if this hexagon is edge-to-edge with another hexagon. * * * in a regular hex grid, two hexagons are touching if the distance * between their centers equals exactly: `2 * sideLength` (i.e. * one full edge length apart). * * - This check uses the Manhattan distance approximation for performance and simplicity. */ isEdgeToEdgeWithOther(other: this): boolean; /** * returns true if this hexagon is colliding with another hexagon. * * * two hexagons are considered colliding if the distance between their centers * is less than the sum of their in-radius (i.e. shortest distance from center to edge). * * * this uses squared distance to avoid unnecessary square root computation. */ isCollidingWithOther(other: this): boolean; applyUniformScaleByFactor(args: UniformScaleConfig): void; scaledUniformallyByFactor(args: UniformScaleConfig): this; static recenterHexagonsRelativeToPoint(args: { hexagons: Array<BoxedHexagon>; centerPoint: Point; }): void; static initFromValue(args: BoxedHexagonValue): BoxedHexagon; static initFromPresetHexagon(args: BoxedHexagonInit & { hexagonType: HexagonType; }): BoxedHexagon; } //# sourceMappingURL=BoxedHexagon.d.ts.map