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 a function that produces bound tuples from flexible inputs */ 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. */ pointFunction?: LatLngPointFunction; /** * LatLngPrecision to use if pointFunction is not provided. */ 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 a function that produces bounds from flexible inputs * @throws {Error} when the input cannot be parsed into a valid bound * * @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 * ``` */ 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. */ 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 a function that returns `true` if the input is within the reference bound */ 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 a function that returns `true` if the input overlaps the reference bound */ 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;