@math.gl/polygon
Version: 
Polygon/polyline processing utilities
103 lines • 4.7 kB
TypeScript
import type { NumericArray } from '@math.gl/core';
export declare const WINDING: {
    readonly CLOCKWISE: 1;
    readonly COUNTER_CLOCKWISE: -1;
};
/** Polygon representation where each point is represented as a separate array of positions. */
type PointsArray = NumericArray[];
/** Segment visitor callback type for polygons defined with flat arrays, */
type SegmentVisitorFlat = (p1x: number, p1y: number, p2x: number, p2y: number, i1: number, i2: number) => void;
/** Segment visitor callback type for polygons defined with array of points. */
export type SegmentVisitorPoints = (p1: NumericArray, p2: NumericArray, i1: number, i2: number) => void;
export type Plane2D = 'xy' | 'yz' | 'xz';
/** Parameters of a polygon. */
type PolygonParams = {
    /**
     * Start index of the polygon in the array of positions.
     * @default `0`
     */
    start?: number;
    /**
     * End index of the polygon in the array of positions.
     * @default number of positions
     */
    end?: number;
    /**
     * Size of a point, 2 (XZ) or 3 (XYZ). Affects only polygons stored in flat arrays.
     * @default `2`
     */
    size?: number;
    /**
     * Indicates that the first point of the polygon is equal to the last point, and additional checks should be ommited.
     */
    isClosed?: boolean;
    /**
     * The 2D projection plane on which to calculate the area of a 3D polygon.
     * @default `'xy'`
     */
    plane?: Plane2D;
};
/**
 * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
 * Note: points are modified in-place.
 * @param points An array that represents points of the polygon.
 * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
 * @param options Parameters of the polygon.
 * @return Returns true if the winding direction was changed.
 */
export declare function modifyPolygonWindingDirection(points: NumericArray, direction: number, options?: PolygonParams): boolean;
/**
 * Returns winding direction of the polygon.
 * @param points An array that represents points of the polygon.
 * @param options Parameters of the polygon.
 * @returns Winding direction of the polygon.
 */
export declare function getPolygonWindingDirection(points: NumericArray, options?: PolygonParams): number;
export declare const DimIndex: Record<string, number>;
/**
 * Returns signed area of the polygon.
 * @param points An array that represents points of the polygon.
 * @param options Parameters of the polygon.
 * @returns Signed area of the polygon.
 * https://en.wikipedia.org/wiki/Shoelace_formula
 */
export declare function getPolygonSignedArea(points: NumericArray, options?: PolygonParams): number;
/**
 * Calls the visitor callback for each segment in the polygon.
 * @param points An array that represents points of the polygon
 * @param visitor A callback to call for each segment.
 * @param options Parameters of the polygon.
 */
export declare function forEachSegmentInPolygon(points: NumericArray, visitor: SegmentVisitorFlat, options?: PolygonParams): void;
/**
 * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
 * Note: points are modified in-place.
 * @param points Array of points that represent the polygon.
 * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
 * @param options Parameters of the polygon.
 * @return Returns true if the winding direction was changed.
 */
export declare function modifyPolygonWindingDirectionPoints(points: PointsArray, direction: number, options?: PolygonParams): boolean;
/**
 * Returns winding direction of the polygon.
 * @param points Array of points that represent the polygon.
 * @param options Parameters of the polygon.
 * @returns Winding direction of the polygon.
 */
export declare function getPolygonWindingDirectionPoints(points: PointsArray, options?: PolygonParams): number;
/**
 * Returns signed area of the polygon.
 * @param points Array of points that represent the polygon.
 * @param options Parameters of the polygon.
 * @returns Signed area of the polygon.
 */
export declare function getPolygonSignedAreaPoints(points: PointsArray, options?: PolygonParams): number;
/**
 * Calls visitor callback for each segment in the polygon.
 * @param points Array of points that represent the polygon.
 * @param visitor A callback to call for each segment.
 * @param options Parameters of the polygon.
 */
export declare function forEachSegmentInPolygonPoints(points: PointsArray, visitor: SegmentVisitorPoints, options?: PolygonParams): void;
export {};
//# sourceMappingURL=polygon-utils.d.ts.map