@thi.ng/geom
Version:
Functional, polymorphic API for 2D geometry types & SVG generation
58 lines • 2.32 kB
TypeScript
import type { Maybe } from "@thi.ng/api";
import type { MultiFn2 } from "@thi.ng/defmulti";
import type { IShape, IShape2 } from "./api.js";
import type { ReadonlyVec } from "@thi.ng/vectors";
import { ComplexPolygon } from "./api/complex-polygon.js";
import { Group } from "./api/group.js";
import { Line } from "./api/line.js";
import { Path } from "./api/path.js";
import { Polygon } from "./api/polygon.js";
import { Polyline } from "./api/polyline.js";
/**
* Function overrides for {@link clipConvex}.
*/
export type ClipConvexFn = {
(shape: ComplexPolygon, boundary: IShape2 | ReadonlyVec[]): Maybe<ComplexPolygon[]>;
(shape: Group, boundary: IShape2 | ReadonlyVec[]): Maybe<Group[]>;
(shape: Line, boundary: IShape2 | ReadonlyVec[]): Maybe<Line[]>;
(shape: Path, boundary: IShape2 | ReadonlyVec[]): Maybe<Path[]>;
(shape: Polyline, boundary: IShape2 | ReadonlyVec[]): Maybe<Polyline[]>;
(shape: IShape2, boundary: IShape2 | ReadonlyVec[]): Maybe<Polygon[]>;
} & MultiFn2<IShape, IShape | ReadonlyVec[], Maybe<IShape[]>>;
/**
* Takes a shape and a boundary (both convex), then uses the Sutherland-Hodgeman
* algorithm to compute a clipped version of the shape (against the boundary)
* and returns an array of resulting clipped shape(s) or `undefined` if there're
* no remaining result vertices (i.e. if the original shape was clipped
* entirely).
*
* @remarks
* Internally uses
* [`sutherlandHodgeman`](https://docs.thi.ng/umbrella/geom-clip-poly/functions/sutherlandHodgeman.html).
* For groups, calls itself for each child shape individually and returns a new
* group of results (if any).
*
* For {@link ComplexPolygon}s, children are only processed if the main boundary
* hasn't been completely clipped. Similarly for closed paths, where sub-paths
* (holes) are only processed if the clipped main path has remaining vertices.
*
* Paths are always first sampled/converted to polygons or polylines.
*
* Currently implemented for:
*
* - {@link Circle}
* - {@link ComplexPolygon}
* - {@link Ellipse}
* - {@link Extra}
* - {@link Group}
* - {@link Line}
* - {@link Path}
* - {@link Polygon}
* - {@link Quad}
* - {@link Triangle}
*
* @param shape
* @param boundary
*/
export declare const clipConvex: ClipConvexFn;
//# sourceMappingURL=clip-convex.d.ts.map