import { type Maybe } from '../value/maybe.type'; import { type Rectangle } from './vector'; import { type LatLngPoint, type LatLngPointInput, type LatLngPrecision, type LatLngPointFunction } from './point'; import { type DecisionFunction } from './decision'; import { type ArrayOrValue } from '../array'; /** * Alias for the south-west corner point of a {@link LatLngBound}. */ export type LatLngBoundSouthWestPoint = LatLngPoint; /** * Alias for the north-east corner point of a {@link LatLngBound}. */ export type LatLngBoundNothEastPoint = LatLngPoint; /** * A geographic bounding box defined by its south-west and north-east corner points. * * Used throughout the library for spatial queries, overlap detection, and map viewport calculations. */ export interface LatLngBound { sw: LatLngBoundSouthWestPoint; ne: LatLngBoundNothEastPoint; } /** * A value that is either a {@link LatLngBound} or a {@link LatLngPoint}. */ export type LatLngBoundOrPoint = LatLngBound | LatLngPoint; /** * Type guard that checks whether the input is a {@link LatLngBound} by testing for the presence of `sw` and `ne` properties. * * @param input - Value to test. * @returns `true` if the input has `sw` and `ne` properties, indicating a bound. */ export declare function isLatLngBound(input: LatLngBound | unknown): input is LatLngBound; /** * Creates a deep copy of the bound so that mutations to the copy do not affect the original. * * @param input - Bound to copy. * @returns A new bound with copied corner points. */ export declare function copyLatLngBound(input: LatLngBound): LatLngBound; /** * Checks whether two bounds are identical by comparing both corner points. * * @param a - First bound. * @param b - Second bound. * @returns `true` if both the `sw` and `ne` corners are the same. */ export declare function isSameLatLngBound(a: LatLngBound, b: LatLngBound): boolean; /** * Computes the difference between the `ne` and `sw` corner points of a bound, giving the span in latitude and longitude. * * @param bounds - Bound to measure. * @param wrap - Whether to wrap the difference across the antimeridian. * @returns A point whose `lat`/`lng` represent the span of the bound. */ export declare function diffLatLngBoundPoints(bounds: LatLngBound, wrap?: boolean): LatLngPoint; /** * Returns true if the input LatLngBound either strictly wraps the map or fully wraps the map. * * A bound "wraps" when it crosses the antimeridian (longitude +/-180), requiring special handling * for containment and overlap checks. * * @param bound - Bound to check. * @returns `true` if the bound wraps the map in either sense. */ export declare function latLngBoundWrapsMap(bound: LatLngBound): boolean; /** * Returns true if the input LatLngBound's sw corner comes after the ne corner longitudinally, * indicating the bound crosses the antimeridian. * * @param bound - Bound to check. * @returns `true` if the sw longitude is greater than the ne longitude. */ export declare function latLngBoundStrictlyWrapsMap(bound: LatLngBound): boolean; /** * Returns true if the LatLngBound's longitudinal span exceeds the total longitude range (360 degrees), * meaning the bound covers the entire map horizontally. * * @param bound - Bound to check. * @returns `true` if the absolute longitude difference exceeds the total longitude range. */ export declare function latLngBoundFullyWrapsMap(bound: LatLngBound): boolean; /** * Returns the north-east corner point of the bound. * * @param bound - Bound to read. * @returns The `ne` corner point. */ export declare function latLngBoundNorthEastPoint(bound: LatLngBound): LatLngPoint; /** * Derives the north-west corner point from the bound's `ne` latitude and `sw` longitude. * * @param bound - Bound to read. * @returns The computed north-west corner point. */ export declare function latLngBoundNorthWestPoint(bound: LatLngBound): LatLngPoint; /** * Derives the south-east corner point from the bound's `sw` latitude and `ne` longitude. * * @param bound - Bound to read. * @returns The computed south-east corner point. */ export declare function latLngBoundSouthEastPoint(bound: LatLngBound): LatLngPoint; /** * Returns the south-west corner point of the bound. * * @param bound - Bound to read. * @returns The `sw` corner point. */ export declare function latLngBoundSouthWestPoint(bound: LatLngBound): LatLngPoint; /** * Computes the geographic center of the bound by averaging the corner coordinates. * * @param bound - Bound to compute the center of. * @returns The center point. * * @example * ```ts * const bound = latLngBound({ lat: 0, lng: 0 }, { lat: 40, lng: 40 }); * const center = latLngBoundCenterPoint(bound); * // center.lat === 20, center.lng === 20 * ``` */ export declare function latLngBoundCenterPoint(bound: LatLngBound): LatLngPoint; /** * Returns the northern latitude boundary (the `ne` latitude). * * @param bound - Bound to read. * @returns The latitude of the north edge. */ export declare function latLngBoundNorthBound(bound: LatLngBound): number; /** * Returns the southern latitude boundary (the `sw` latitude). * * @param bound - Bound to read. * @returns The latitude of the south edge. */ export declare function latLngBoundSouthBound(bound: LatLngBound): number; /** * Returns the eastern longitude boundary (the `ne` longitude). * * @param bound - Bound to read. * @returns The longitude of the east edge. */ export declare function latLngBoundEastBound(bound: LatLngBound): number; /** * Returns the western longitude boundary (the `sw` longitude). * * @param bound - Bound to read. * @returns The longitude of the west edge. */ export declare function latLngBoundWestBound(bound: LatLngBound): number; /** * Tuple of the sw corner and the north east point. */ export type LatLngBoundTuple = [LatLngBoundSouthWestPoint | LatLngPointInput, LatLngBoundNothEastPoint | LatLngPointInput]; /** * Tuple of four points that define the corners of a bounding box, from which the min/max extents are derived. */ export type LatLngBoundTuplePoints = [LatLngPointInput, LatLngPointInput, LatLngPointInput, LatLngPointInput]; /** * Accepted input types for creating a {@link LatLngBound}: a bound object, a 2-element tuple (sw/ne), or a 4-element tuple of corner points. */ export type LatLngBoundInput = LatLngBound | LatLngBoundTuple | LatLngBoundTuplePoints; /** * Convenience function that creates a {@link LatLngBoundTuple} using the default configuration. * * @param input - A sw point or any bound input. * @param inputNe - Optional ne point when providing two separate points. * @returns A tuple of `[sw, ne]` points. */ export declare function latLngBoundTuple(input: LatLngBoundSouthWestPoint | LatLngBoundInput, inputNe?: LatLngBoundNothEastPoint): LatLngBoundTuple; /** * Converts the input to a {@link LatLngBoundTuple}. Accepts the same flexible input types as {@link LatLngBoundFunction}. */ export type LatLngBoundTupleFunction = ((input: LatLngBoundSouthWestPoint | LatLngBoundInput, inputNe?: LatLngBoundNothEastPoint) => LatLngBoundTuple) & ((sw: LatLngBoundSouthWestPoint, ne: LatLngBoundNothEastPoint) => LatLngBoundTuple) & ((bound: LatLngBoundInput) => LatLngBoundTuple); export type LatLngBoundTupleFunctionConfig = LatLngBoundFunctionConfig; /** * Creates a {@link LatLngBoundTupleFunction} that converts various bound inputs into a `[sw, ne]` tuple, * applying optional precision to the resulting points. * * @param config - Optional configuration for point precision. * @returns Produces bound tuples from flexible inputs. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilKind factory * @dbxUtilTags value, lat-lng, bound, tuple, factory, geographic * @dbxUtilRelated lat-lng-bound-function, lat-lng-bound * * @__NO_SIDE_EFFECTS__ */ export declare function latLngBoundTupleFunction(config?: LatLngBoundTupleFunctionConfig): LatLngBoundTupleFunction; /** * Convenience function that creates a {@link LatLngBound} using the default configuration. * * @param input - A sw point or any bound input. * @param inputNe - Optional ne point when providing two separate points. * @returns A bound object. * * @example * ```ts * const bound = latLngBound({ lat: 0, lng: 0 }, { lat: 40, lng: 40 }); * // bound.sw.lat === 0, bound.ne.lat === 40 * ``` */ export declare function latLngBound(input: LatLngBoundSouthWestPoint | LatLngBoundInput, inputNe?: LatLngBoundNothEastPoint): LatLngBound; /** * Converts various input types to a {@link LatLngBound}. Accepts two separate points, a bound object, a 2-element tuple, or a 4-element tuple. */ export type LatLngBoundFunction = ((input: LatLngBoundSouthWestPoint | LatLngBoundInput, inputNe?: LatLngBoundNothEastPoint) => LatLngBound) & ((sw: LatLngBoundSouthWestPoint, ne: LatLngBoundNothEastPoint) => LatLngBound) & ((bound: LatLngBoundInput) => LatLngBound); /** * Configuration for creating a {@link LatLngBoundFunction}. */ export interface LatLngBoundFunctionConfig { /** * Point function to use for calculations. */ readonly pointFunction?: LatLngPointFunction; /** * LatLngPrecision to use if pointFunction is not provided. */ readonly precision?: LatLngPrecision; } /** * Creates a {@link LatLngBoundFunction} that normalizes various bound input formats into a {@link LatLngBound}. * * Supports creating bounds from: two separate points, a `[sw, ne]` tuple, a four-point tuple (computes min/max extents), * or a pre-existing bound object. * * @param config - Optional configuration for point precision and custom point functions. * @returns Produces bounds from flexible inputs. * @throws {Error} When the input cannot be parsed into a valid bound. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilKind factory * @dbxUtilTags value, lat-lng, bound, factory, geographic, normalize * @dbxUtilRelated lat-lng-bound, lat-lng-bound-tuple-function, lat-lng-point-function * * @example * ```ts * const fn = latLngBoundFunction({ precision: 3 }); * const result = fn([{ lat: 20, lng: 20 }, { lat: 30, lng: 30 }]); * // result.sw.lat === 20, result.ne.lat === 30 * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function latLngBoundFunction(config?: LatLngBoundFunctionConfig): LatLngBoundFunction; /** * Input type for {@link extendLatLngBound}: a single bound/point or an array of them. */ export type ExtendLatLngBoundInput = ArrayOrValue; /** * Creates a {@link LatLngBound} from the input, which may be a single point, a single bound, or an array of points/bounds. * * When given an array, the first element seeds the initial bound and subsequent elements extend it. * * @param input - One or more points/bounds to derive the bounding box from. * @returns The computed bound, or `undefined` if the input is empty. * * @example * ```ts * const bound = latLngBoundFromInput([ * { lat: 0, lng: 0 }, * { lat: 40, lng: 40 } * ]); * // bound covers from (0,0) to (40,40) * ``` */ export declare function latLngBoundFromInput(input: ExtendLatLngBoundInput): Maybe; /** * Extends an existing bound to include all the given points and/or bounds. * * The returned bound's `sw` corner uses the minimum lat/lng encountered, and its `ne` corner uses the maximum. * * @param bound - The starting bound to extend. * @param extendWith - One or more points/bounds to include. * @returns A new bound that encompasses the original and all extensions. */ export declare function extendLatLngBound(bound: LatLngBound, extendWith: ExtendLatLngBoundInput): LatLngBound; /** * A decision function that checks whether a point or bound satisfies a spatial condition against a reference bound. */ /** * Scales a bound about its center point, growing it for a scale above 1 and shrinking it below 1. * * Use it to put a margin around a bound that was fitted tightly to its contents, so what sits on the very edge is not * flush against it. The scale is proportional to the bound's own span rather than an absolute distance, so the margin * stays visually consistent across bounds of different sizes. * * Latitude and longitude are each clamped to their valid range, so scaling a bound that already spans the globe * returns the same extent rather than an impossible one. Like {@link latLngBoundCenterPoint}, this does not account * for a bound that wraps the antimeridian. * * @param bound - Bound to scale. * @param scale - Multiplier applied to the bound's span. `1` returns an equivalent bound, `1.2` is 20% wider and taller. * @returns The scaled bound, sharing the input's center. * * @example * ```ts * const bound = latLngBound({ lat: 0, lng: 0 }, { lat: 10, lng: 10 }); * scaleLatLngBound(bound, 1.2); * // sw: { lat: -1, lng: -1 }, ne: { lat: 11, lng: 11 } * ``` */ export declare function scaleLatLngBound(bound: LatLngBound, scale: number): LatLngBound; /** * Recenters a bound on a point, growing it symmetrically so it still contains everything it did before. * * Moving a bound's center would normally push part of it out of view. This instead takes the greater distance from * the new center to each opposing edge and mirrors it, so the result is centered on `center` and is a superset of * `bound`. Use it when a view has to be anchored on something specific — a person's address, a selected marker — * without dropping the content the bound was built to cover. * * Latitude and longitude are each clamped to their valid range. Like {@link latLngBoundCenterPoint}, this does not * account for a bound that wraps the antimeridian. * * @param bound - Bound whose content must remain covered. * @param center - Point the result is centered on. * @returns A bound centered on `center` that contains `bound`. * * @example * ```ts * const bound = latLngBound({ lat: 0, lng: 0 }, { lat: 10, lng: 10 }); * centerLatLngBoundOn(bound, { lat: 2, lng: 2 }); * // sw: { lat: -6, lng: -6 }, ne: { lat: 10, lng: 10 } * ``` */ export declare function centerLatLngBoundOn(bound: LatLngBound, center: LatLngPoint): LatLngBound; export type LatLngBoundCheckFunction = DecisionFunction; /** * Function that returns true if the input is entirely within the context's bound. * * Exposes the reference bound via the `_bound` property. */ export type IsWithinLatLngBoundFunction = LatLngBoundCheckFunction & { readonly _bound: LatLngBound; }; /** * Creates an {@link IsWithinLatLngBoundFunction} that checks if a given point or bound * falls entirely within the specified bound. Points are checked directly; bounds require * both corners to be within. * * @param bound - The reference bound to check containment against. * @returns Returns `true` if the input is within the reference bound. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilKind factory * @dbxUtilTags value, lat-lng, bound, contains, decision, factory, geographic * @dbxUtilRelated overlaps-lat-lng-bound-function, is-lat-lng-point-within-lat-lng-bound * * @__NO_SIDE_EFFECTS__ */ export declare function isWithinLatLngBoundFunction(bound: LatLngBound): IsWithinLatLngBoundFunction; /** * Checks whether one bound is entirely contained within another by verifying both its corners are within the outer bound. * * @param bound - The inner bound to test. * @param within - The outer bound to test against. * @returns `true` if both corners of `bound` are within `within` */ export declare function isLatLngBoundWithinLatLngBound(bound: LatLngBound, within: LatLngBound): boolean; /** * Checks whether a point lies within a bound. Handles bounds that wrap the antimeridian by checking * if the longitude falls on either side of the wrap. * * @param point - The point to test. * @param within - The bound to test against. * @returns `true` if the point is within the bound. * * @example * ```ts * const bound = latLngBound({ lat: 0, lng: 0 }, { lat: 40, lng: 40 }); * isLatLngPointWithinLatLngBound(latLngPoint(10, 10), bound); * // true * ``` */ export declare function isLatLngPointWithinLatLngBound(point: LatLngPoint, within: LatLngBound): boolean; /** * Function that returns true if the input overlaps the context's bound. * * Exposes the reference bound via the `_bound` property. */ export type OverlapsLatLngBoundFunction = LatLngBoundCheckFunction & { readonly _bound: LatLngBound; }; /** * Checks whether two bounds overlap each other. * * @param a - The first bound. * @param b - The second bound. * @returns `true` if the bounds overlap. */ export declare function latLngBoundOverlapsLatLngBound(a: LatLngBound, b: LatLngBound): boolean; /** * Creates an {@link OverlapsLatLngBoundFunction} that checks whether a given point or bound * overlaps the reference bound. Internally converts bounds to rectangles for overlap detection, * handling antimeridian wrapping. * * @param bound - The reference bound to check overlap against. * @returns Returns `true` if the input overlaps the reference bound. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilKind factory * @dbxUtilTags value, lat-lng, bound, overlap, decision, factory, geographic * @dbxUtilRelated is-within-lat-lng-bound-function, lat-lng-bound-overlaps-lat-lng-bound * * @__NO_SIDE_EFFECTS__ */ export declare function overlapsLatLngBoundFunction(bound: LatLngBound): OverlapsLatLngBoundFunction; /** * The total span of longitude in degrees (360). */ export declare const TOTAL_SPAN_OF_LONGITUDE = 360; /** * Normalizes a {@link LatLngBound} into a {@link Rectangle} in an arbitrary coordinate space * where the left edge (-180 longitude) begins at x=360. This allows safe rectangle-based * overlap comparisons without worrying about antimeridian wrapping. * * @param bound - The geographic bound to convert. * @returns A rectangle suitable for overlap calculations. */ export declare function boundToRectangle(bound: LatLngBound): Rectangle;