/** Represents an element of {@link Polygon}. */ export interface Point { /** The x-coordinate of the point. */ x: number; /** The y-coordinate of the point. */ y: number; /** * Whether the point is an off-curve point, i.e. a control point in a quadratic * Bézier curve. */ off: boolean; } /** * The same as {@link Point} except that the `off` property is optional. * When `off` is omitted, it is treated as an on-curve point (`off: false`). * Used in the parameter type of {@link Polygon}'s constructor. */ export type PointOptOff = Omit & Partial>; /** * Represents a single contour of a rendered glyph. * * A contour that a Polygon represents is a closed curve made up of straight line * segments or quadratic Bézier curve segments. A Polygon is represented as a * series of {@link Point}'s, each of which is an on-curve point or an off-curve * point. Two consecutive on-curve points form a line segment. A sequence of * two on-curve points with an off-curve point in between forms a curve segment. * The last point and the first point of a Polygon form a line segment that closes * the loop (if the two points differ). */ export declare class Polygon { protected readonly _precision: number; protected _array: Point[]; /** * A read-only array consisting of the points in this contour. * * Modifications to this array do NOT affect the contour; * use the {@link set} method to modify the contour. * * @example * ```ts * for (const point of polygon.array) { * // ... * } * ``` * * Note that the coordinates of all points are computed each time this property * is accessed. If you need to access the array repeatedly, consider storing * the result in a variable to avoid redundant computation. * ```ts * // DO: * const array = polygon.array; * for (let i = 0; i < array.length; i++) { * const point = array[i]; * // ... * } * * // DON'T: * for (let i = 0; i < polygon.array.length; i++) { * const point = polygon.array[i]; * // ... * } * ``` * * @see {@link Polygon.length} is faster if you only need the length. * @see {@link Polygon.get} is faster if you need just one element. */ get array(): readonly Readonly[]; /** The number of points in this contour. */ get length(): number; /** * Constructs a `Polygon` object. If the `length` argument is given, * the constructed object represents a contour of size `length`, with all * its points initialized to the origin (0, 0). Otherwise the contour has * no points. * @param length - The initial number of points in the contour. */ constructor(length?: number); /** * Constructs a `Polygon` object with the given points as its contour. * @param points - The points in the contour. * @internal */ constructor(points: readonly PointOptOff[]); /** * Appends a point to the end of its contour. * @param x - The x-coordinate of the appended point. * @param y - The y-coordinate of the appended point. * @param off - Whether the appended point is an off-curve point. Defaults to `false`. */ push(x: number, y: number, off?: boolean): void; /** * Appends a point to the end of its contour. * @param point - The appended point. * @internal */ pushPoint(point: PointOptOff): void; /** * Modifies a point in its contour. * @param index - The index in the contour of the point to be modified. * @param x - The new x-coordinate of the point. * @param y - The new y-coordinate of the point. * @param off - Whether the new point is an off-curve point. Defaults to `false`. */ set(index: number, x: number, y: number, off?: boolean): void; /** * Modifies a point in its contour. * @param index - The index in the contour of the point to be modified. * @param point - A point of the new coordinate values. If `off` property is * omitted, the point is treated as an on-curve point. * @internal */ setPoint(index: number, point: PointOptOff): void; /** * Retrieves a point from its contour. Throws an error if the index is * out of bounds. * @param index - The index in the contour of the point to be retrieved. * @returns A read-only point object. Modifications made to the returned * object do NOT affect the values of the point in this Polygon's contour; * use the {@link set} method to modify the contour. * @example * ```ts * for (let i = 0; i < polygon.length; i++) { * const point = polygon.get(i); * // ... * } * ``` */ get(index: number): Readonly; /** * Reverses the order of points in its contour. */ reverse(): void; /** * Appends the points from the contour of another {@link Polygon} to the end of * this contour. The other Polygon is not mutated. * @param poly - The other {@link Polygon} to be appended. */ concat(poly: Polygon): void; /** * Removes the first point from its contour. Does nothing if the contour is empty. */ shift(): void; /** * Inserts a new point at the beginning of its contour. * @param x - The x-coordinate of the inserted point. * @param y - The y-coordiante of the inserted point. * @param off - Whether the inserted point is an off-curve point. Defaults to `false`. */ unshift(x: number, y: number, off?: boolean): void; /** * Creates a deep copy of this Polygon. * @returns A new {@link Polygon} instance. */ clone(): Polygon; /** * Iterates over its points. * @returns An iterator of its {@link Point}s. * @example * ```ts * for (const { x, y, off } of polygon) { * // ... * } * ``` */ [Symbol.iterator]: (this: this) => Iterator>; protected createInternalPoint(x: number, y: number, off?: boolean): Point; /** * Translates the whole polygon by the given amount. * @param dx - The x-amount of translation. * @param dy - The y-amount of translation. * @returns This object (for chaining). * @internal */ translate(dx: number, dy: number): this; /** * Flips the sign of the x-coordinate of each point in the contour. * @returns This object (for chaining). * @internal */ reflectX(): this; /** * Flips the sign of the y-coordinate of each point in the contour. * @returns This object (for chaining). * @internal */ reflectY(): this; /** * Rotates the whole polygon by 90 degrees clockwise. * @returns This object (for chaining). * @internal */ rotate90(): this; /** * Rotates the whole polygon by 180 degrees. * @returns This object (for chaining). * @internal */ rotate180(): this; /** * Rotates the whole polygon by 270 degrees clockwise. * @returns This object (for chaining). * @internal */ rotate270(): this; /** * @returns This object (for chaining). * @internal */ floor(): this; }