@andamento/core 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,776 @@
1
+ /**
2
+ * Small, dependency-free 2D geometry kernel.
3
+ *
4
+ * Conventions:
5
+ * - Coordinates are SVG-style (y grows downward), but all math is orientation-agnostic.
6
+ * - Polygons are arrays of vertices without a repeated closing vertex.
7
+ * - "Positive" orientation means a positive shoelace area. All internal polygons are
8
+ * normalized to positive orientation, so the interior is to the left of each edge
9
+ * in the shoelace sense and the inward normal of edge (dx, dy) is (-dy, dx).
10
+ * - `clipConvex` needs a convex clip polygon (the subject can be any simple polygon);
11
+ * `insetConvex` needs a convex polygon and `containsPolygon` a convex `outer`. Non-convex tiles are inset
12
+ * with `insetPolygon` (offset.ts).
13
+ */
14
+ interface Vec {
15
+ x: number;
16
+ y: number;
17
+ }
18
+ type Polygon = Vec[];
19
+ interface Rect {
20
+ x: number;
21
+ y: number;
22
+ width: number;
23
+ height: number;
24
+ }
25
+ declare const vec: (x: number, y: number) => Vec;
26
+ declare const add: (a: Vec, b: Vec) => Vec;
27
+ declare const sub: (a: Vec, b: Vec) => Vec;
28
+ declare const scale: (a: Vec, s: number) => Vec;
29
+ declare const dot: (a: Vec, b: Vec) => number;
30
+ declare const cross: (a: Vec, b: Vec) => number;
31
+ declare const length: (a: Vec) => number;
32
+ /** Polygon for an axis-aligned rectangle, in positive orientation. */
33
+ declare function rectPolygon(x: number, y: number, width: number, height: number): Polygon;
34
+ /** Shoelace signed area. Positive for the library's canonical orientation. */
35
+ declare function signedArea(p: Polygon): number;
36
+ declare const area: (p: Polygon) => number;
37
+ declare function ensurePositive(p: Polygon): Polygon;
38
+ declare function centroid(p: Polygon): Vec;
39
+ declare function bbox(p: Polygon): Rect;
40
+ declare function rectsOverlap(a: Rect, b: Rect, tol?: number): boolean;
41
+ /** Rotate by `radians` about the coordinate origin, then translate by `offset`. */
42
+ declare function transform(p: Polygon, radians: number, offset: Vec): Polygon;
43
+ declare function isConvex(p: Polygon, tol?: number): boolean;
44
+ /**
45
+ * Keep the part of `poly` where dot(normal, v - point) >= offset
46
+ * (one pass of Sutherland–Hodgman).
47
+ */
48
+ declare function clipHalfPlane(poly: Polygon, point: Vec, normal: Vec, offset?: number): Polygon;
49
+ /** Remove consecutive duplicate vertices; return [] if the result has no area. */
50
+ declare function cleanPolygon(p: Polygon, tol?: number): Polygon;
51
+ /**
52
+ * Intersection of `subject` (any simple polygon) with a convex `clip` polygon.
53
+ * If a non-convex subject is cut into separate parts, they come back as one polygon
54
+ * joined by zero-width strips along the clip edge; use `clipPolygonToConvex` to get
55
+ * the parts separately.
56
+ */
57
+ declare function clipConvex(subject: Polygon, clip: Polygon): Polygon;
58
+ /**
59
+ * Shrink a convex polygon by moving every edge inward by `distance`.
60
+ * Implemented as a half-plane intersection, so edges that collapse simply vanish
61
+ * and an over-inset polygon returns [].
62
+ */
63
+ declare function insetConvex(poly: Polygon, distance: number): Polygon;
64
+ /** True if every vertex of `inner` lies inside (or on) convex polygon `outer`. */
65
+ declare function containsPolygon(outer: Polygon, inner: Polygon, tol?: number): boolean;
66
+ /** Do two polygons share a boundary segment of positive length? */
67
+ declare function sharesEdge(a: Polygon, b: Polygon, tol: number): boolean;
68
+ /** Convex hull (positive orientation) of a set of points. */
69
+ declare function convexHull(points: Vec[]): Polygon;
70
+
71
+ /**
72
+ * Shrink a simple polygon (convex or not) by moving every edge inward by `distance`.
73
+ * Returns [] if nothing is left. If the shape splits, the largest piece is returned.
74
+ */
75
+ declare function insetPolygon(poly: Polygon, distance: number): Polygon;
76
+ /** Like `insetPolygon`, but every piece when a narrow neck pinches the shape apart. */
77
+ declare function insetPolygonPieces(poly: Polygon, distance: number): Polygon[];
78
+ /**
79
+ * Grow a simple polygon by moving every edge outward by `distance` (mitred corners;
80
+ * pockets narrower than 2 × distance close up). Positively oriented.
81
+ */
82
+ declare function outsetPolygon(poly: Polygon, distance: number): Polygon;
83
+ /** Cut a closed outline at its self-crossings into simple loops. */
84
+ declare function splitSelfIntersections(poly: Polygon): Polygon[];
85
+ /** Ray-casting point-in-polygon test (even–odd rule). */
86
+ declare function pointInPolygon(pt: Vec, poly: Polygon): boolean;
87
+ /**
88
+ * Intersection of a simple polygon (convex or not) with a convex `clip` polygon, as
89
+ * separate pieces. Unlike `clipConvex`, a subject that the clip edge cuts into several
90
+ * parts comes back as several clean polygons.
91
+ *
92
+ * The subject's outline is walked edge by edge; the stretches inside the clip region form
93
+ * chains that enter and leave through the clip outline. Each piece is a chain followed by
94
+ * a walk forward along the clip outline to wherever the next chain enters (both outlines
95
+ * have the same orientation, so "forward" stays on the inside).
96
+ */
97
+ declare function clipPolygonToConvex(subject: Polygon, clip: Polygon): Polygon[];
98
+
99
+ /**
100
+ * Polygon boolean operations by overlay.
101
+ *
102
+ * Every input outline is cut at every point where it meets another, giving a set of
103
+ * pieces that don't cross. For each piece, a point just to its left and just to its
104
+ * right is tested against what the result should contain (any combination of inside /
105
+ * outside tests). Pieces with the result on exactly one side form the result's
106
+ * boundary, oriented with the result on the left, and are chained into loops.
107
+ *
108
+ * This handles holes, shapes touching at a point, and edges that run along each other,
109
+ * as long as features are much larger than the tolerance.
110
+ */
111
+ /** A region with holes: `outer` is positively oriented, `holes` negatively. */
112
+ interface Shape {
113
+ outer: Polygon;
114
+ holes: Polygon[];
115
+ }
116
+ /**
117
+ * The boundary of `{ p : inside(p) }` among the given outlines, as shapes.
118
+ * `scale` is the size of the scene; tolerances are relative to it.
119
+ */
120
+ declare function overlay(outlines: Polygon[], inside: (p: Vec) => boolean, scale: number): Shape[];
121
+ /**
122
+ * Split the plane into regions by a labeling function: each point gets a label (a number;
123
+ * negative for "nothing"), and every region of equal label is returned as shapes. The
124
+ * labels may only change across the given outlines (closed loops; pass an open polyline's
125
+ * segments as two-point "loops"), which are cut where they meet like `overlay`'s.
126
+ */
127
+ declare function partition(outlines: Polygon[], label: (p: Vec) => number, scale: number): Map<number, Shape[]>;
128
+ /** Area of a shape (outline minus holes). */
129
+ declare const shapeArea: (s: Shape) => number;
130
+ /** Centroid of a shape, holes included. */
131
+ declare function shapeCentroid(s: Shape): Vec;
132
+
133
+ /**
134
+ * Andamento: tesserae laid in rows (courses) that follow guide curves, circle center points
135
+ * or run along the region's outline, the way mosaicists lay them.
136
+ */
137
+ interface FlowSpec {
138
+ type: "flow";
139
+ /** Row height: the width of each tessera across its row. */
140
+ size: number;
141
+ /** Tessera length along its row, as a multiple of `size`. Defaults to 1.3. */
142
+ length?: number;
143
+ /** How much tessera lengths vary, 0 (all alike) to 0.9. Defaults to 0.3. */
144
+ jitter?: number;
145
+ /**
146
+ * Curves for rows to follow, in layout units: a row runs along each, and further rows
147
+ * parallel to it on both sides. Open polylines, or `closed` loops.
148
+ */
149
+ guides?: {
150
+ points: Vec[];
151
+ closed?: boolean;
152
+ }[];
153
+ /** Points for rows to circle, in layout units: a round tessera, ringed by row after row. */
154
+ centers?: Vec[];
155
+ /**
156
+ * Rows also run along the region's outline (and round its holes), as in opus
157
+ * vermiculatum. Defaults to true when there are no guides or centers.
158
+ */
159
+ followEdges?: boolean;
160
+ /** Seed for the deterministic random generator. Defaults to 1. */
161
+ seed?: number;
162
+ }
163
+
164
+ interface GridSpec {
165
+ type: "grid";
166
+ /** Cell width. */
167
+ width: number;
168
+ /** Cell height. Defaults to `width` (squares). */
169
+ height?: number;
170
+ }
171
+ interface RunningBondSpec {
172
+ type: "runningBond";
173
+ width: number;
174
+ height: number;
175
+ /** Fraction of a brick each row is shifted by. Defaults to 0.5. */
176
+ offset?: number;
177
+ }
178
+ interface HerringboneSpec {
179
+ type: "herringbone";
180
+ /** Long side of each rectangle. Must be greater than `width`. */
181
+ length: number;
182
+ /** Short side of each rectangle. */
183
+ width: number;
184
+ }
185
+ interface BasketweaveSpec {
186
+ type: "basketweave";
187
+ /** Side of each square block (= length of each strip). */
188
+ length: number;
189
+ /** Strips per block. Defaults to 2. */
190
+ strips?: number;
191
+ }
192
+ interface HexagonalSpec {
193
+ type: "hexagonal";
194
+ /** Circumradius: center-to-corner distance. */
195
+ size: number;
196
+ /** "pointy" puts a corner at the top; "flat" puts an edge at the top. Defaults to "pointy". */
197
+ orientation?: "pointy" | "flat";
198
+ }
199
+ interface TriangularSpec {
200
+ type: "triangular";
201
+ /** Side length of each equilateral triangle. */
202
+ size: number;
203
+ }
204
+ interface RhombilleSpec {
205
+ type: "rhombille";
206
+ /** Side length of each rhombus. Three rhombi form a hexagon ("tumbling blocks"). */
207
+ size: number;
208
+ }
209
+ interface OctagonSquareSpec {
210
+ type: "octagonSquare";
211
+ /** Edge length shared by the octagons and the small squares. */
212
+ size: number;
213
+ }
214
+ interface TrihexagonalSpec {
215
+ type: "trihexagonal";
216
+ /** Edge length shared by the hexagons and triangles. */
217
+ size: number;
218
+ }
219
+ interface RhombitrihexagonalSpec {
220
+ type: "rhombitrihexagonal";
221
+ /** Edge length shared by the hexagons, squares and triangles. */
222
+ size: number;
223
+ }
224
+ interface CairoSpec {
225
+ type: "cairo";
226
+ /** Spacing of the underlying square grid; each pentagon is roughly this wide. */
227
+ size: number;
228
+ }
229
+ interface HopscotchSpec {
230
+ type: "hopscotch";
231
+ /** Side of the large squares. */
232
+ large: number;
233
+ /** Side of the small squares. Must not exceed `large`. */
234
+ small: number;
235
+ }
236
+ interface PinwheelSpec {
237
+ type: "pinwheel";
238
+ /** Long side of each rectangle. Must be greater than `width`. */
239
+ length: number;
240
+ /** Short side of each rectangle. The center squares have side `length - width`. */
241
+ width: number;
242
+ }
243
+ interface FlemishBondSpec {
244
+ type: "flemishBond";
245
+ /** Length of the long bricks (stretchers). */
246
+ length: number;
247
+ /** Course height. */
248
+ height: number;
249
+ /** Length of the short bricks (headers). Defaults to `length / 2`. */
250
+ header?: number;
251
+ }
252
+ interface ChevronSpec {
253
+ type: "chevron";
254
+ /** Long side of each plank. */
255
+ length: number;
256
+ /** Plank width, measured across the plank. */
257
+ width: number;
258
+ /** Plank slope in degrees from horizontal, between 0 and 90 (exclusive). Defaults to 45. */
259
+ angle?: number;
260
+ }
261
+ interface FishScaleSpec {
262
+ type: "fishScale";
263
+ /** Width of each scale. Scales overlap like roof shingles: rounded below, pointed on top. */
264
+ size: number;
265
+ }
266
+ interface VoronoiSpec {
267
+ type: "voronoi";
268
+ /** Typical cell width: about one cell per size × size area. */
269
+ size: number;
270
+ /** Rounds of Lloyd relaxation; more rounds give more even, rounder cells. Defaults to 2. */
271
+ relax?: number;
272
+ /** Seed for the deterministic random generator. Defaults to 1. */
273
+ seed?: number;
274
+ }
275
+ interface DelaunaySpec {
276
+ type: "delaunay";
277
+ /** Typical spacing of the triangle corners. */
278
+ size: number;
279
+ /** Rounds of Lloyd relaxation on the corners; more rounds give more even triangles. Defaults to 2. */
280
+ relax?: number;
281
+ /** Seed for the deterministic random generator. Defaults to 1. */
282
+ seed?: number;
283
+ }
284
+ interface AshlarSpec {
285
+ type: "ashlar";
286
+ /** Typical course (row) height. */
287
+ height: number;
288
+ /** Shortest stone. */
289
+ minLength: number;
290
+ /** Longest stone. */
291
+ maxLength: number;
292
+ /** How much course heights vary, 0–0.9, as a fraction of `height`. Defaults to 0. */
293
+ heightVariation?: number;
294
+ /** Seed for the deterministic random generator. Defaults to 1. */
295
+ seed?: number;
296
+ }
297
+ interface PenroseSpec {
298
+ type: "penrose";
299
+ /** Edge length of the rhombs, or the long edge of the kites and darts. */
300
+ size: number;
301
+ /**
302
+ * "rhombs" (P3: thick and thin rhombs, all convex) or "kitesAndDarts" (P2: convex kites
303
+ * and non-convex darts). Defaults to "rhombs".
304
+ */
305
+ variant?: "rhombs" | "kitesAndDarts";
306
+ }
307
+ interface HatSpec {
308
+ type: "hat";
309
+ /** Approximate width of each hat (its widest extent). */
310
+ size: number;
311
+ }
312
+ interface SpectreSpec {
313
+ type: "spectre";
314
+ /** Approximate width of each spectre (its widest extent). */
315
+ size: number;
316
+ }
317
+ interface IsohedralSpec {
318
+ type: "isohedral";
319
+ /** Isohedral type number (see `isohedralTypes`; 81 of the 93 types). */
320
+ ih: number;
321
+ /** Approximate tile width (its widest extent). */
322
+ size: number;
323
+ /** Shape parameters moving the tile's corners; see `isohedralInfo(ih)`. Defaults per type. */
324
+ params?: number[];
325
+ /**
326
+ * Edge curves: "wave" (default) or "straight", or one curve per edge class (see
327
+ * `isohedralInfo(ih).edgeKinds`) as points strictly between (0,0) and (1,0). Curves for
328
+ * "S" and "U" edges describe the first half of the edge; "I" edges are always straight.
329
+ */
330
+ edges?: "wave" | "straight" | Vec[][];
331
+ /**
332
+ * Height of the "wave" curves, as a fraction of each edge. Defaults to 0.15, lowered for
333
+ * the few types where that would make the tile overlap itself.
334
+ */
335
+ amount?: number;
336
+ }
337
+ interface JigsawSpec {
338
+ type: "jigsaw";
339
+ /** Target piece size; columns and rows are chosen so pieces fit the region exactly. */
340
+ size: number;
341
+ /** Seed for tab directions and positions. Defaults to 1. */
342
+ seed?: number;
343
+ }
344
+ /**
345
+ * A custom repeating tiling: the motif's polygons are copied to every point i·a + j·b.
346
+ * Coordinates are in region units. Nothing checks that the copies fit together; use
347
+ * `checkPeriodic` while designing one. Polygons may be non-convex but must be simple.
348
+ */
349
+ interface PeriodicSpec {
350
+ type: "periodic";
351
+ a: Vec;
352
+ b: Vec;
353
+ /** Tiles of one lattice cell. `protoTile` defaults to the tile's position in this list. */
354
+ motif: {
355
+ polygon: Polygon;
356
+ protoTile?: number;
357
+ }[];
358
+ }
359
+ /**
360
+ * Explicit tiles, used as given (in region units): nothing is generated, and `rotation`
361
+ * and `origin` are ignored. The usual gap, margin, edge, rounding and neighbor handling
362
+ * applies. Ids default to "t0", "t1", …; given ids must be unique.
363
+ */
364
+ interface TilesSpec {
365
+ type: "tiles";
366
+ tiles: {
367
+ polygon: Polygon;
368
+ id?: string;
369
+ protoTile?: number;
370
+ }[];
371
+ }
372
+ interface MondrianSpec {
373
+ type: "mondrian";
374
+ /** No side is cut shorter than this. */
375
+ minSize: number;
376
+ /** Cells larger than this along either side are always split further (when possible). */
377
+ maxSize: number;
378
+ /** Chance (0–1) of splitting a cell that already fits within `maxSize`. Defaults to 0.4. */
379
+ splitChance?: number;
380
+ /** Seed for the deterministic random generator. Defaults to 1. */
381
+ seed?: number;
382
+ /** Snap split positions to multiples of this value (relative to each cell). */
383
+ snap?: number;
384
+ }
385
+ type TilingSpec = FlowSpec | GridSpec | RunningBondSpec | HerringboneSpec | BasketweaveSpec | HexagonalSpec | TriangularSpec | RhombilleSpec | OctagonSquareSpec | TrihexagonalSpec | RhombitrihexagonalSpec | CairoSpec | HopscotchSpec | PinwheelSpec | FlemishBondSpec | ChevronSpec | FishScaleSpec | VoronoiSpec | DelaunaySpec | AshlarSpec | PenroseSpec | HatSpec | SpectreSpec | IsohedralSpec | JigsawSpec | PeriodicSpec | TilesSpec | MondrianSpec;
386
+ type TilingType = TilingSpec["type"];
387
+ declare const grid: (p: Omit<GridSpec, "type">) => GridSpec;
388
+ declare const runningBond: (p: Omit<RunningBondSpec, "type">) => RunningBondSpec;
389
+ declare const herringbone: (p: Omit<HerringboneSpec, "type">) => HerringboneSpec;
390
+ declare const basketweave: (p: Omit<BasketweaveSpec, "type">) => BasketweaveSpec;
391
+ declare const hexagonal: (p: Omit<HexagonalSpec, "type">) => HexagonalSpec;
392
+ declare const triangular: (p: Omit<TriangularSpec, "type">) => TriangularSpec;
393
+ declare const rhombille: (p: Omit<RhombilleSpec, "type">) => RhombilleSpec;
394
+ declare const octagonSquare: (p: Omit<OctagonSquareSpec, "type">) => OctagonSquareSpec;
395
+ declare const trihexagonal: (p: Omit<TrihexagonalSpec, "type">) => TrihexagonalSpec;
396
+ declare const rhombitrihexagonal: (p: Omit<RhombitrihexagonalSpec, "type">) => RhombitrihexagonalSpec;
397
+ declare const cairo: (p: Omit<CairoSpec, "type">) => CairoSpec;
398
+ declare const hopscotch: (p: Omit<HopscotchSpec, "type">) => HopscotchSpec;
399
+ declare const pinwheel: (p: Omit<PinwheelSpec, "type">) => PinwheelSpec;
400
+ declare const flemishBond: (p: Omit<FlemishBondSpec, "type">) => FlemishBondSpec;
401
+ declare const chevron: (p: Omit<ChevronSpec, "type">) => ChevronSpec;
402
+ declare const fishScale: (p: Omit<FishScaleSpec, "type">) => FishScaleSpec;
403
+ declare const hat: (p: Omit<HatSpec, "type">) => HatSpec;
404
+ declare const spectre: (p: Omit<SpectreSpec, "type">) => SpectreSpec;
405
+ declare const isohedral: (p: Omit<IsohedralSpec, "type">) => IsohedralSpec;
406
+ declare const jigsaw: (p: Omit<JigsawSpec, "type">) => JigsawSpec;
407
+ declare const voronoi: (p: Omit<VoronoiSpec, "type">) => VoronoiSpec;
408
+ declare const delaunay: (p: Omit<DelaunaySpec, "type">) => DelaunaySpec;
409
+ declare const ashlar: (p: Omit<AshlarSpec, "type">) => AshlarSpec;
410
+ declare const penrose: (p: Omit<PenroseSpec, "type">) => PenroseSpec;
411
+ declare const periodic: (p: Omit<PeriodicSpec, "type">) => PeriodicSpec;
412
+ declare const tiles: (p: Omit<TilesSpec, "type">) => TilesSpec;
413
+ declare const mondrian: (p: Omit<MondrianSpec, "type">) => MondrianSpec;
414
+ /** Andamento: tesserae in rows following guide curves, centers or the region's outline. See `FlowSpec`. */
415
+ declare const flow: (p: Omit<FlowSpec, "type">) => FlowSpec;
416
+ /** A tile as produced by a generator, before gap/clipping is applied. */
417
+ interface RawTile {
418
+ /** Stable identifier, unique within one generated layout. */
419
+ id: string;
420
+ polygon: Polygon;
421
+ /** Index of the prototile this tile is a copy of (e.g. herringbone: 0 = horizontal, 1 = vertical). */
422
+ protoTile: number;
423
+ }
424
+ interface GenerateContext {
425
+ /** Area that must be covered. */
426
+ region: Polygon;
427
+ /** Pattern rotation in degrees. */
428
+ rotation: number;
429
+ /** Where the pattern's local origin sits. */
430
+ origin: Vec;
431
+ /** Safety cap on the number of tiles generated. */
432
+ maxTiles: number;
433
+ /**
434
+ * For generators that can vary their tile size smoothly (Voronoi, Delaunay): the size
435
+ * wanted at a point, as a factor (at most 1) of the spec's size.
436
+ */
437
+ sizeAt?: (p: Vec) => number;
438
+ /** The exact area to tile (outline and holes, less margin), for generators that follow it. */
439
+ outline?: Polygon[];
440
+ /** Layout units per generator unit (the pattern scale), for specs given in layout units. */
441
+ unit?: number;
442
+ }
443
+ /**
444
+ * A periodic tiling: a motif of prototiles repeated at every point
445
+ * i·a + j·b of a lattice.
446
+ */
447
+ interface PeriodicDefinition {
448
+ a: Vec;
449
+ b: Vec;
450
+ motif: {
451
+ polygon: Polygon;
452
+ protoTile: number;
453
+ }[];
454
+ }
455
+ /** Tilings generated procedurally (seeded) rather than from a repeating motif. */
456
+ type ProceduralSpec = MondrianSpec | VoronoiSpec | DelaunaySpec | AshlarSpec | JigsawSpec | FlowSpec;
457
+ declare function periodicDefinition(spec: Exclude<TilingSpec, ProceduralSpec | PenroseSpec | HatSpec | SpectreSpec | IsohedralSpec | TilesSpec>): PeriodicDefinition;
458
+ /** Enumerate every lattice copy of the motif that can touch `ctx.region`. */
459
+ declare function generatePeriodic(def: PeriodicDefinition, ctx: GenerateContext): RawTile[];
460
+ /**
461
+ * Random recursive guillotine partition of the region's bounding box.
462
+ * Rotation and origin are ignored: Mondrian layouts are always axis-aligned to the region.
463
+ */
464
+ declare function generateMondrian(spec: MondrianSpec, ctx: GenerateContext): RawTile[];
465
+ declare function generateTiles(spec: TilingSpec, ctx: GenerateContext): RawTile[];
466
+ interface PeriodicCheck {
467
+ /** True when no gaps, overlaps or self-intersecting tiles were found. */
468
+ ok: boolean;
469
+ /** Area of one lattice cell, |a × b|, and the motif's total area (equal for a tiling). */
470
+ cellArea: number;
471
+ motifArea: number;
472
+ /** Fraction of sample points covered by no tile, and by more than one. */
473
+ gaps: number;
474
+ overlaps: number;
475
+ /** Motif indices whose outline crosses itself. */
476
+ selfIntersecting: number[];
477
+ }
478
+ /**
479
+ * Check a custom periodic tiling by sampling one lattice cell: every point should be
480
+ * covered by exactly one copy of one motif tile. Sampling can miss slivers narrower than
481
+ * the sample spacing (`samples` points per side, default 60).
482
+ */
483
+ declare function checkPeriodic(spec: PeriodicSpec | PeriodicDefinition, samples?: number): PeriodicCheck;
484
+
485
+ /**
486
+ * How a tiling edge may be shaped:
487
+ * - "J": any curve.
488
+ * - "S": looks the same after a 180° turn (like the letter S).
489
+ * - "U": looks the same mirrored across its midpoint (like the letter U).
490
+ * - "I": straight.
491
+ */
492
+ type EdgeKind = "J" | "S" | "U" | "I";
493
+ /** The isohedral types available (IH numbers; 81 of the 93 have freely shaped tiles). */
494
+ declare const isohedralTypes: readonly number[];
495
+ interface IsohedralInfo {
496
+ /** Number of shape parameters, which move the tile's corners. */
497
+ numParameters: number;
498
+ defaultParameters: number[];
499
+ /** Shape constraint of each edge class, in the order `edges` curves are given. */
500
+ edgeKinds: EdgeKind[];
501
+ /** Number of tile corners (tiling vertices). */
502
+ numVertices: number;
503
+ }
504
+ /** Parameters and edge constraints of an isohedral type, for building UIs. */
505
+ declare function isohedralInfo(ih: number): IsohedralInfo;
506
+ /**
507
+ * The prototile outline (in Tactile's coordinates) for a spec. Without an explicit
508
+ * `amount`, the "wave" curves start at 0.15 and are lowered until the outline doesn't
509
+ * cross itself (a few types with short edges or sharp corners need less).
510
+ */
511
+ declare function isohedralPrototile(spec: Omit<IsohedralSpec, "type" | "size">): Polygon;
512
+
513
+ /**
514
+ * How tiles at the edge of the region are treated.
515
+ * - "clip": cut tiles to the region outline (a full-bleed look).
516
+ * - "inside": keep only tiles that fit entirely inside the region.
517
+ * - "overflow": keep every tile that touches the region, uncut.
518
+ * - "window": tiles stay whole and the region is a window onto them: renderers shape,
519
+ * round, bevel and fill each tile as the whole tile (`Cell.tile`) and hide
520
+ * what falls outside the region (`Layout.view`). A cut edge is a straight
521
+ * line through the tile, not a new corner.
522
+ */
523
+ type EdgeMode = "clip" | "inside" | "overflow" | "window";
524
+ interface LayoutOptions {
525
+ /**
526
+ * The area to tile: a rectangle or any simple polygon (convex or not; it mustn't cross
527
+ * itself), in your own units (cm, px, in…).
528
+ */
529
+ region: Rect | Polygon;
530
+ /**
531
+ * Areas inside the region to leave empty: windows, doors, sockets. Rectangles or
532
+ * simple polygons; they may overlap each other or the region's edge. Tiles are cut
533
+ * around them (or skipped, with `edges: "inside"`), and `margin` applies around them too.
534
+ */
535
+ holes?: (Rect | Polygon)[];
536
+ tiling: TilingSpec;
537
+ /** Space between neighboring tiles. Defaults to 0. */
538
+ gap?: number;
539
+ /** Empty border kept between the region outline (and any holes) and the tiles. Defaults to 0. */
540
+ margin?: number;
541
+ /** Pattern rotation in degrees (ignored by the random patterns: mondrian, voronoi, delaunay, ashlar, jigsaw). Defaults to 0. */
542
+ rotation?: number;
543
+ /**
544
+ * Shifts the pattern (ignored by the random patterns). For penrose this is where the
545
+ * ten-fold star at the pattern's center sits. Defaults to the top-left of the region.
546
+ */
547
+ origin?: Vec;
548
+ /** Defaults to "clip". */
549
+ edges?: EdgeMode;
550
+ /**
551
+ * Drop edge tiles that end up smaller than this fraction (0–1) of a full tile,
552
+ * so you don't get slivers. Applies to "clip", "overflow" and "window". Defaults to 0.
553
+ */
554
+ minFill?: number;
555
+ /**
556
+ * Round every tile corner with this radius, in region units. Corners too small
557
+ * for the full radius get the largest radius that fits. Defaults to 0 (sharp).
558
+ * Rounding is applied when rendering; `Cell.polygon`, `area` and `centroid`
559
+ * describe the sharp-cornered shape.
560
+ */
561
+ cornerRadius?: number;
562
+ /**
563
+ * Scale the whole pattern (every tile size in the tiling spec) by this factor, about
564
+ * the pattern origin. Handy for fitting a tile count without knowing which size
565
+ * parameters a pattern has; see `fitCount`. Defaults to 1.
566
+ */
567
+ tileScale?: number;
568
+ /**
569
+ * Featured tiles: groups of neighboring tiles merged into one bigger cell, e.g. for a
570
+ * hero image. Merging happens before the gap and edge handling, so a featured cell gets
571
+ * the same gap all round as any other. See `Feature`.
572
+ */
573
+ features?: Feature[];
574
+ /**
575
+ * Vary the tile size across the region: the size wanted at each point, as a factor of the
576
+ * tiling's own size (1 as given, 0.5 half as big, 2 twice). Voronoi and Delaunay change
577
+ * size smoothly; other tilings are generated at the largest size wanted and, where tiles
578
+ * should be smaller, replaced by the same tiling at half the scale (again and again, down
579
+ * to the smallest), cut to fit. Grids and other tilings that halve exactly nest without
580
+ * cuts. See `radialSize`, `edgeSize` and `imageSize`.
581
+ */
582
+ sizeAt?: (point: Vec) => number;
583
+ /** Safety cap on generated tiles. Defaults to 20000. */
584
+ maxTiles?: number;
585
+ }
586
+ /**
587
+ * A featured tile: `tiles` neighboring tiles merged into one cell. The group grows from
588
+ * a tile near `at`, adding whichever neighbor keeps it most compact (so 4 grid tiles make
589
+ * a 2 × 2 square, 7 hexagons a flower); several starting tiles are tried and the most
590
+ * compact group kept, near `at` and avoiding tiles the region edge cuts. Features don't
591
+ * share tiles: a later one grows among the tiles still free.
592
+ */
593
+ interface Feature {
594
+ /** How many tiles to merge. Defaults to 4. Fewer are merged if the group runs out of room. */
595
+ tiles?: number;
596
+ /** Where the group starts, in region units. Defaults to the middle of the region. */
597
+ at?: Vec;
598
+ /**
599
+ * Exact tile ids to merge instead (from a layout without features; ids are stable).
600
+ * Overrides `tiles` and `at`. Tiles that aren't in the layout or are already taken are skipped.
601
+ */
602
+ ids?: string[];
603
+ /**
604
+ * Which content item (by position) goes in this featured cell. By default featured cells
605
+ * take the first items, in `features` order. See `weightedLayout`.
606
+ */
607
+ item?: number;
608
+ }
609
+ interface Cell {
610
+ /** Stable id derived from the tile's position in the pattern. */
611
+ id: string;
612
+ /** Position in reading order (top-to-bottom, then left-to-right). Use it to assign content to cells. */
613
+ index: number;
614
+ /** Visible shape: after gap and edge handling. */
615
+ polygon: Polygon;
616
+ /**
617
+ * Holes in the visible shape, when a region hole lies wholly inside the tile. Absent
618
+ * otherwise. `area` and `centroid` account for them.
619
+ */
620
+ holes?: Polygon[];
621
+ /** The full pattern tile before gap and edge handling. */
622
+ original: Polygon;
623
+ /**
624
+ * With `edges: "window"`, for a cell the region outline cuts: the whole tile (after the
625
+ * gap), which renderers shape, round and fill, letting the region hide the rest. `polygon`
626
+ * is still the visible part (its largest piece, when the outline cuts the tile in two).
627
+ * See `cellShape` and `visibleShapes`.
628
+ */
629
+ tile?: Polygon;
630
+ bbox: Rect;
631
+ centroid: Vec;
632
+ area: number;
633
+ /** The tile crosses the region outline (it was cut in "clip" mode, or sticks out in "overflow"). */
634
+ boundary: boolean;
635
+ /** Which prototile this is a copy of (e.g. herringbone: 0 horizontal, 1 vertical). */
636
+ protoTile: number;
637
+ /** Ids of cells that share an edge with this one in the underlying pattern. */
638
+ neighbors: string[];
639
+ /** For a featured cell: its position in `features`. Featured cells get content first. */
640
+ featured?: number;
641
+ /** For a featured cell: the content item it's for, when its feature names one (`Feature.item`). */
642
+ featuredItem?: number;
643
+ /** For a featured cell: ids of the tiles merged into it. */
644
+ merged?: string[];
645
+ }
646
+ interface Layout {
647
+ /** The region outline (before margin). */
648
+ region: Polygon;
649
+ /** The region's holes (before margin), positively oriented. */
650
+ holes: Polygon[];
651
+ /** Bounding box of the region; a good SVG viewBox. */
652
+ bounds: Rect;
653
+ /** Corner radius renderers apply to every cell (0 for sharp corners). */
654
+ cornerRadius: number;
655
+ /**
656
+ * With `edges: "window"`: the area tiles show in (the region less its margin and holes).
657
+ * Renderers hide whatever part of a tile lies outside it.
658
+ */
659
+ view?: Shape[];
660
+ cells: Cell[];
661
+ }
662
+ declare function createLayout(options: LayoutOptions): Layout;
663
+ /**
664
+ * Greedy graph coloring over cell adjacency: neighboring cells get different
665
+ * color indices. Handy for placeholder fills. Returns one index per cell (by cell.index).
666
+ */
667
+ declare function colorCells(layout: Layout, colors: number): number[];
668
+
669
+ interface SafeAreaOptions {
670
+ /**
671
+ * Width / height the area must have (an image or card of known shape, say). Omit for
672
+ * the largest-area rectangle of any shape (for text and other content that reflows).
673
+ */
674
+ aspect?: number;
675
+ /**
676
+ * For a cell an `edges: "window"` layout cuts: "tile" (the default) fits the whole tile,
677
+ * as if the region weren't there, so content near the edge is partly hidden like the
678
+ * tile; "visible" fits the part that shows. Other cells are the same either way.
679
+ */
680
+ within?: "tile" | "visible";
681
+ }
682
+ /**
683
+ * The largest axis-aligned rectangle that fits wholly inside a cell's shape (its outline,
684
+ * holes and rounded corners), so content placed there isn't clipped. With `aspect`, the
685
+ * largest rectangle of that shape. Among equally large positions it picks the one nearest
686
+ * the cell's center. In layout coordinates; see `safeAreaCss` for CSS.
687
+ *
688
+ * Works for any shape, convex or not. Results are cached per cell.
689
+ */
690
+ declare function safeArea(cell: Cell, layout: Pick<Layout, "cornerRadius" | "view">, options?: SafeAreaOptions): Rect;
691
+
692
+ /**
693
+ * CSS placement for one cell, as percentages of the layout bounds, so the result
694
+ * scales with whatever size the container is rendered at.
695
+ *
696
+ * Apply to an absolutely positioned element inside a `position: relative`
697
+ * container whose aspect ratio matches `layout.bounds`
698
+ * (see `boundsAspectRatio`). Works with any framework, or none.
699
+ */
700
+ interface CellCss {
701
+ left: string;
702
+ top: string;
703
+ width: string;
704
+ height: string;
705
+ /** A `polygon(...)` clip path relative to the element's own box. */
706
+ clipPath: string;
707
+ }
708
+ /**
709
+ * `polygon(...)` for `poly`, expressed as percentages of `box`. With `holes`, it's an
710
+ * even–odd polygon that visits each hole from the outline's first point and comes back,
711
+ * so the connecting lines cancel out.
712
+ */
713
+ declare function cssPolygon(poly: Polygon, box: Rect, precision?: number, holes?: Polygon[]): string;
714
+ /**
715
+ * `poly` with points added along its edges to make exactly `n`, keeping every original
716
+ * vertex, so any two shapes can be morphed point by point (CSS transitions only interpolate
717
+ * `polygon()` values with the same number of points). The points run the same way round
718
+ * for every shape and start at the corner nearest the top left of `box`, so a shape
719
+ * morphs into another without twisting. A polygon with more than `n` points is returned
720
+ * as it is.
721
+ */
722
+ declare function resamplePolygon(poly: Polygon, n: number, box: Rect): Polygon;
723
+ /**
724
+ * `poly` with its corners rounded (by `radius`, or a radius per corner) as at least `n`
725
+ * points, laid out the same way whatever the radius: each corner gets a fixed number of
726
+ * points by how far the outline turns there (one per 10°, all on the vertex when it's sharp,
727
+ * spread along the arc when it's rounded), and the rest go along the edges by the sharp
728
+ * outline's edge lengths. So a tile morphs smoothly as its corner radius changes, as well as
729
+ * into other shapes (see `resamplePolygon` for the start point and direction). Shapes with
730
+ * too many corners for `n` (merged featured tiles, say) get more points: the next multiple
731
+ * of 24 that fits, so most tiles share one count and can morph into each other.
732
+ */
733
+ declare function morphPolygon(poly: Polygon, radius: number | readonly number[], n: number, box: Rect): Polygon;
734
+ /** Options for `cellCss`. */
735
+ interface CellCssOptions {
736
+ /**
737
+ * Give every clip path this many points (see `morphPolygon`), so CSS can animate one tile
738
+ * shape into another. Shapes with many corners (merged featured tiles) get more, in steps
739
+ * of 24; cells with holes keep their own.
740
+ */
741
+ points?: number;
742
+ }
743
+ /**
744
+ * `polygon(...)` for several shapes (outlines with holes) at once: an even–odd polygon
745
+ * that visits each extra loop from the first outline's first point and comes back.
746
+ */
747
+ declare function cssShapes(shapes: readonly Shape[], box: Rect, precision?: number): string;
748
+ /**
749
+ * CSS placement for `cell` within `layout`, including rounded corners if the layout has
750
+ * them. A window cell (see `cellShape`) is placed over its whole tile and clipped to the
751
+ * part of it inside `layout.view`.
752
+ */
753
+ declare function cellCss(cell: Cell, layout: Layout, precision?: number, options?: CellCssOptions): CellCss;
754
+ /**
755
+ * Placement, inside a cell's element (as positioned by `cellCss`), of a box covering the
756
+ * whole layout bounds. Put the same content (an image with `object-fit: cover`, say) in
757
+ * every cell at this placement and the cells together show it as one picture, each
758
+ * through its own window.
759
+ */
760
+ declare function backdropCss(cell: Cell, layout: Layout, precision?: number): Omit<CellCss, "clipPath">;
761
+ /**
762
+ * Placement, inside a cell's element (as positioned by `cellCss`), of the cell's safe area
763
+ * (see `safeArea`): the largest rectangle that isn't clipped by the tile's shape.
764
+ */
765
+ declare function safeAreaCss(cell: Cell, layout: Layout, options?: SafeAreaOptions, precision?: number): Omit<CellCss, "clipPath">;
766
+ /** `polygon(...)` for the layout's region, with its holes, relative to the bounds. */
767
+ declare function regionCss(layout: Layout, precision?: number): string;
768
+ /**
769
+ * `polygon(...)` for the area tiles show in, relative to the bounds: `layout.view` in a
770
+ * window layout, else the region with its holes.
771
+ */
772
+ declare function viewCss(layout: Layout, precision?: number): string;
773
+ /** Value for the CSS `aspect-ratio` property of a container holding `layout`. */
774
+ declare function boundsAspectRatio(layout: Layout): string;
775
+
776
+ export { bbox as $, type AshlarSpec as A, type BasketweaveSpec as B, type Cell as C, type DelaunaySpec as D, type EdgeKind as E, type Feature as F, type GenerateContext as G, type HatSpec as H, type IsohedralInfo as I, type JigsawSpec as J, type TilingSpec as K, type Layout as L, type MondrianSpec as M, type TilingType as N, type OctagonSquareSpec as O, type Polygon as P, type TriangularSpec as Q, type Rect as R, type Shape as S, type TilesSpec as T, type TrihexagonalSpec as U, type Vec as V, type VoronoiSpec as W, area as X, ashlar as Y, backdropCss as Z, basketweave as _, type RawTile as a, length as a$, boundsAspectRatio as a0, cairo as a1, cellCss as a2, centroid as a3, checkPeriodic as a4, chevron as a5, colorCells as a6, createLayout as a7, cssShapes as a8, delaunay as a9, safeArea as aA, safeAreaCss as aB, spectre as aC, tiles as aD, triangular as aE, trihexagonal as aF, vec as aG, viewCss as aH, voronoi as aI, add as aJ, cleanPolygon as aK, clipConvex as aL, clipHalfPlane as aM, clipPolygonToConvex as aN, containsPolygon as aO, convexHull as aP, cross as aQ, cssPolygon as aR, dot as aS, ensurePositive as aT, generateMondrian as aU, generatePeriodic as aV, generateTiles as aW, insetConvex as aX, insetPolygonPieces as aY, isConvex as aZ, isohedralPrototile as a_, fishScale as aa, flemishBond as ab, flow as ac, grid as ad, hat as ae, herringbone as af, hexagonal as ag, hopscotch as ah, insetPolygon as ai, isohedral as aj, isohedralInfo as ak, isohedralTypes as al, jigsaw as am, mondrian as an, morphPolygon as ao, octagonSquare as ap, overlay as aq, penrose as ar, periodic as as, periodicDefinition as at, pinwheel as au, rectPolygon as av, regionCss as aw, rhombille as ax, rhombitrihexagonal as ay, runningBond as az, type LayoutOptions as b, outsetPolygon as b0, partition as b1, pointInPolygon as b2, rectsOverlap as b3, resamplePolygon as b4, scale as b5, shapeArea as b6, shapeCentroid as b7, sharesEdge as b8, signedArea as b9, splitSelfIntersections as ba, sub as bb, transform as bc, type CairoSpec as c, type CellCss as d, type CellCssOptions as e, type ChevronSpec as f, type EdgeMode as g, type FishScaleSpec as h, type FlemishBondSpec as i, type FlowSpec as j, type GridSpec as k, type HerringboneSpec as l, type HexagonalSpec as m, type HopscotchSpec as n, type IsohedralSpec as o, type PenroseSpec as p, type PeriodicCheck as q, type PeriodicDefinition as r, type PeriodicSpec as s, type PinwheelSpec as t, type ProceduralSpec as u, type RhombilleSpec as v, type RhombitrihexagonalSpec as w, type RunningBondSpec as x, type SafeAreaOptions as y, type SpectreSpec as z };