@seatlayer/core 0.31.0 → 0.33.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.
@@ -27,6 +27,15 @@ function accessibilityRingColor(types) {
27
27
  const primary = types?.[0];
28
28
  return primary && ACCESSIBILITY_RING_COLOR[primary] || "#3b82f6";
29
29
  }
30
+ var SEAT_COMMERCIAL_MARKS = [
31
+ { key: "obstructedView", label: "Obstructed view", short: "Obstructed", icon: "\u26D4" },
32
+ { key: "restrictedView", label: "Restricted view", short: "Restricted", icon: "\u{1F441}" },
33
+ { key: "premium", label: "Premium seat", short: "Premium", icon: "\u2605" }
34
+ ];
35
+ var SEAT_COMMERCIAL_LABEL = new Map(SEAT_COMMERCIAL_MARKS.map((mark) => [mark.key, mark]));
36
+ function seatCommercialMeta(key) {
37
+ return SEAT_COMMERCIAL_LABEL.get(key);
38
+ }
30
39
  var LABEL_STYLE_MIN_SIZE = 8;
31
40
  var LABEL_STYLE_MAX_SIZE = 24;
32
41
  var SURROUNDINGS_SHAPE_ROLES = [
@@ -152,6 +161,147 @@ function distributeAlongCubic(path, count, resolution = 192) {
152
161
  return output;
153
162
  }
154
163
 
164
+ // src/core/polygonAnchor.ts
165
+ var MAX_CELLS = 4e3;
166
+ function distanceToSegment(p, a, b) {
167
+ const dx = b.x - a.x;
168
+ const dy = b.y - a.y;
169
+ const denominator = dx * dx + dy * dy;
170
+ const t = denominator ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / denominator)) : 0;
171
+ return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
172
+ }
173
+ function distanceToRings(p, rings) {
174
+ let best = Infinity;
175
+ for (const ring of rings) {
176
+ if (ring.length < 2) continue;
177
+ for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
178
+ const d = distanceToSegment(p, ring[j], ring[i]);
179
+ if (d < best) best = d;
180
+ }
181
+ }
182
+ return best;
183
+ }
184
+ function inRing(p, ring) {
185
+ let inside = false;
186
+ for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
187
+ const xi = ring[i].x;
188
+ const yi = ring[i].y;
189
+ const xj = ring[j].x;
190
+ const yj = ring[j].y;
191
+ const hit = yi > p.y !== yj > p.y && p.x < (xj - xi) * (p.y - yi) / (yj - yi) + xi;
192
+ if (hit) inside = !inside;
193
+ }
194
+ return inside;
195
+ }
196
+ function signedDistance(p, outer, holes) {
197
+ const inside = inRing(p, outer) && !holes.some((hole) => inRing(p, hole));
198
+ const distance = distanceToRings(p, [outer, ...holes]);
199
+ return inside ? distance : -distance;
200
+ }
201
+ function cellAt(x, y, h, outer, holes) {
202
+ const d = signedDistance({ x, y }, outer, holes);
203
+ return { x, y, h, d, max: d + h * Math.SQRT2 };
204
+ }
205
+ var CellQueue = class {
206
+ constructor() {
207
+ this.items = [];
208
+ }
209
+ get size() {
210
+ return this.items.length;
211
+ }
212
+ push(cell) {
213
+ const items = this.items;
214
+ items.push(cell);
215
+ let index = items.length - 1;
216
+ while (index > 0) {
217
+ const parent = index - 1 >> 1;
218
+ if (items[parent].max >= items[index].max) break;
219
+ [items[parent], items[index]] = [items[index], items[parent]];
220
+ index = parent;
221
+ }
222
+ }
223
+ pop() {
224
+ const items = this.items;
225
+ const top = items[0];
226
+ const last = items.pop();
227
+ if (items.length && last) {
228
+ items[0] = last;
229
+ let index = 0;
230
+ for (; ; ) {
231
+ const left = index * 2 + 1;
232
+ const right = left + 1;
233
+ let best = index;
234
+ if (left < items.length && items[left].max > items[best].max) best = left;
235
+ if (right < items.length && items[right].max > items[best].max) best = right;
236
+ if (best === index) break;
237
+ [items[best], items[index]] = [items[index], items[best]];
238
+ index = best;
239
+ }
240
+ }
241
+ return top;
242
+ }
243
+ };
244
+ function polygonArea(ring) {
245
+ if (ring.length < 3) return 0;
246
+ let sum = 0;
247
+ for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
248
+ sum += (ring[j].x + ring[i].x) * (ring[j].y - ring[i].y);
249
+ }
250
+ return Math.abs(sum) / 2;
251
+ }
252
+ function polygonNetArea(outer, holes) {
253
+ return Math.max(0, polygonArea(outer) - (holes ?? []).reduce((total, hole) => total + polygonArea(hole), 0));
254
+ }
255
+ function polygonInscribedAnchor(outer, holes) {
256
+ const rings = holes ?? [];
257
+ if (!outer.length) return { point: { x: 0, y: 0 }, radius: 0 };
258
+ if (outer.length < 3) {
259
+ const x = outer.reduce((total, p) => total + p.x, 0) / outer.length;
260
+ const y = outer.reduce((total, p) => total + p.y, 0) / outer.length;
261
+ return { point: { x, y }, radius: 0 };
262
+ }
263
+ let minX = Infinity;
264
+ let minY = Infinity;
265
+ let maxX = -Infinity;
266
+ let maxY = -Infinity;
267
+ for (const p of outer) {
268
+ if (p.x < minX) minX = p.x;
269
+ if (p.y < minY) minY = p.y;
270
+ if (p.x > maxX) maxX = p.x;
271
+ if (p.y > maxY) maxY = p.y;
272
+ }
273
+ const width = maxX - minX;
274
+ const height = maxY - minY;
275
+ const cellSize = Math.min(width, height);
276
+ if (!(cellSize > 0)) {
277
+ return { point: { x: (minX + maxX) / 2, y: (minY + maxY) / 2 }, radius: 0 };
278
+ }
279
+ const precision = Math.max(width, height) / 150;
280
+ const queue = new CellQueue();
281
+ let h = cellSize / 2;
282
+ for (let x = minX; x < maxX; x += cellSize) {
283
+ for (let y = minY; y < maxY; y += cellSize) {
284
+ queue.push(cellAt(x + h, y + h, h, outer, rings));
285
+ }
286
+ }
287
+ let best = cellAt(minX + width / 2, minY + height / 2, 0, outer, rings);
288
+ let explored = 0;
289
+ while (queue.size) {
290
+ const cell = queue.pop();
291
+ if (!cell) break;
292
+ if (cell.d > best.d) best = cell;
293
+ if (cell.max - best.d <= precision) continue;
294
+ if (explored >= MAX_CELLS) continue;
295
+ explored += 1;
296
+ h = cell.h / 2;
297
+ queue.push(cellAt(cell.x - h, cell.y - h, h, outer, rings));
298
+ queue.push(cellAt(cell.x + h, cell.y - h, h, outer, rings));
299
+ queue.push(cellAt(cell.x - h, cell.y + h, h, outer, rings));
300
+ queue.push(cellAt(cell.x + h, cell.y + h, h, outer, rings));
301
+ }
302
+ return { point: { x: best.x, y: best.y }, radius: Math.max(0, best.d) };
303
+ }
304
+
155
305
  // src/core/sectionPath.ts
156
306
  var TAU = Math.PI * 2;
157
307
  function translateSectionOutlinePath(path, dx, dy) {
@@ -860,38 +1010,7 @@ function pointInPolygonWithHoles(p, outer, holes) {
860
1010
  return pointInPolygon(p, outer) && !(holes ?? []).some((hole) => pointInPolygon(p, hole) || pointOnPolygonBoundary(p, hole));
861
1011
  }
862
1012
  function polygonLabelPoint(outer, holes) {
863
- if (!outer.length) return { x: 0, y: 0 };
864
- const xs = outer.map((point) => point.x);
865
- const ys = outer.map((point) => point.y);
866
- const bounds = { minX: Math.min(...xs), maxX: Math.max(...xs), minY: Math.min(...ys), maxY: Math.max(...ys) };
867
- const centroid = polygonCentroid(outer);
868
- if (pointInPolygonWithHoles(centroid, outer, holes)) return centroid;
869
- let best = outer[0];
870
- let bestScore = -Infinity;
871
- const rings = [outer, ...holes ?? []];
872
- for (let row = 1; row < 24; row += 1) {
873
- for (let column = 1; column < 24; column += 1) {
874
- const point = {
875
- x: bounds.minX + (bounds.maxX - bounds.minX) * column / 24,
876
- y: bounds.minY + (bounds.maxY - bounds.minY) * row / 24
877
- };
878
- if (!pointInPolygonWithHoles(point, outer, holes)) continue;
879
- const score = Math.min(...rings.flatMap((ring) => ring.map((start, index) => {
880
- const end = ring[(index + 1) % ring.length];
881
- const dx = end.x - start.x;
882
- const dy = end.y - start.y;
883
- const denominator = dx * dx + dy * dy;
884
- const projection = denominator ? ((point.x - start.x) * dx + (point.y - start.y) * dy) / denominator : 0;
885
- const t = Math.max(0, Math.min(1, projection));
886
- return Math.hypot(point.x - (start.x + t * dx), point.y - (start.y + t * dy));
887
- })));
888
- if (score > bestScore) {
889
- best = point;
890
- bestScore = score;
891
- }
892
- }
893
- }
894
- return best;
1013
+ return polygonInscribedAnchor(outer, holes).point;
895
1014
  }
896
1015
  function polygonCentroid(pts) {
897
1016
  if (!pts.length) return { x: 0, y: 0 };
@@ -1214,11 +1333,15 @@ export {
1214
1333
  accessibilityMeta,
1215
1334
  ACCESSIBILITY_RING_COLOR,
1216
1335
  accessibilityRingColor,
1336
+ SEAT_COMMERCIAL_MARKS,
1337
+ seatCommercialMeta,
1217
1338
  LABEL_STYLE_MIN_SIZE,
1218
1339
  LABEL_STYLE_MAX_SIZE,
1219
1340
  SURROUNDINGS_SHAPE_ROLES,
1220
1341
  layerOf,
1221
1342
  CHART_STORAGE_KEY,
1343
+ distanceToRings,
1344
+ polygonNetArea,
1222
1345
  METRES_PER_CHART_UNIT,
1223
1346
  CHART_UNITS_PER_METRE,
1224
1347
  TIER_HEIGHT_M,
@@ -1249,4 +1372,4 @@ export {
1249
1372
  expandChart,
1250
1373
  chartBounds
1251
1374
  };
1252
- //# sourceMappingURL=chunk-FGS67GT3.js.map
1375
+ //# sourceMappingURL=chunk-MGC5BVAD.js.map