leaflet
Version:
JavaScript library for mobile-friendly interactive maps
159 lines (158 loc) • 5.29 kB
TypeScript
export type PointTuple = [number, number];
export type PointExpression = Point | PointTuple | {
x: number;
y: number;
};
/** @typedef {[number, number]} PointTuple */
/**
* A `Point`, or its array (`[x, y]`) or object (`{x, y}`) form.
* @typedef {Point | PointTuple | {x: number, y: number}} PointExpression
*/
/**
* Represents a point with `x` and `y` coordinates in pixels.
*
* @example
* ```js
* const point = new Point(200, 300);
* ```
*
* All Leaflet methods and options that accept `Point` objects also accept them in a simple Array form (unless noted
* otherwise), so these lines are equivalent:
*
* ```js
* map.panBy([200, 300]);
* map.panBy(new Point(200, 300));
* ```
*
* Note that `Point` does not inherit from Leaflet's `Class` object, which means new classes can't inherit from it,
* and new methods can't be added to it with the `include` function.
*
* @categoryDescription Functions
* There are several static functions which can be called without instantiating Point:
*/
export declare class Point {
/**
* The `x` coordinate of the point
* @type {number}
*/
x: number;
/**
* The `y` coordinate of the point
* @type {number}
*/
y: number;
constructor(x: number, y: number, round?: boolean);
constructor(coords: PointExpression);
/**
* Returns `true` if the Point object can be properly initialized.
* @category Functions
* @overload
* @param {number} x
* @param {number} [y]
* @returns {boolean}
*/
/**
* Expects an array of the form `[x, y]` or a plain object of the form `{x: Number, y: Number}`. Returns `true` if
* the Point object can be properly initialized.
* @overload
* @param {unknown} coords
* @returns {coords is PointExpression}
*/
/**
* @param {unknown} x
* @param {unknown} [y]
*/
static validate(x: number, y?: number): boolean;
/**
* Returns `true` if the Point object can be properly initialized.
* @category Functions
* @overload
* @param {number} x
* @param {number} [y]
* @returns {boolean}
*/
/**
* Expects an array of the form `[x, y]` or a plain object of the form `{x: Number, y: Number}`. Returns `true` if
* the Point object can be properly initialized.
* @overload
* @param {unknown} coords
* @returns {coords is PointExpression}
*/
/**
* @param {unknown} x
* @param {unknown} [y]
*/
static validate(coords: unknown): coords is PointExpression;
/** Returns a copy of the current point. */
clone(): Point;
/**
* Returns the result of addition of the current and the given points.
* @param {PointExpression} point
*/
add(point: PointExpression): Point;
/** @param {Point} point */
_add(point: Point): this;
/**
* Returns the result of subtraction of the given point from the current.
* @param {PointExpression} point
*/
subtract(point: PointExpression): Point;
/** @param {Point} point */
_subtract(point: Point): this;
/**
* Returns the result of division of the current point by the given number.
* @param {number} num
*/
divideBy(num: number): Point;
/** @param {number} num */
_divideBy(num: number): this;
/**
* Returns the result of multiplication of the current point by the given number.
* @param {number} num
*/
multiplyBy(num: number): Point;
/** @param {number} num */
_multiplyBy(num: number): this;
/**
* Multiply each coordinate of the current point by each coordinate of `scale`. In linear
* algebra terms, multiply the point by the [scaling
* matrix](https://en.wikipedia.org/wiki/Scaling_%28geometry%29#Matrix_representation) defined by `scale`.
* @param {Point} scale
*/
scaleBy(scale: Point): Point;
/**
* Inverse of `scaleBy`. Divide each coordinate of the current point by each coordinate of `scale`.
* @param {Point} scale
*/
unscaleBy(scale: Point): Point;
/** Returns a copy of the current point with rounded coordinates. */
round(): Point;
_round(): this;
/** Returns a copy of the current point with floored coordinates (rounded down). */
floor(): Point;
_floor(): this;
/** Returns a copy of the current point with ceiled coordinates (rounded up). */
ceil(): Point;
_ceil(): this;
/** Returns a copy of the current point with truncated coordinates (rounded towards zero). */
trunc(): Point;
_trunc(): this;
/**
* Returns the cartesian distance between the current and the given points.
* @param {PointExpression} point
*/
distanceTo(point: PointExpression): number;
/**
* Returns `true` if the given point has the same coordinates.
* @param {PointExpression} point
*/
equals(point: PointExpression): boolean;
/**
* Returns `true` if both coordinates of the given point are less than
* the corresponding current point coordinates (in absolute values).
* @param {PointExpression} point
*/
contains(point: PointExpression): boolean;
/** Returns a string representation of the point for debugging purposes. */
toString(): string;
}