@mark1russell7/layout-contract 0.11.0 → 0.11.2

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.
@@ -144,6 +144,44 @@ declare function nearestOnSegment(p: Point, a: Point, b: Point): Point;
144
144
  * The hit test of a route uses it with the polyline of `samplePath`.
145
145
  */
146
146
  declare function pointPolylineDistance(p: Point, points: readonly Point[]): number;
147
+ /** The place on a polyline nearest to a point, from `locateOnPolyline`. */
148
+ interface PolylinePlace {
149
+ /** The point of the polyline nearest to the point. */
150
+ readonly point: Point;
151
+ /** The length of the polyline from its first point to `point`. */
152
+ readonly along: number;
153
+ /** The distance from the point to `point`. It is the same float as `pointPolylineDistance`. */
154
+ readonly distance: number;
155
+ /** The index of the first point of the segment of `point`. A polyline of one point gives 0. */
156
+ readonly segment: number;
157
+ /**
158
+ * The side of the point: the exact sign of the cross product of the segment and the vector from its start to the point.
159
+ * A point on the line of the segment gives 0. A polyline of one point gives 0.
160
+ */
161
+ readonly side: -1 | 0 | 1;
162
+ }
163
+ /**
164
+ * This function gives the place on a polyline nearest to `p`: the point, its length along the polyline, the distance and the side.
165
+ * When two segments are at the same distance, the first segment wins. An empty polyline gives `undefined`.
166
+ * A street address uses it: the length along the street line of each known number, and its side of the street.
167
+ */
168
+ declare function locateOnPolyline(p: Point, points: readonly Point[]): PolylinePlace | undefined;
169
+ /**
170
+ * This function gives the point at the length `along` of a polyline, moved by `offset` at a right angle to its segment.
171
+ * A positive `offset` moves the point to the side 1 of `locateOnPolyline`, and a negative `offset` to the side -1.
172
+ *
173
+ * An `along` less than 0 gives the first point, and an `along` more than the length gives the last point. The offset then uses the segment at that end.
174
+ * Segments of length 0 have no direction, so the offset skips them. A polyline with no direction gives its point with no offset.
175
+ * An empty polyline gives `undefined`.
176
+ */
177
+ declare function pointAlongPolyline(points: readonly Point[], along: number, offset?: number): Point | undefined;
178
+ /**
179
+ * This function joins polylines at their shared end points into longer polylines, for example the ways of one street.
180
+ * Two ends join only when their coordinates are equal. A join reverses a polyline when its direction is opposite.
181
+ * The first polyline that is left starts each chain, and the chain grows at both ends with the first polyline that touches an end.
182
+ * Thus a branch point keeps one branch in the chain, and the other branches start their own chains. An empty polyline gives no chain.
183
+ */
184
+ declare function chainPolylines(lines: readonly (readonly Point[])[]): Point[][];
147
185
  /** A ring of a polygon: its corners in order, as `[x, y]` pairs. The last corner connects to the first. */
148
186
  type Ring = readonly (readonly [number, number])[];
149
187
  /** This function tells if the point (`x`, `y`) is inside a ring, by the even-odd rule. A ring can be concave. The answer for a point on the border can be each value. */
@@ -745,5 +783,5 @@ declare function minEffectOf(spec: Pick<MeasureSpec, "minEffect">, a?: number, b
745
783
  * Two equal values are a tie, also two infinite values. A value `NaN` is an error.
746
784
  */
747
785
  declare function compareMeasure(candidate: number, baseline: number, spec: Pick<MeasureSpec, "direction" | "minEffect">): Verdict;
748
- export { CorpusEntry as $, translate as $t, shapeKindsOf as A, convexCorners as At, LayoutInput as B, pointInRings as Bt, checkShapes as C, SIDES as Ct, ruleLevel as D, boundsOf as Dt, itemShapeOf as E, SizedRect as Et, LayoutBox as F, grow as Ft, PairGap as G, regionArea as Gt, PackInput as H, pointRegionDistance as Ht, LayoutCell as I, marginSides as It, canonicalInput as J, scaleRect as Jt, Port as K, regionPerimeter as Kt, LayoutContainer as L, nearestOnSegment as Lt, shapeSupportProblems as M, cornersInConvex as Mt, shapesOf as N, crossingPoint as Nt, shapeKindOf as O, boxCenterDistance as Ot, Item as P, dropIndex as Pt, ClaimBreak as Q, toSizedRect as Qt, LayoutEdge as R, overlapOf as Rt, boxArea as S, Ring as St, isShapeKind as T, Sides as Tt, PackInputOptions as U, pointSegmentDistance as Ut, Obstacle as V, pointPolylineDistance as Vt, PackLink as W, rectCenter as Wt, portPoint as X, snapRect as Xt, packLinks as Y, segmentsCross as Yt, toPackInput as Z, toRect as Zt, ShapeKind as _, splitFolds as _t, MeasureSpec as a, FamilyCell as at, ShapeLimit as b, Rect as bt, minEffectOf as c, SplitFold as ct, SHAPE_KINDS as d, corpusHashOf as dt, CorpusSplit as et, SHAPE_KIND_IDS as f, declaredClaimOf as ft, ShapeInput as g, splitFileName as gt, ShapeGeometry as h, leaveOneSeedOut as ht, JointMeasureId as i, FamilyBy as it, shapeLevel as j, convexOverlap as jt, shapeKindProblem as k, clipRing as kt, DEFAULT_SHAPES as l, checkDeclared as lt, ShapeCheck as m, familyOf as mt, JOINT_MEASURES as n, Declares as nt, Verdict as o, SPLIT_SCHEMA as ot, ShapeBound as p, declaredCounts as pt, Resize as q, ringCentroid as qt, JOINT_MOVED_MIN as r, FAMILY_ANY_KIND as rt, compareMeasure as s, SplitCorpus as st, Direction as t, DeclaredClaim as tt, RuleLevel as u, checkSplit as ut, ShapeKindSpec as v, Margin as vt, inputShapeLevel as w, Side as wt, ShapeSupport as x, Region as xt, ShapeLevel as y, Point as yt, LayoutGenerator as z, pointInRing as zt };
749
- //# sourceMappingURL=measures-Qii_B6SV.d.ts.map
786
+ export { CorpusEntry as $, segmentsCross as $t, shapeKindsOf as A, chainPolylines as At, LayoutInput as B, nearestOnSegment as Bt, checkShapes as C, Ring as Ct, ruleLevel as D, SizedRect as Dt, itemShapeOf as E, Sides as Et, LayoutBox as F, crossingPoint as Ft, PairGap as G, pointPolylineDistance as Gt, PackInput as H, pointAlongPolyline as Ht, LayoutCell as I, dropIndex as It, canonicalInput as J, rectCenter as Jt, Port as K, pointRegionDistance as Kt, LayoutContainer as L, grow as Lt, shapeSupportProblems as M, convexCorners as Mt, shapesOf as N, convexOverlap as Nt, shapeKindOf as O, boundsOf as Ot, Item as P, cornersInConvex as Pt, ClaimBreak as Q, scaleRect as Qt, LayoutEdge as R, locateOnPolyline as Rt, boxArea as S, Region as St, isShapeKind as T, Side as Tt, PackInputOptions as U, pointInRing as Ut, Obstacle as V, overlapOf as Vt, PackLink as W, pointInRings as Wt, portPoint as X, regionPerimeter as Xt, packLinks as Y, regionArea as Yt, toPackInput as Z, ringCentroid as Zt, ShapeKind as _, splitFolds as _t, MeasureSpec as a, FamilyCell as at, ShapeLimit as b, PolylinePlace as bt, minEffectOf as c, SplitFold as ct, SHAPE_KINDS as d, corpusHashOf as dt, snapRect as en, CorpusSplit as et, SHAPE_KIND_IDS as f, declaredClaimOf as ft, ShapeInput as g, splitFileName as gt, ShapeGeometry as h, leaveOneSeedOut as ht, JointMeasureId as i, FamilyBy as it, shapeLevel as j, clipRing as jt, shapeKindProblem as k, boxCenterDistance as kt, DEFAULT_SHAPES as l, checkDeclared as lt, ShapeCheck as m, familyOf as mt, JOINT_MEASURES as n, toSizedRect as nn, Declares as nt, Verdict as o, SPLIT_SCHEMA as ot, ShapeBound as p, declaredCounts as pt, Resize as q, pointSegmentDistance as qt, JOINT_MOVED_MIN as r, translate as rn, FAMILY_ANY_KIND as rt, compareMeasure as s, SplitCorpus as st, Direction as t, toRect as tn, DeclaredClaim as tt, RuleLevel as u, checkSplit as ut, ShapeKindSpec as v, Margin as vt, inputShapeLevel as w, SIDES as wt, ShapeSupport as x, Rect as xt, ShapeLevel as y, Point as yt, LayoutGenerator as z, marginSides as zt };
787
+ //# sourceMappingURL=measures-DXg0-L2U.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measures-DXg0-L2U.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/measures.ts"],"mappings":";KAGY;;cAGC,gBAAgB;UAEZ;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;;;;;;UAOM;WACN;WACA;WACA;WACA;;;iBAIK,OAAO,MAAM,YAAY;;iBAKzB,YAAY,MAAM,OAAO;;;;;iBAWzB,SAAS,MAAM,OAAO;;;;;;iBAWtB,UAAU,MAAM,MAAM,iBAAiB;;UAMtC;WACN;WACA;WACA;WACA;;;;;;KAOC;WACG;WAAuB;WAAoB;WAAoB;WAAoB;;WAEnF;WACA,QAAQ;WACR,iBAAiB;;WAEjB;WAAyB;WAAqB;WAAqB;;WACnE;WA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;iBAwCpC,YAAY,iBAAiB,SAAS;;;;;iBAQtC,YAAY,KAAK,YAAY;;;;;;;iBAW7B,QAAQ,KAAK;;iBAQb,aAAa,OAAO,KAAK,wBAAwB;;iBAMjD,YAAY,OAAO,KAAK,wBAAwB;;iBAMhD,iBAAiB,KAAK;;iBAWtB,SAAS,KAAK,KAAK,mCAAmC;;UAKrD;;;;;;WAMN;;;;;;;;iBASK,YAAY,OAAO,YAAY,eAAe,gBAAgB,UAAS,aAAkB;;KCtQ7F;;;;;;UAOK,YAAY;WAClB,IAAI;WACJ;WACA,WAAW;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA;aAAgC;;;WAEhC;;WAEA,kBAAkB;;;;;WAKlB,QAAQ;;;KAIP;;;;;cAqBC,yBAAyB,YAAY;;cAcrC;;KAGD;;;;;;iBAOI,YAAY,MAAM,KAAK,2BAA2B,YAAO;;;;;;;iBAezD,eAAe,mBAAmB,kBAAkB,MAAM,KAAK,0CAA0C"}
package/build/text.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as MeasureSpec } from "./measures-Qii_B6SV.js";
1
+ import { a as MeasureSpec } from "./measures-DXg0-L2U.js";
2
2
  /**
3
3
  * The advance function of a host: the width of a run of text in a font, in pixels.
4
4
  * A browser host gives `canvasAdvance(context)`. A test or a server host gives a function of a font file.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/layout-contract",
4
- "version": "0.11.0",
4
+ "version": "0.11.2",
5
5
  "description": "The shared contract of the packing and highways layout engines: the input and record formats, the turn rule, margins, tolerances and hard rules.",
6
6
  "keywords": [
7
7
  "layout",
@@ -11,13 +11,13 @@
11
11
  "contract",
12
12
  "typescript"
13
13
  ],
14
- "homepage": "https://github.com/mark1russell7/layout-contract#readme",
14
+ "homepage": "https://github.com/metrograph-labs/layout-contract#readme",
15
15
  "bugs": {
16
- "url": "https://github.com/mark1russell7/layout-contract/issues"
16
+ "url": "https://github.com/metrograph-labs/layout-contract/issues"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "git+https://github.com/mark1russell7/layout-contract.git",
20
+ "url": "git+https://github.com/metrograph-labs/layout-contract.git",
21
21
  "directory": "packages/layout-contract"
22
22
  },
23
23
  "license": "MIT",
package/src/geometry.ts CHANGED
@@ -390,6 +390,114 @@ export function pointPolylineDistance(p: Point, points: readonly Point[]): numbe
390
390
  return best;
391
391
  }
392
392
 
393
+ /** The place on a polyline nearest to a point, from `locateOnPolyline`. */
394
+ export interface PolylinePlace {
395
+ /** The point of the polyline nearest to the point. */
396
+ readonly point: Point;
397
+ /** The length of the polyline from its first point to `point`. */
398
+ readonly along: number;
399
+ /** The distance from the point to `point`. It is the same float as `pointPolylineDistance`. */
400
+ readonly distance: number;
401
+ /** The index of the first point of the segment of `point`. A polyline of one point gives 0. */
402
+ readonly segment: number;
403
+ /**
404
+ * The side of the point: the exact sign of the cross product of the segment and the vector from its start to the point.
405
+ * A point on the line of the segment gives 0. A polyline of one point gives 0.
406
+ */
407
+ readonly side: -1 | 0 | 1;
408
+ }
409
+
410
+ /**
411
+ * This function gives the place on a polyline nearest to `p`: the point, its length along the polyline, the distance and the side.
412
+ * When two segments are at the same distance, the first segment wins. An empty polyline gives `undefined`.
413
+ * A street address uses it: the length along the street line of each known number, and its side of the street.
414
+ */
415
+ export function locateOnPolyline(p: Point, points: readonly Point[]): PolylinePlace | undefined {
416
+ const first = points[0];
417
+ if (first === undefined) return undefined;
418
+ if (points.length === 1) return { point: first, along: 0, distance: Math.hypot(p.x - first.x, p.y - first.y), segment: 0, side: 0 };
419
+ let best: PolylinePlace | undefined;
420
+ let run = 0;
421
+ for (let i = 1; i < points.length; i++) {
422
+ const a = points[i - 1]!;
423
+ const b = points[i]!;
424
+ const length = Math.hypot(b.x - a.x, b.y - a.y);
425
+ const near = nearestOnSegment(p, a, b);
426
+ const distance = pointSegmentDistance(p, a, b);
427
+ if (best === undefined || distance < best.distance) {
428
+ best = { point: near, along: run + Math.hypot(near.x - a.x, near.y - a.y), distance, segment: i - 1, side: length === 0 ? 0 : (side(a, b, p) as -1 | 0 | 1) };
429
+ }
430
+ run += length;
431
+ }
432
+ return best;
433
+ }
434
+
435
+ /**
436
+ * This function gives the point at the length `along` of a polyline, moved by `offset` at a right angle to its segment.
437
+ * A positive `offset` moves the point to the side 1 of `locateOnPolyline`, and a negative `offset` to the side -1.
438
+ *
439
+ * An `along` less than 0 gives the first point, and an `along` more than the length gives the last point. The offset then uses the segment at that end.
440
+ * Segments of length 0 have no direction, so the offset skips them. A polyline with no direction gives its point with no offset.
441
+ * An empty polyline gives `undefined`.
442
+ */
443
+ export function pointAlongPolyline(points: readonly Point[], along: number, offset = 0): Point | undefined {
444
+ const first = points[0];
445
+ if (first === undefined) return undefined;
446
+ let run = 0;
447
+ let last: { a: Point; b: Point; length: number } | undefined;
448
+ for (let i = 1; i < points.length; i++) {
449
+ const a = points[i - 1]!;
450
+ const b = points[i]!;
451
+ const length = Math.hypot(b.x - a.x, b.y - a.y);
452
+ if (length === 0) continue;
453
+ if (along <= run + length) return offsetPoint(a, b, length, Math.max(0, along - run), offset);
454
+ last = { a, b, length };
455
+ run += length;
456
+ }
457
+ if (last === undefined) return first;
458
+ return offsetPoint(last.a, last.b, last.length, last.length, offset);
459
+ }
460
+
461
+ /** This function gives the point at the length `at` of the segment `ab`, moved by `offset` to the side 1 of the segment. */
462
+ function offsetPoint(a: Point, b: Point, length: number, at: number, offset: number): Point {
463
+ const ux = (b.x - a.x) / length;
464
+ const uy = (b.y - a.y) / length;
465
+ return { x: a.x + at * ux - offset * uy, y: a.y + at * uy + offset * ux };
466
+ }
467
+
468
+ /**
469
+ * This function joins polylines at their shared end points into longer polylines, for example the ways of one street.
470
+ * Two ends join only when their coordinates are equal. A join reverses a polyline when its direction is opposite.
471
+ * The first polyline that is left starts each chain, and the chain grows at both ends with the first polyline that touches an end.
472
+ * Thus a branch point keeps one branch in the chain, and the other branches start their own chains. An empty polyline gives no chain.
473
+ */
474
+ export function chainPolylines(lines: readonly (readonly Point[])[]): Point[][] {
475
+ const same = (a: Point, b: Point): boolean => a.x === b.x && a.y === b.y;
476
+ const rest = lines.filter((line) => line.length > 0).map((line) => [...line]);
477
+ const chains: Point[][] = [];
478
+ for (let chain = rest.shift(); chain !== undefined; chain = rest.shift()) {
479
+ let grew = true;
480
+ while (grew) {
481
+ grew = false;
482
+ for (let i = 0; i < rest.length; i++) {
483
+ const line = rest[i]!;
484
+ const start = chain[0]!;
485
+ const end = chain.at(-1)!;
486
+ if (same(line[0]!, end)) chain = [...chain, ...line.slice(1)];
487
+ else if (same(line.at(-1)!, end)) chain = [...chain, ...line.toReversed().slice(1)];
488
+ else if (same(line.at(-1)!, start)) chain = [...line.slice(0, -1), ...chain];
489
+ else if (same(line[0]!, start)) chain = [...line.toReversed().slice(0, -1), ...chain];
490
+ else continue;
491
+ rest.splice(i, 1);
492
+ grew = true;
493
+ break;
494
+ }
495
+ }
496
+ chains.push(chain);
497
+ }
498
+ return chains;
499
+ }
500
+
393
501
  /** A ring of a polygon: its corners in order, as `[x, y]` pairs. The last corner connects to the first. */
394
502
  export type Ring = readonly (readonly [number, number])[];
395
503
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"measures-Qii_B6SV.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/measures.ts"],"mappings":";KAGY;;cAGC,gBAAgB;UAEZ;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;;;;;;UAOM;WACN;WACA;WACA;WACA;;;iBAIK,OAAO,MAAM,YAAY;;iBAKzB,YAAY,MAAM,OAAO;;;;;iBAWzB,SAAS,MAAM,OAAO;;;;;;iBAWtB,UAAU,MAAM,MAAM,iBAAiB;;UAMtC;WACN;WACA;WACA;WACA;;;;;;KAOC;WACG;WAAuB;WAAoB;WAAoB;WAAoB;;WAEnF;WACA,QAAQ;WACR,iBAAiB;;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