import { Multiline } from './Multiline'; import { PlanarSet } from '../data_structures/PlanarSet'; import * as geom from '../classes'; import type { Box } from '../classes/Box'; import type { Face } from '../classes/Face'; import type { Line } from '../classes/Line'; import type { Point } from '../classes/Point'; import type { Segment } from '../classes/Segment'; import type { Edge, EdgeShape } from '../classes/Edge'; import { Shape } from './Shape'; /** * Class representing a polygon. * Polygon in FlattenJS is a multipolygon comprised from a set of [faces]{@link geom.Face}. * Face, in turn, is a closed loop of [edges]{@link geom.Edge}, where edge may be segment * or circular arc */ export declare class Polygon extends Shape { static EMPTY: Readonly; /** * Container of faces (closed loops), may be empty */ faces: PlanarSet; /** * Container of edges */ edges: PlanarSet; /** * Constructor creates new instance of polygon. With no arguments new polygon is empty. * Constructor accepts as argument array that define loop of shapes * or array of arrays in case of multi polygon * Loop may be defined in different ways: * - array of shapes of type Segment or Arc * - array of points (geom.Point) * - array of numeric pairs which represent points * - box or circle object * Alternatively, it is possible to use polygon.addFace method * @param {args} - array of shapes or array of arrays */ constructor(); constructor(edges: EdgeShape[]); constructor(points: Point[]); constructor(points: number[][]); constructor(shape: geom.Box | geom.Circle); get tag(): geom.ShapeTag; get name(): string; get parts(): geom.EdgeShape[]; /** * Returns bounding box of the polygon */ get box(): Box; /** * Returns bounding box of the polygon */ get center(): geom.Point; /** * Returns array of vertices */ get vertices(): geom.Point[]; /** * Create new cloned instance of the polygon */ clone(): any; /** * Return true is polygon has no edges */ isEmpty(): boolean; /** * Return true if polygon is valid for boolean operations * Polygon is valid if * 1. All faces are simple polygons (there are no self-intersected polygons) * 2. All faces are orientable and there is no island inside island or hole inside hole - TODO * 3. There is no intersections between faces (excluding touching) - TODO */ isValid(): boolean; /** * Returns area of the polygon. Area of an island will be added, area of a hole will be subtracted */ area(): number; /** * Add new face to polygon. Returns added face * @param {Point[]|Segment[]|Arc[]|Circle|Box} args - new face may be create with one of the following ways: * 1) array of points that describe closed path (edges are segments) * 2) array of shapes (segments and arcs) which describe closed path * 3) circle - will be added as counterclockwise arc * 4) box - will be added as counterclockwise rectangle * You can chain method face.reverse() is you need to change direction of the creates face */ addFace(a: unknown, b?: unknown): geom.Face; /** * Delete existing face from polygon */ deleteFace(face: geom.Face): boolean; /** * Clear all faces and create new faces from edges */ recreateFaces(): void; /** * Delete chain of edges from the face. * @param face Face to remove chain * @param edgeFrom Start of the chain of edges to be removed * @param edgeTo End of the chain of edges to be removed */ removeChain(face: Face, edgeFrom: Edge, edgeTo: Edge): void; /** * Add point as a new vertex and split edge. Point supposed to belong to an edge. * When edge is split, new edge created from the start of the edge to the new vertex * and inserted before current edge. * Current edge is trimmed and updated. * Method returns new edge added. If no edge added, it returns edge before vertex * @param pt Point to be added as a new vertex * @param edge Edge to be split with new vertex and then trimmed from start */ addVertex(pt: Point, edge: Edge): geom.Edge; /** * Merge given edge with next edge and remove vertex between them */ removeEndVertex(edge: Edge): void; /** * Cut polygon with multiline and return array of new polygons * Multiline should be constructed from a line with intersection point, see notebook: * https://next.observablehq.com/@alexbol99/cut-polygon-with-line */ cut(multiline: Multiline): any[]; /** * Cut face of polygon with a segment between two points and create two new polygons * Supposed that a segments between points does not intersect any other edge * @param pt1 * @param pt2 */ cutFace(pt1: Point, pt2: Point): geom.Polygon[]; /** * Return a result of cutting polygon with line */ cutWithLine(line: Line): any; /** * Returns the first found edge of polygon that contains given point * If point is a vertex, return the edge where the point is an end vertex, not a start one */ findEdgeByPoint(pt: Point): geom.Edge; /** * Split polygon into array of polygons, where each polygon is an island with all * hole that it contains */ splitToIslands(): geom.Polygon[]; /** * Reverse orientation of all faces to opposite */ reverse(): this; /** * Returns true if polygon contains shape: no point of shape lay outside of the polygon, * false otherwise */ contains(shape: Shape): boolean; /** * Return distance and shortest segment between polygon and other shape as array [distance, shortest_segment] */ distanceTo(shape: Shape): [number, Segment]; /** * Return array of intersection points between polygon and other shape * @param shape Shape of the one of supported types */ intersect(shape: Shape): geom.Point[]; /** * Returns new polygon translated by vector vec */ translate(a: unknown, b?: unknown): geom.Polygon; /** * Return new polygon rotated by given angle around given point * If point omitted, rotate around origin (0,0) * Positive value of angle defines rotation counterclockwise, negative - clockwise * @param angle - rotation angle in radians * @param center - rotation center, default is (0,0) */ rotate(angle?: number, center?: geom.Point): geom.Polygon; /** * Return new polygon with coordinates multiplied by scaling factor * @param sx - x-axis scaling factor * @param sy - y-axis scaling factor */ scale(sx: number, sy?: number): geom.Polygon; /** * Return new polygon transformed using affine transformation matrix */ transform(matrix?: Readonly): geom.Polygon; /** * This method returns an object that defines how data will be * serialized when called JSON.stringify() method */ toJSON(): { name: string; faces: any[][]; }; /** * Transform all faces into array of polygons */ toArray(): geom.Polygon[]; } /** * Shortcut method to create new polygon */ export declare const polygon: (a: any) => geom.Polygon; //# sourceMappingURL=Polygon.d.ts.map