UNPKG

ixfx

Version:

A framework for programming interactivity

1,457 lines (1,385 loc) 204 kB
import { C as CirclePositioned, a as Circle, b as CircleRandomPointOpts } from './CircleType-D9Xd-yDE.js'; import { P as Path, C as CompoundPath$1, D as Dimensions, W as WithBeziers } from './PathType-m0JxWZvm.js'; import { a as Point3d, P as Point, b as Placeholder$3, c as Placeholder3d } from './PointType-BDlA07rn.js'; import { R as RandomSource } from './Types-CR0Pe5zY.js'; import { T as Triangle, Q as QuadraticBezier, C as CubicBezier, a as CubicBezierPath, b as QuadraticBezierPath, c as Arc, A as ArcPositioned, d as Ellipse } from './Ellipse-Dfv4Jz-W.js'; import { a as RectPositioned, b as Rect3dPositioned, R as Rect, c as RectArray, d as RectPositionedArray, e as Rect3d } from './RectTypes-CjvCxMc4.js'; import { P as PolyLine, L as Line } from './LineType-DkIFzpdp.js'; import { G as Grid, f as GridCell, g as GridBoundsLogic, a as GridCellAccessor, b as GridCellSetter, h as GridArray1d, d as GridReadable, c as GridWritable, e as GridCardinalDirection, i as GridNeighbours, j as GridCardinalDirectionOptional, k as GridCellAndValue, l as GridVisual, m as GridNeighbour, n as GridNeighbourSelectionLogic, o as GridVisitorOpts, p as GridCreateVisitor, q as GridIdentifyNeighbours, r as GridNeighbourMaybe, s as GridNeighbourSelector } from './Types-CeD-4LiW.js'; import { a as PointRelation, P as PointRelationResult } from './PointRelationTypes-CugALcGn.js'; import { C as Coord, P as PolarRay, a as PolarRayWithOrigin } from './Types-BQZMHPmi.js'; import { a as TraversableTree } from './Types-DI3Ag868.js'; import { b as Scaler } from './Scaler-BqD8fmOQ.js'; import { R as Rgb8Bit } from './Types-ZQdFqX9n.js'; declare function abs(pt: Point3d): Point3d; declare function abs(pt: Point): Point; /** * Returns the angle in radians between `a` and `b`. * * Eg if `a` is the origin, and `b` is another point, * in degrees one would get 0 to -180 when `b` was above `a`. * -180 would be `b` in line with `a`. * Same for under `a`. * * Providing a third point `c` gives the interior angle, where `b` is the middle point. * * See also {@link angleRadianCircle} which returns coordinates on 0..Math.Pi*2 * range. This avoids negative numbers. * @param a * @param b * @param c * @returns */ declare const angleRadian$1: (a: Point, b?: Point, c?: Point) => number; /** * Returns the angle between point(s) using a radian circle system. * ``` * 90deg * Pi/2 * | * Pi ---+--- 0 * 180 | * 3PI/2 * 270deg * ``` * @param a * @param b * @param c * @returns */ declare const angleRadianCircle: (a: Point, b?: Point, c?: Point) => number; type PointApplyFn = (v: number, field: `x` | `y`) => number; type Point3dApplyFn = (v: number, field: `x` | `y` | `z`) => number; declare function apply$2(pt: Point3d, fn: Point3dApplyFn): Point3d; declare function apply$2(pt: Point, fn: PointApplyFn): Point; type PointAverager = (point: Point) => Point; type PointAverageKinds = `moving-average-light`; /** * Uses {@link Numbers.movingAverageLight} to keep track of * average x, y and z values. * ```js * // Create averager * const averager = Points.averager(`moving-average-light`); * * // Call function with a point to add it to average * // and return the current average. * averager(somePoint); // Yields current average {x,y,z?} * ``` * @param opts Scaling parameter. Higher means more smoothing, lower means less (minimum: 1). Default: 3 * @returns */ declare function averager(kind: `moving-average-light`, opts: Partial<{ scaling: number; }>): PointAverager; /** * Returns the minimum rectangle that can enclose all provided points * @param points * @returns */ declare const bbox$5: (...points: ReadonlyArray<Point>) => RectPositioned; declare const bbox3d: (...points: ReadonlyArray<Point3d>) => Rect3dPositioned; /** * Calculates the [centroid](https://en.wikipedia.org/wiki/Centroid#Of_a_finite_set_of_points) of a set of points * Undefined values are skipped over. * * ```js * // Find centroid of a list of points * const c1 = centroid(p1, p2, p3, ...); * * // Find centroid of an array of points * const c2 = centroid(...pointsArray); * ``` * @param points * @returns A single point */ declare const centroid$1: (...points: ReadonlyArray<Point | undefined>) => Point; declare function clamp(a: Point, min?: number, max?: number): Point; declare function clamp(a: Point3d, min?: number, max?: number): Point3d; /** * Returns -2 if both x & y of a is less than b * Returns -1 if either x/y of a is less than b * * Returns 2 if both x & y of a is greater than b * Returns 1 if either x/y of a is greater than b's x/y * * Returns 0 if x/y of a and b are equal * @param a * @param b * @returns */ declare const compare: (a: Point, b: Point) => number; /** * Compares points based on x value. Y value is ignored. * * Return values: * * 0: If a.x === b.x * * 1: a is to the right of b (ie. a.x > b.x) * * -1: a is to the left of b (ie. a.x < b.x) * * @example Sorting by x * ```js * arrayOfPoints.sort(Points.compareByX); * ``` * * @param a * @param b * @returns */ declare const compareByX: (a: Point, b: Point) => number; /** * Compares points based on Y value. X value is ignored. * Returns values: * * 0: If a.y === b.y * * 1: A is below B (ie. a.y > b.y) * * -1: A is above B (ie. a.y < b.y) * * @example Sorting by Y * ```js * arrayOfPoints.sort(Points.compareByY); * ``` * @param a * @param b * @returns */ declare const compareByY: (a: Point, b: Point) => number; /** * Compares points based on Z value. XY values are ignored. * Returns values: * * 0: If a.z === b.z * * 1: A is below B (ie. a.z > b.z) * * -1: A is above B (ie. a.z < b.z) * * @example Sorting by Y * ```js * arrayOfPoints.sort(Points.compareByZ); * ``` * @param a * @param b * @returns */ declare const compareByZ: (a: Point3d, b: Point3d) => number; /** * Simple convex hull impementation. Returns a set of points which * enclose `pts`. * * For more power, see something like [Hull.js](https://github.com/AndriiHeonia/hull) * @param pts * @returns */ declare const convexHull: (...pts: ReadonlyArray<Point>) => ReadonlyArray<Point>; declare function distance$1(a: Point, b?: Point): number; declare function distance$1(a: Point, x: number, y: number): number; type ShapePositioned = CirclePositioned | RectPositioned; type ContainsResult = `none` | `contained`; type Sphere = Point3d & { readonly radius: number; }; type PointCalculableShape = PolyLine | Line | RectPositioned | Point | CirclePositioned; /** * Returns the intersection result between a and b. * `a` can be a {@link CirclePositioned} or {@link RectPositioned} * `b` can be as above or a {@link Point}. * @param a * @param b */ declare const isIntersecting$2: (a: ShapePositioned, b: ShapePositioned | Point) => boolean; type ShapeRandomPointOpts = { readonly randomSource: RandomSource; }; /** * Returns a random point within a shape. * `shape` can be {@link CirclePositioned} or {@link RectPositioned} * @param shape * @param opts * @returns */ declare const randomPoint$2: (shape: ShapePositioned, opts?: Partial<ShapeRandomPointOpts>) => Point; /** * Returns the center of a shape * Shape can be: rectangle, triangle, circle * @param shape * @returns */ declare const center$2: (shape?: Rect | Triangle | Circle) => Point; /** * Generates a starburst shape, returning an array of points. By default, initial point is top and horizontally-centred. * * ``` * // Generate a starburst with four spikes * const pts = starburst(4, 100, 200); * ``` * * `points` of two produces a lozenge shape. * `points` of three produces a triangle shape. * `points` of five is the familiar 'star' shape. * * Note that the path will need to be closed back to the first point to enclose the shape. * * @example Create starburst and draw it. Note use of 'loop' flag to close the path * ``` * const points = starburst(4, 100, 200); * Drawing.connectedPoints(ctx, pts, {loop: true, fillStyle: `orange`, strokeStyle: `red`}); * ``` * * Options: * * initialAngleRadian: angle offset to begin from. This overrides the `-Math.PI/2` default. * * @param points Number of points in the starburst. Defaults to five, which produces a typical star * @param innerRadius Inner radius. A proportionally smaller inner radius makes for sharper spikes. If unspecified, 50% of the outer radius is used. * @param outerRadius Outer radius. Maximum radius of a spike to origin * @param opts Options * @param origin Origin, or `{ x:0, y:0 }` by default. */ declare const starburst: (outerRadius: number, points?: number, innerRadius?: number, origin?: Point, opts?: { readonly initialAngleRadian?: number; }) => ReadonlyArray<Point>; type ArrowOpts = { readonly arrowSize?: number; readonly tailLength?: number; readonly tailThickness?: number; readonly angleRadian?: number; }; /** * Returns the points forming an arrow. * * @example Create an arrow anchored by its tip at 100,100 * ```js * const opts = { * tailLength: 10, * arrowSize: 20, * tailThickness: 5, * angleRadian: degreeToRadian(45) * } * const arrow = Shapes.arrow({x:100, y:100}, `tip`, opts); // Yields an array of points * * // Eg: draw points * Drawing.connectedPoints(ctx, arrow, {strokeStyle: `red`, loop: true}); * ``` * * @param origin Origin of arrow * @param from Does origin describe the tip, tail or middle? * @param opts Options for arrow * @returns */ declare const arrow: (origin: Point, from: `tip` | `tail` | `middle`, opts?: ArrowOpts) => ReadonlyArray<Point>; type index$d_ArrowOpts = ArrowOpts; type index$d_ContainsResult = ContainsResult; type index$d_PointCalculableShape = PointCalculableShape; type index$d_ShapePositioned = ShapePositioned; type index$d_ShapeRandomPointOpts = ShapeRandomPointOpts; type index$d_Sphere = Sphere; declare const index$d_arrow: typeof arrow; declare const index$d_starburst: typeof starburst; declare namespace index$d { export { type index$d_ArrowOpts as ArrowOpts, type index$d_ContainsResult as ContainsResult, type index$d_PointCalculableShape as PointCalculableShape, type index$d_ShapePositioned as ShapePositioned, type index$d_ShapeRandomPointOpts as ShapeRandomPointOpts, type index$d_Sphere as Sphere, index$d_arrow as arrow, center$2 as center, isIntersecting$2 as isIntersecting, randomPoint$2 as randomPoint, index$d_starburst as starburst }; } /** * Returns the distance from point `a` to the center of `shape`. * @param a Point * @param shape Point, or a positioned Rect or Circle. * @returns */ declare const distanceToCenter: (a: Point, shape: PointCalculableShape) => number; /** * Returns a rotated coordinate * @param c Coordinate * @param amountRadian Amount to rotate, in radians * @returns */ declare const rotate$3: (c: Coord, amountRadian: number) => Coord; /** * Inverts the direction of coordinate. Ie if pointing north, will point south. * @param p * @returns */ declare const invert$1: (p: Coord) => Coord; /** * Returns true if PolarCoords have same magnitude but opposite direction * @param a * @param b * @returns */ declare const isOpposite: (a: Coord, b: Coord) => boolean; /** * Returns true if Coords have the same direction, regardless of magnitude * @param a * @param b * @returns */ declare const isParallel: (a: Coord, b: Coord) => boolean; /** * Returns true if coords are opposite direction, regardless of magnitude * @param a * @param b * @returns */ declare const isAntiParallel: (a: Coord, b: Coord) => boolean; /** * Returns a rotated coordinate * @param c Coordinate * @param amountDeg Amount to rotate, in degrees * @returns */ declare const rotateDegrees: (c: Coord, amountDeg: number) => Coord; /** * Converts to Cartesian coordiantes */ type ToCartesian = { (point: Coord, origin?: Point): Point; (distance: number, angleRadians: number, origin?: Point): Point; }; /** * Converts to Cartesian coordinate from polar. * * ```js * import { Polar } from 'https://unpkg.com/ixfx/dist/geometry.js'; * * const origin = { x: 50, y: 50}; // Polar origin * // Yields: { x, y } * const polar = Polar.toCartesian({ distance: 10, angleRadian: 0 }, origin); * ``` * * Distance and angle can be provided as numbers intead: * * ``` * // Yields: { x, y } * const polar = Polar.toCartesian(10, 0, origin); * ``` * * @param a * @param b * @param c * @returns */ declare const toCartesian$2: ToCartesian; /** * Converts a Cartesian coordinate to polar * * ```js * import { Polar } from 'https://unpkg.com/ixfx/dist/geometry.js'; * * // Yields: { angleRadian, distance } * const polar = Polar.fromCartesian({x: 50, y: 50}, origin); * ``` * * Any additional properties of `point` are copied to object. * @param point Point * @param origin Origin * @returns */ declare const fromCartesian: (point: Point, origin: Point) => Coord; /** * Returns a human-friendly string representation `(distance, angleDeg)`. * If `precision` is supplied, this will be the number of significant digits. * @param p * @returns */ declare const toString$5: (p: Coord, digits?: number) => string; declare const toPoint: (v: Coord, origin?: { readonly x: 0; readonly y: 0; }) => Point; /** * Returns true if `p` seems to be a {@link Polar.Coord} (ie has both distance & angleRadian fields) * @param p * @returns True if `p` seems to be a PolarCoord */ declare const isPolarCoord: (p: unknown) => p is Coord; /** * Throws an error if Coord is invalid * @param p * @param name */ declare const guard$6: (p: Coord, name?: string) => void; declare const normalise$2: (c: Coord) => Coord; /** * Clamps the magnitude of a vector * @param v * @param max * @param min * @returns */ declare const clampMagnitude$2: (v: Coord, max?: number, min?: number) => Coord; /** * Calculate dot product of two PolarCoords. * * Eg, power is the dot product of force and velocity * * Dot products are also useful for comparing similarity of * angle between two unit PolarCoords. * @param a * @param b * @returns */ declare const dotProduct$2: (a: Coord, b: Coord) => number; /** * Multiplies the magnitude of a coord by `amt`. * Direction is unchanged. * @param v * @param amt * @returns */ declare const multiply$5: (v: Coord, amt: number) => Coord; /** * Divides the magnitude of a coord by `amt`. * Direction is unchanged. * @param v * @param amt * @returns */ declare const divide$4: (v: Coord, amt: number) => Coord; /** * Converts a ray to a Line in cartesian coordinates. * * @param ray * @param origin Override or provide origin point * @returns */ declare const toCartesian$1: (ray: PolarRay, origin?: Point) => Line; /** * Returns a copy of `ray` ensuring it has an origin. * If the `origin` parameter is provided, it will override the existing origin. * If no origin information is available, 0,0 is used. * @param ray * @param origin * @returns */ declare const toString$4: (ray: PolarRay) => string; /** * Returns a PolarRay based on a line and origin. * If `origin` is omitted, the origin is taken to be the 'a' point of the line. * @param line * @param origin * @returns */ declare const fromLine: (line: Line, origin?: Point) => PolarRay; declare const Ray_fromLine: typeof fromLine; declare namespace Ray { export { Ray_fromLine as fromLine, toCartesian$1 as toCartesian, toString$4 as toString }; } /** * Produces an Archimedean spiral. It's a generator. * * ```js * const s = spiral(0.1, 1); * for (const coord of s) { * // Use Polar coord... * if (coord.step === 1000) break; // Stop after 1000 iterations * } * ``` * * @param smoothness 0.1 pretty rounded, at around 5 it starts breaking down * @param zoom At smoothness 0.1, zoom starting at 1 is OK */ declare function spiral(smoothness: number, zoom: number): IterableIterator<Coord & { readonly step: number; }>; /** * Produces an Archimedian spiral with manual stepping. * @param step Step number. Typically 0, 1, 2 ... * @param smoothness 0.1 pretty rounded, at around 5 it starts breaking down * @param zoom At smoothness 0.1, zoom starting at 1 is OK * @returns */ declare const spiralRaw: (step: number, smoothness: number, zoom: number) => Coord; declare const index$c_Coord: typeof Coord; declare const index$c_PolarRay: typeof PolarRay; declare const index$c_PolarRayWithOrigin: typeof PolarRayWithOrigin; declare const index$c_Ray: typeof Ray; declare const index$c_fromCartesian: typeof fromCartesian; declare const index$c_isAntiParallel: typeof isAntiParallel; declare const index$c_isOpposite: typeof isOpposite; declare const index$c_isParallel: typeof isParallel; declare const index$c_isPolarCoord: typeof isPolarCoord; declare const index$c_rotateDegrees: typeof rotateDegrees; declare const index$c_spiral: typeof spiral; declare const index$c_spiralRaw: typeof spiralRaw; declare const index$c_toPoint: typeof toPoint; declare namespace index$c { export { index$c_Coord as Coord, index$c_PolarRay as PolarRay, index$c_PolarRayWithOrigin as PolarRayWithOrigin, index$c_Ray as Ray, clampMagnitude$2 as clampMagnitude, divide$4 as divide, dotProduct$2 as dotProduct, index$c_fromCartesian as fromCartesian, guard$6 as guard, invert$1 as invert, index$c_isAntiParallel as isAntiParallel, index$c_isOpposite as isOpposite, index$c_isParallel as isParallel, index$c_isPolarCoord as isPolarCoord, multiply$5 as multiply, normalise$2 as normalise, rotate$3 as rotate, index$c_rotateDegrees as rotateDegrees, index$c_spiral as spiral, index$c_spiralRaw as spiralRaw, toCartesian$2 as toCartesian, index$c_toPoint as toPoint, toString$5 as toString }; } /** * Return the start point of a path * * @param path * @return Point */ declare const getStart: (path: Path) => Point; /** * Return the end point of a path * * @param path * @return Point */ declare const getEnd: (path: Path) => Point; declare const index$b_Dimensions: typeof Dimensions; declare const index$b_Path: typeof Path; declare const index$b_WithBeziers: typeof WithBeziers; declare const index$b_getEnd: typeof getEnd; declare const index$b_getStart: typeof getStart; declare namespace index$b { export { CompoundPath$1 as CompoundPath, index$b_Dimensions as Dimensions, index$b_Path as Path, index$b_WithBeziers as WithBeziers, index$b_getEnd as getEnd, index$b_getStart as getStart }; } type CircularPath = Circle & Path & { readonly kind: `circular`; }; type Vector$1 = Point | Coord; /** * Returns the distance from point `a` to the exterior of `shape`. * * @example Distance from point to rectangle * ``` * const distance = distanceToExterior( * {x: 50, y: 50}, * {x: 100, y: 100, width: 20, height: 20} * ); * ``` * * @example Find closest shape to point * ``` * import {minIndex} from '../data/arrays.js'; * const shapes = [ some shapes... ]; // Shapes to compare against * const pt = { x: 10, y: 10 }; // Comparison point * const distances = shapes.map(v => distanceToExterior(pt, v)); * const closest = shapes[minIndex(...distances)]; * ``` * @param a Point * @param shape Point, or a positioned Rect or Circle. * @returns */ declare const distanceToExterior: (a: Point, shape: PointCalculableShape) => number; declare function divide$3(a: Point, b: Point): Point; declare function divide$3(a: Point3d, b: Point3d): Point3d; declare function divide$3(a: Point, x: number, y: number): Point; declare function divide$3(a: Point3d, x: number, y: number, z: number): Point3d; declare function divide$3(ax: number, ay: number, bx: number, by: number): Point; declare function divide$3(ax: number, ay: number, az: number, bx: number, by: number, bz: number): Point3d; /** * Returns a function that divides a point: * ```js * const f = divider(100, 200); * f(50,100); // Yields: { x: 0.5, y: 0.5 } * ``` * * Input values can be Point, separate x,y and optional z values or an array: * ```js * const f = divider({ x: 100, y: 100 }); * const f = divider( 100, 100 ); * const f = divider([ 100, 100 ]); * ``` * * Likewise the returned function an take these as inputs: * ```js * f({ x: 100, y: 100}); * f( 100, 100 ); * f([ 100, 100 ]); * ``` * * Function throws if divisor has 0 for any coordinate (since we can't divide by 0) * @param a Divisor point, array of points or x * @param b Divisor y value * @param c Divisor z value * @returns */ declare function divider(a: Point3d | Point | number | Array<number>, b?: number, c?: number): (aa: Point3d | Point | number | Array<number>, bb?: number, cc?: number) => Point; declare const dotProduct$1: (...pts: ReadonlyArray<Point>) => number; /** * An empty point of `{ x: 0, y: 0 }`. * * Use `isEmpty` to check if a point is empty. * Use `Empty3d` to get an empty point with `z`. */ declare const Empty$3: { readonly x: 0; readonly y: 0; }; /** * Returns { x:1, y:1 } */ declare const Unit: { readonly x: 1; readonly y: 1; }; /** * An empty Point of `{ x: 0, y: 0, z: 0}` * Use `isEmpty` to check if a point is empty. * Use `Empty` to get an empty point without `z`. */ declare const Empty3d: { readonly x: 0; readonly y: 0; readonly z: 0; }; /** * Returns { x:1,y:1,z:1 } */ declare const Unit3d: { readonly x: 1; readonly y: 1; readonly z: 1; }; declare function findMinimum(comparer: (a: Point, b: Point) => Point, ...points: ReadonlyArray<Point>): Point; declare function findMinimum(comparer: (a: Point3d, b: Point3d) => Point3d, ...points: ReadonlyArray<Point3d>): Point3d; declare function from(x: number, y: number, z: number): Point3d; declare function from(x: number, y: number): Point; declare function from(arr: [x: number, y: number, z: number]): Point3d; declare function from(arr: [x: number, y: number]): Point; /** * Parses a point as a string, in the form 'x,y' or 'x,y,z'. * eg '10,15' will be returned as `{ x: 10, y: 15 }`. * * Throws an error if `str` is not a string. * * ```js * Points.fromString(`10,15`); // { x:10, y:15 } * Points.fromString(`a,10`); // { x:NaN, y:10 } * ``` * * Use {@link Points.isNaN} to check if returned point has NaN for either coordinate. * @param str */ declare const fromString: (str: string) => Point; /** * Returns an array of points from an array of numbers. * * Array can be a continuous series of x, y values: * ``` * [1,2,3,4] would yield: [{x:1, y:2}, {x:3, y:4}] * ``` * * Or it can be an array of arrays: * ``` * [[1,2], [3,4]] would yield: [{x:1, y:2}, {x:3, y:4}] * ``` * @param coords * @returns */ declare const fromNumbers$2: (...coords: ReadonlyArray<ReadonlyArray<number>> | ReadonlyArray<number>) => ReadonlyArray<Point>; declare function getTwoPointParameters(a: Point, b: Point): [a: Point, b: Point]; declare function getTwoPointParameters(a: Point3d, b: Point3d): [a: Point3d, b: Point3d]; declare function getTwoPointParameters(a: Point, x: number, y: number): [a: Point, b: Point]; declare function getTwoPointParameters(a: Point3d, x: number, y: number, z: number): [a: Point3d, b: Point3d]; declare function getTwoPointParameters(ax: number, ay: number, bx: number, by: number): [a: Point, b: Point]; declare function getTwoPointParameters(ax: number, ay: number, az: number, bx: number, by: number, bz: number): [a: Point3d, b: Point3d]; /** * Returns a Point form of either a point, x,y params or x,y,z params. * If parameters are undefined, an empty point is returned (0, 0) * @ignore * @param a * @param b * @returns */ declare function getPointParameter$1(a?: Point3d | Point | number | Array<number> | ReadonlyArray<number>, b?: number | boolean, c?: number): Point | Point3d; /** * Returns true if xy (and z, if present) are _null_. * @param p * @returns */ declare const isNull: (p: Point) => boolean; /*** * Returns true if either x, y, z isNaN. */ declare const isNaN$1: (p: Point) => boolean; /** * Throws an error if point is invalid * @param p * @param name */ declare function guard$5(p: Point, name?: string): void; /** * Throws if parameter is not a valid point, or either x or y is 0 * @param pt * @returns */ declare const guardNonZeroPoint: (pt: Point | Point3d, name?: string) => boolean; /** * Returns _true_ if `p` has x & y properties. * Returns _false_ if `p` is undefined, null or does not contain properties. * Use {@link isPoint3d} to check further check for `z`. * @param p * @returns */ declare function isPoint(p: number | unknown): p is Point; /** * Returns _true_ if `p` has x, y, & z properties. * Returns _false_ if `p` is undefined, null or does not contain properties. * @param p * @returns */ declare const isPoint3d: (p: Point | unknown) => p is Point3d; /** * Returns true if both xy (and z, if present) are 0. * Use `Points.Empty` to return an empty point. * @param p * @returns */ declare const isEmpty$3: (p: Point) => boolean; /** * Returns true if point is a placeholder, where xy (and z, if present) * are `NaN`. * * Use Points.Placeholder to return a placeholder point. * @param p * @returns */ declare const isPlaceholder$3: (p: Point) => boolean; /** * Returns a relative point between two points * ```js * interpolate(0.5, a, b); // Halfway point between a and b * ``` * * Alias for Lines.interpolate(amount, a, b); * * @param amount Relative amount, 0-1 * @param a * @param b * @param allowOverflow If true, length of line can be exceeded for `amount` of below 0 and above `1`. * @returns {@link Point} */ declare const interpolate$4: (amount: number, a: Point, b: Point, allowOverflow?: boolean) => Point; /** * Inverts one or more axis of a point * ```js * invert({x:10, y:10}); // Yields: {x:-10, y:-10} * invert({x:10, y:10}, `x`); // Yields: {x:-10, y:10} * ``` * @param pt Point to invert * @param what Which axis. If unspecified, both axies are inverted * @returns */ declare const invert: (pt: Point | Point3d, what?: `both` | `x` | `y` | `z`) => Point; /** * Returns _true_ if the points have identical values * * ```js * const a = {x: 10, y: 10}; * const b = {x: 10, y: 10;}; * a === b // False, because a and be are different objects * isEqual(a, b) // True, because a and b are same value * ``` * @param p Points * @returns _True_ if points are equal */ declare const isEqual$6: (...p: ReadonlyArray<Point>) => boolean; /** * Clamps the magnitude of a point. * This is useful when using a Point as a vector, to limit forces. * @param pt * @param max Maximum magnitude (1 by default) * @param min Minimum magnitude (0 by default) * @returns */ declare const clampMagnitude$1: (pt: Point, max?: number, min?: number) => Point; /** * Returns the left-most of the provided points. * * Same as: * ```js * findMinimum((a, b) => { * if (a.x <= b.x) return a; * return b; *}, ...points) * ``` * * @param points * @returns */ declare const leftmost: (...points: ReadonlyArray<Point>) => Point; /** * Returns the right-most of the provided points. * * Same as: * ```js * findMinimum((a, b) => { * if (a.x >= b.x) return a; * return b; *}, ...points) * ``` * * @param points * @returns */ declare const rightmost: (...points: ReadonlyArray<Point>) => Point; declare function multiply$4(a: Point, b: Point): Point; declare function multiply$4(a: Point3d, b: Point3d): Point3d; declare function multiply$4(a: Point, x: number, y: number): Point; declare function multiply$4(a: Point3d, x: number, y: number, z: number): Point3d; declare function multiply$4(ax: number, ay: number, bx: number, by: number): Point; declare function multiply$4(ax: number, ay: number, az: number, bx: number, by: number, bz: number): Point3d; /** * Multiplies all components by `v`. * Existing properties of `pt` are maintained. * * ```js * multiplyScalar({ x:2, y:4 }, 2); * // Yields: { x:4, y:8 } * ``` * @param pt Point * @param v Value to multiply by * @returns */ declare const multiplyScalar$2: (pt: Point | Point3d, v: number) => Point | Point3d; /** * Normalise point as a unit vector. * * ```js * normalise({x:10, y:20}); * normalise(10, 20); * ``` * @param ptOrX Point, or x value * @param y y value if first param is x * @returns */ declare const normalise$1: (ptOrX: Point | number, y?: number) => Point; /** * Normalises a point by a given width and height * @param point Point * @param width Width * @param height Height */ declare function normaliseByRect$1(point: Point, width: number, height: number): Point; /** * Normalises a point by a given rect's width and height * @param pt * @param rect */ declare function normaliseByRect$1(pt: Point, rect: Rect): Point; /** * Normalises x,y by width and height so it is on a 0..1 scale * @param x * @param y * @param width * @param height */ declare function normaliseByRect$1(x: number, y: number, width: number, height: number): Point; /** * Runs a sequential series of functions on `pt`. The output from one feeding into the next. * ```js * const p = Points.pipelineApply(somePoint, Points.normalise, Points.invert); * ``` * * If you want to make a reusable pipeline of functions, consider {@link pipeline} instead. * @param point * @param pipelineFns * @returns */ declare const pipelineApply: (point: Point, ...pipelineFns: ReadonlyArray<(pt: Point) => Point>) => Point; /** * Returns a pipeline function that takes a point to be transformed through a series of functions * ```js * // Create pipeline * const p = Points.pipeline(Points.normalise, Points.invert); * * // Now run it on `somePoint`. * // First we normalised, and then invert * const changedPoint = p(somePoint); * ``` * * If you don't want to create a pipeline, use {@link pipelineApply}. * @param pipeline Pipeline of functions * @returns */ declare const pipeline: (...pipeline: ReadonlyArray<(pt: Point) => Point>) => (pt: Point) => Point; /** * Computes the progress between two waypoints, given `position`. * * [Source](https://www.habrador.com/tutorials/math/2-passed-waypoint/?s=09) * @param position Current position * @param waypointA Start * @param waypointB End * @returns */ declare const progressBetween: (position: Point | Point3d, waypointA: Point | Point3d, waypointB: Point | Point3d) => number; /** * Project `origin` by `distance` and `angle` (radians). * * To figure out rotation, imagine a horizontal line running through `origin`. * * Rotation = 0 deg puts the point on the right of origin, on same y-axis * * Rotation = 90 deg/3:00 puts the point below origin, on the same x-axis * * Rotation = 180 deg/6:00 puts the point on the left of origin on the same y-axis * * Rotation = 270 deg/12:00 puts the point above the origin, on the same x-axis * * ```js * // Yields a point 100 units away from 10,20 with 10 degrees rotation (ie slightly down) * const a = Points.project({x:10, y:20}, 100, degreeToRadian(10)); * ``` * @param origin * @param distance * @param angle * @returns */ declare const project: (origin: Point, distance: number, angle: number) => { x: number; y: number; }; declare function quantiseEvery(pt: Point3d, snap: Point3d, middleRoundsUp?: boolean): Point3d; declare function quantiseEvery(pt: Point, snap: Point, middleRoundsUp?: boolean): Point; /** * Returns a random 2D point on a 0..1 scale. * ```js * import { Points } from "https://unpkg.com/ixfx/dist/geometry.js"; * const pt = Points.random(); // eg {x: 0.2549012, y:0.859301} * ``` * * A custom source of randomness can be provided: * ```js * import { Points } from "https://unpkg.com/ixfx/dist/geometry.js"; * import { weightedSource } from "https://unpkg.com/ixfx/dist/random.js" * const pt = Points.random(weightedSource(`quadIn`)); * ``` * @param rando * @returns */ declare const random$2: (rando?: RandomSource) => Point; /** * Returns a random 3D point on a 0..1 scale. * ```js * import { Points } from "https://unpkg.com/ixfx/dist/geometry.js"; * const pt = Points.random(); // eg {x: 0.2549012, y:0.859301} * ``` * * A custom source of randomness can be provided: * ```js * import { Points } from "https://unpkg.com/ixfx/dist/geometry.js"; * import { weightedSource } from "https://unpkg.com/ixfx/dist/random.js" * const pt = Points.random(weightedSource(`quadIn`)); * ``` * @param rando * @returns */ declare const random3d: (rando?: RandomSource) => Point3d; /** * Reduces over points, treating _x_ and _y_ separately. * * ``` * // Sum x and y values * const total = Points.reduce(points, (p, acc) => { * return {x: p.x + acc.x, y: p.y + acc.y} * }); * ``` * @param pts Points to reduce * @param fn Reducer * @param initial Initial value, uses `{ x:0, y:0 }` by default * @returns */ declare const reduce: (pts: ReadonlyArray<Point>, fn: (p: Point, accumulated: Point) => Point, initial?: Point) => Point; /** * Tracks the relation between two points. * * 1. Call `Points.relation` with the initial reference point * 2. You get back a function * 3. Call the function with a new point to compute relational information. * * It computes angle, average, centroid, distance and speed. * * ```js * import { Points } from "https://unpkg.com/ixfx/dist/geometry.js"; * * // Reference point: 50,50 * const t = Points.relation({x:50,y:50}); // t is a function * * // Invoke the returned function with a point * const relation = t({ x:0, y:0 }); // Juicy relational data * ``` * * Or with destructuring: * * ```js * const { angle, distanceFromStart, distanceFromLast, average, centroid, speed } = t({ x:0,y:0 }); * ``` * * x & y coordinates can also be used as parameters: * ```js * const t = Points.relation(50, 50); * const result = t(0, 0); * // result.speed, result.angle ... * ``` * * Note that intermediate values are not stored. It keeps the initial * and most-recent point. If you want to compute something over a set * of prior points, you may want to use {@link Trackers.points} * @param a Initial point, or x value * @param b y value, if first option is a number. * @returns */ declare const relation: (a: Point | number, b?: number) => PointRelation; /** * Rotate a single point by a given amount in radians * @param pt * @param amountRadian * @param origin */ declare function rotate$2(pt: Point, amountRadian: number, origin?: Point): Point; /** * Rotate several points by a given amount in radians * @param pt Points * @param amountRadian Amount to rotate in radians. If 0 is given, a copy of the input array is returned * @param origin Origin to rotate around. Defaults to 0,0 */ declare function rotate$2(pt: ReadonlyArray<Point>, amountRadian: number, origin?: Point): ReadonlyArray<Point>; declare const rotatePointArray: (v: ReadonlyArray<ReadonlyArray<number>>, amountRadian: number) => Array<Array<number>>; /** * Round the point's _x_ and _y_ to given number of digits * @param ptOrX * @param yOrDigits * @param digits * @returns */ declare const round: (ptOrX: Point | number, yOrDigits?: number, digits?: number) => Point; declare function subtract$3(a: Point, b: Point): Point; declare function subtract$3(a: Point3d, b: Point3d): Point3d; declare function subtract$3(a: Point, x: number, y: number): Point; declare function subtract$3(a: Point3d, x: number, y: number, z: number): Point3d; declare function subtract$3(ax: number, ay: number, bx: number, by: number): Point; declare function subtract$3(ax: number, ay: number, az: number, bx: number, by: number, bz: number): Point3d; declare function sum$3(a: Point, b: Point): Point; declare function sum$3(a: Point3d, b: Point3d): Point3d; declare function sum$3(a: Point, x: number, y: number): Point; declare function sum$3(a: Point3d, x: number, y: number, z: number): Point3d; declare function sum$3(ax: number, ay: number, bx: number, by: number): Point; declare function sum$3(ax: number, ay: number, az: number, bx: number, by: number, bz: number): Point3d; /** * Returns a point with rounded x,y coordinates. By default uses `Math.round` to round. * ```js * toIntegerValues({x:1.234, y:5.567}); // Yields: {x:1, y:6} * ``` * * ```js * toIntegerValues(pt, Math.ceil); // Use Math.ceil to round x,y of `pt`. * ``` * @param pt Point to round * @param rounder Rounding function, or Math.round by default * @returns */ declare const toIntegerValues: (pt: Point, rounder?: (x: number) => number) => Point; /** * Returns a copy of `pt` with `z` field omitted. * If it didn't have one to begin within, a copy is still returned. * @param pt * @returns */ declare const to2d: (pt: Point) => Point; /** * Returns a copy of `pt` with a `z` field set. * Defaults to a z value of 0. * @param pt Point * @param z Z-value, defaults to 0 * @returns */ declare const to3d: (pt: Point, z?: number) => Point3d; /** * Returns a human-friendly string representation `(x, y)`. * If `precision` is supplied, this will be the number of significant digits. * @param p * @returns */ declare function toString$3(p: Point, digits?: number): string; /** * Returns point as an array in the form [x,y]. This can be useful for some libraries * that expect points in array form. * * ``` * const p = {x: 10, y:5}; * const p2 = toArray(p); // yields [10,5] * ``` * @param p * @returns */ declare const toArray$1: (p: Point) => ReadonlyArray<number>; /** * Returns true if two points are within a specified range on both axes. * * Provide a point for the range to set different x/y range, or pass a number * to use the same range for both axis. * * Note this simply compares x,y values it does not calcuate distance. * * @example * ```js * withinRange({x:100,y:100}, {x:101, y:101}, 1); // True * withinRange({x:100,y:100}, {x:105, y:101}, {x:5, y:1}); // True * withinRange({x:100,y:100}, {x:105, y:105}, {x:5, y:1}); // False - y axis too far * ``` * @param a * @param b * @param maxRange * @returns */ declare const withinRange$1: (a: Point, b: Point, maxRange: Point | number) => boolean; /** * Wraps a point to be within `ptMin` and `ptMax`. * Note that max values are _exclusive_, meaning the return value will always be one less. * * Eg, if a view port is 100x100 pixels, wrapping the point 150,100 yields 50,99. * * ```js * // Wraps 150,100 to on 0,0 -100,100 range * wrap({x:150,y:100}, {x:100,y:100}); * ``` * * Wrap normalised point: * ```js * wrap({x:1.2, y:1.5}); // Yields: {x:0.2, y:0.5} * ``` * @param pt Point to wrap * @param ptMax Maximum value, or `{ x:1, y:1 }` by default * @param ptMin Minimum value, or `{ x:0, y:0 }` by default * @returns Wrapped point */ declare const wrap$2: (pt: Point, ptMax?: Point, ptMin?: Point) => Point; declare const index$a_Empty3d: typeof Empty3d; declare const index$a_Placeholder3d: typeof Placeholder3d; declare const index$a_Point: typeof Point; declare const index$a_Point3d: typeof Point3d; type index$a_Point3dApplyFn = Point3dApplyFn; type index$a_PointApplyFn = PointApplyFn; type index$a_PointAverageKinds = PointAverageKinds; type index$a_PointAverager = PointAverager; declare const index$a_PointRelation: typeof PointRelation; declare const index$a_PointRelationResult: typeof PointRelationResult; declare const index$a_Unit: typeof Unit; declare const index$a_Unit3d: typeof Unit3d; declare const index$a_abs: typeof abs; declare const index$a_angleRadianCircle: typeof angleRadianCircle; declare const index$a_averager: typeof averager; declare const index$a_bbox3d: typeof bbox3d; declare const index$a_clamp: typeof clamp; declare const index$a_compare: typeof compare; declare const index$a_compareByX: typeof compareByX; declare const index$a_compareByY: typeof compareByY; declare const index$a_compareByZ: typeof compareByZ; declare const index$a_convexHull: typeof convexHull; declare const index$a_distanceToCenter: typeof distanceToCenter; declare const index$a_distanceToExterior: typeof distanceToExterior; declare const index$a_divider: typeof divider; declare const index$a_findMinimum: typeof findMinimum; declare const index$a_from: typeof from; declare const index$a_fromString: typeof fromString; declare const index$a_getTwoPointParameters: typeof getTwoPointParameters; declare const index$a_guardNonZeroPoint: typeof guardNonZeroPoint; declare const index$a_invert: typeof invert; declare const index$a_isNull: typeof isNull; declare const index$a_isPoint: typeof isPoint; declare const index$a_isPoint3d: typeof isPoint3d; declare const index$a_leftmost: typeof leftmost; declare const index$a_pipeline: typeof pipeline; declare const index$a_pipelineApply: typeof pipelineApply; declare const index$a_progressBetween: typeof progressBetween; declare const index$a_project: typeof project; declare const index$a_quantiseEvery: typeof quantiseEvery; declare const index$a_random3d: typeof random3d; declare const index$a_reduce: typeof reduce; declare const index$a_relation: typeof relation; declare const index$a_rightmost: typeof rightmost; declare const index$a_rotatePointArray: typeof rotatePointArray; declare const index$a_round: typeof round; declare const index$a_to2d: typeof to2d; declare const index$a_to3d: typeof to3d; declare const index$a_toIntegerValues: typeof toIntegerValues; declare namespace index$a { export { Empty$3 as Empty, index$a_Empty3d as Empty3d, Placeholder$3 as Placeholder, index$a_Placeholder3d as Placeholder3d, index$a_Point as Point, index$a_Point3d as Point3d, type index$a_Point3dApplyFn as Point3dApplyFn, type index$a_PointApplyFn as PointApplyFn, type index$a_PointAverageKinds as PointAverageKinds, type index$a_PointAverager as PointAverager, index$a_PointRelation as PointRelation, index$a_PointRelationResult as PointRelationResult, index$a_Unit as Unit, index$a_Unit3d as Unit3d, index$a_abs as abs, angleRadian$1 as angleRadian, index$a_angleRadianCircle as angleRadianCircle, apply$2 as apply, index$a_averager as averager, bbox$5 as bbox, index$a_bbox3d as bbox3d, centroid$1 as centroid, index$a_clamp as clamp, clampMagnitude$1 as clampMagnitude, index$a_compare as compare, index$a_compareByX as compareByX, index$a_compareByY as compareByY, index$a_compareByZ as compareByZ, index$a_convexHull as convexHull, distance$1 as distance, index$a_distanceToCenter as distanceToCenter, index$a_distanceToExterior as distanceToExterior, divide$3 as divide, index$a_divider as divider, dotProduct$1 as dotProduct, index$a_findMinimum as findMinimum, index$a_from as from, fromNumbers$2 as fromNumbers, index$a_fromString as fromString, getPointParameter$1 as getPointParameter, index$a_getTwoPointParameters as getTwoPointParameters, guard$5 as guard, index$a_guardNonZeroPoint as guardNonZeroPoint, interpolate$4 as interpolate, index$a_invert as invert, isEmpty$3 as isEmpty, isEqual$6 as isEqual, isNaN$1 as isNaN, index$a_isNull as isNull, isPlaceholder$3 as isPlaceholder, index$a_isPoint as isPoint, index$a_isPoint3d as isPoint3d, index$a_leftmost as leftmost, multiply$4 as multiply, multiplyScalar$2 as multiplyScalar, normalise$1 as normalise, normaliseByRect$1 as normaliseByRect, index$a_pipeline as pipeline, index$a_pipelineApply as pipelineApply, index$a_progressBetween as progressBetween, index$a_project as project, index$a_quantiseEvery as quantiseEvery, random$2 as random, index$a_random3d as random3d, index$a_reduce as reduce, index$a_relation as relation, index$a_rightmost as rightmost, rotate$2 as rotate, index$a_rotatePointArray as rotatePointArray, index$a_round as round, subtract$3 as subtract, sum$3 as sum, index$a_to2d as to2d, index$a_to3d as to3d, toArray$1 as toArray, index$a_toIntegerValues as toIntegerValues, toString$3 as toString, withinRange$1 as withinRange, wrap$2 as wrap }; } type Waypoint = CirclePositioned; type WaypointOpts = { readonly maxDistanceFromLine: number; readonly enforceOrder: boolean; }; /** * Create from set of points, connected in order starting at array position 0. * @param waypoints * @param opts * @returns */ declare const fromPoints$2: (waypoints: ReadonlyArray<Point>, opts?: Partial<WaypointOpts>) => Waypoints; /** * Result */ type WaypointResult = { /** * Path being compared against */ path: Path; /** * Index of this path in original `paths` array */ index: number; /** * Nearest point on path. See also {@link distance} */ nearest: Point; /** * Closest distance to path. See also {@link nearest} */ distance: number; /** * Rank of this result, 0 being highest. */ rank: number; /** * Relative position on this path segment * 0 being start, 0.5 middle and so on. */ positionRelative: number; }; /** * Given point `pt`, returns a list of {@link WaypointResult}, comparing * this point to a set of paths. * ```js * // Init once with a set of paths * const w = init(paths); * // Now call with a point to get results * const results = w({ x: 10, y: 20 }); * ``` */ type Waypoints = (pt: Point) => Array<WaypointResult>; /** * Initialise * * Options: * * maxDistanceFromLine: Distances greater than this are not matched. Default 0.1 * @param paths * @param opts * @returns */ declare const init: (paths: ReadonlyArray<Path>, opts?: Partial<WaypointOpts>) => Waypoints; type Waypoint$1_Waypoint = Waypoint; type Waypoint$1_WaypointOpts = WaypointOpts; type Waypoint$1_WaypointResult = WaypointResult; type Waypoint$1_Waypoints = Waypoints; declare const Waypoint$1_init: typeof init; declare namespace Waypoint$1 { export { type Waypoint$1_Waypoint as Waypoint, type Waypoint$1_WaypointOpts as WaypointOpts, type Waypoint$1_WaypointResult as WaypointResult, type Waypoint$1_Waypoints as Waypoints, fromPoints$2 as fromPoints, Waypoint$1_init as init }; } type RandomOpts = { readonly attempts?: number; readonly randomSource?: RandomSource; }; /** * Naive randomised circle packing. * [Algorithm by Taylor Hobbs](https://tylerxhobbs.com/essays/2016/a-randomized-approach-to-cicle-packing) */ declare const random$1: (circles: ReadonlyArray<Circle>, container: ShapePositioned, opts?: RandomOpts) => CirclePositioned[]; type CirclePacking_RandomOpts = RandomOpts; declare namespace CirclePacking { export { type CirclePacking_RandomOpts as RandomOpts, random$1 as random }; } declare const Layout_CirclePacking: typeof CirclePacking; declare namespace Layout { export { Layout_CirclePacking as CirclePacking }; } /** * Returns the area of `circle`. * @param circle * @returns */ declare const area$5: (circle: Circle) => number; /** * Computes a bounding box that encloses circle * @param circle * @returns */ declare const bbox$4: (circle: CirclePositioned | Circle) => RectPositioned; /** * Returns the center of a circle * * If the circle has an x,y, that is the center. * If not, `radius` is used as the x and y. * * ```js * import { Circles } from "https://unpkg.com/ixfx/dist/geometry.js" * const circle = { radius: 5, x: 10, y: 10}; * * // Yields: { x: 5, y: 10 } * Circles.center(circle); * ``` * * It's a trivial function, but can make for more understandable code * @param circle * @returns Center of circle */ declare const center$1: (circle: CirclePositioned | Circle) => Readonly<{ x: number; y: number; }>; /** * Returns the distance between two circle centers. * * ```js * import { Circles } from "https://unpkg.com/ixfx/dist/geometry.js" * const circleA = { radius: 5, x: 5, y: 5 } * const circleB = { radius: 10, x: 20, y: 20 } * const distance = Circles.distanceCenter(circleA, circleB); * ``` * Throws an error if either is lacking position. * @param a * @param b * @returns Distance */ declare const distanceCenter$1: (a: CirclePositioned, b: CirclePositioned | Point) => number; /** * Returns the distance between the exterior of two circles, or between the exterior of a circle and point. * If `b` overlaps or is enclosed by `a`, distance is 0. * * ```js * import { Circles } from "https://unpkg.com/ixfx/dist/geometry.js" * const circleA = { radius: 5, x: 5, y: 5 } * const circleB = { radius: 10, x: 20, y: 20 } * const distance = Circles.distanceCenter(circleA, circleB); * ``` * @param a * @param b */ declare const distanceFromExterior$1: (a: CirclePositioned, b: CirclePositioned | Point) => number; /** * Yields the points making up the exterior (ie. circumference) of the circle. * Uses [Midpoint Circle Algorithm](http://en.wikipedia.org/wiki/Midpoint_circle_algorithm) * * @example Draw outline of circle * ```js * const circle = { x: 100, y: 100, radius: 50 } * for (const pt of Circles.exteriorIntegerPoints(circle)) { * // Fill 1x1 pixel * ctx.fillRect(pt.x, pt.y, 1, 1); * } * ``` * @param circle */ declare function exteriorIntegerPoints(circle: CirclePositioned): IterableIterator<Point>; /** * Throws if radius is out of range. If x,y is present, these will be validated too. * @param circle * @param parameterName */ declare const guard$4: (circle: CirclePositioned | Circle, parameterName?: string) => void; /** * Throws if `circle` is not positioned or has dodgy fields * @param circle * @param parameterName * @returns */ declare const guardPositioned$1: (circle: CirclePositioned, parameterName?: string) => void; /*** * Returns true if radius, x or y are NaN */ declare const isNaN: (a: Circle | CirclePositioned) => boolean; /** * Returns true if parameter has x,y. Does not verify if parameter is a circle or not * * ```js * import { Circles } from "https://unpkg.com/ixfx/dist/geometry.js" * * const circleA = { radius: 5 }; * Circles.isPositioned(circle); // false * * const circleB = { radius: 5, x: 10, y: 10 } * Circles.isPositioned(circle); // true * ``` * @param p Circle * @returns */ declare const isPositioned$2: (p: Circle | Point) => p is Point; declare const isCircle: (p: any) => p is Circle; declare const isCirclePositioned: (p: any) => p is CirclePositioned; /** * Returns all integer points contained within `circl