@adatechnology/game-urban 0.4.0 → 0.5.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.
- package/README.md +10 -2
- package/dist/index.d.ts +3 -29
- package/dist/index.global.js +7 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/networks/index.d.ts +166 -7
- package/dist/networks/index.js +284 -96
- package/dist/networks/index.js.map +1 -1
- package/dist/{types-CYeqw_58.d.ts → types-mY6VwZgN.d.ts} +62 -2
- package/package.json +1 -1
package/dist/networks/index.js
CHANGED
|
@@ -74,6 +74,10 @@ var NETWORK_VIOLATION = {
|
|
|
74
74
|
ORPHAN_CONNECTION: "orphan_connection",
|
|
75
75
|
CONNECTION_MOVED: "connection_moved",
|
|
76
76
|
DROP_TOO_LONG: "drop_too_long",
|
|
77
|
+
DROP_SKEWED: "drop_skewed",
|
|
78
|
+
DROP_OFF_FRONTAGE: "drop_off_frontage",
|
|
79
|
+
DROP_OVER_OTHER_LOT: "drop_over_other_lot",
|
|
80
|
+
POLE_TOO_MANY_DROPS: "pole_too_many_drops",
|
|
77
81
|
MISSING_SAG: "missing_sag",
|
|
78
82
|
CLEARANCE: "clearance",
|
|
79
83
|
MV_OVER_LOT: "mv_over_lot",
|
|
@@ -194,6 +198,9 @@ var DEFAULT_NETWORK_RULES = {
|
|
|
194
198
|
catenarySamples: 16,
|
|
195
199
|
power: {
|
|
196
200
|
dropMaxLength: 30,
|
|
201
|
+
dropMaxSkew: 30,
|
|
202
|
+
dropFrontageSlack: 0.5,
|
|
203
|
+
dropsPerPole: 4,
|
|
197
204
|
lvCircuitMaxLength: 200,
|
|
198
205
|
maxLoading: 0.8,
|
|
199
206
|
transformers: [
|
|
@@ -286,17 +293,17 @@ function segmentCrossing(a0, a1, b0, b1) {
|
|
|
286
293
|
const qz = b0[1] - a0[1];
|
|
287
294
|
const t = (qx * sz - qz * sx) / denominator;
|
|
288
295
|
const u = (qx * rz - qz * rx) / denominator;
|
|
289
|
-
const
|
|
290
|
-
return
|
|
296
|
+
const inside3 = (value) => value > 1e-9 && value < 1 - 1e-9;
|
|
297
|
+
return inside3(t) && inside3(u) ? [t, u] : void 0;
|
|
291
298
|
}
|
|
292
299
|
function pointInPolygon(point, outline) {
|
|
293
|
-
let
|
|
300
|
+
let inside3 = false;
|
|
294
301
|
for (let index = 0, previous = outline.length - 1; index < outline.length; previous = index++) {
|
|
295
302
|
const a = outline[index];
|
|
296
303
|
const b = outline[previous];
|
|
297
|
-
if (a[1] > point[1] !== b[1] > point[1] && point[0] < (b[0] - a[0]) * (point[1] - a[1]) / (b[1] - a[1]) + a[0])
|
|
304
|
+
if (a[1] > point[1] !== b[1] > point[1] && point[0] < (b[0] - a[0]) * (point[1] - a[1]) / (b[1] - a[1]) + a[0]) inside3 = !inside3;
|
|
298
305
|
}
|
|
299
|
-
return
|
|
306
|
+
return inside3;
|
|
300
307
|
}
|
|
301
308
|
function segmentEntersPolygon(a, b, outline) {
|
|
302
309
|
if (outline.length < 3) return false;
|
|
@@ -410,9 +417,9 @@ function validateBuildings(context, span) {
|
|
|
410
417
|
}
|
|
411
418
|
function validateCrowns(context, span) {
|
|
412
419
|
for (const crown of context.options.obstacles?.crowns ?? []) {
|
|
413
|
-
const
|
|
414
|
-
if (
|
|
415
|
-
const [low, high] = heightRange(context, span,
|
|
420
|
+
const inside3 = circleShares(planOf(span.from), planOf(span.to), [crown.x, crown.z], crown.radius);
|
|
421
|
+
if (inside3 === void 0) continue;
|
|
422
|
+
const [low, high] = heightRange(context, span, inside3[0], inside3[1]);
|
|
416
423
|
if (low <= crown.top && high >= crown.bottom) context.report({ code: NETWORK_VIOLATION.SPAN_THROUGH_CROWN, id: span.edge.id, detail: `${crown.x},${crown.z}` });
|
|
417
424
|
}
|
|
418
425
|
}
|
|
@@ -537,6 +544,101 @@ function validateBuried(context) {
|
|
|
537
544
|
}
|
|
538
545
|
}
|
|
539
546
|
|
|
547
|
+
// src/networks/frame.ts
|
|
548
|
+
function worldOf({ frame, u, v }) {
|
|
549
|
+
return frame.along === "x" ? [u, frame.axis + v] : [frame.axis + v, u];
|
|
550
|
+
}
|
|
551
|
+
function frameOf({ frame, x, z }) {
|
|
552
|
+
return frame.along === "x" ? [x, z - frame.axis] : [z, x - frame.axis];
|
|
553
|
+
}
|
|
554
|
+
var UINT32 = 2 ** 32;
|
|
555
|
+
function hashOf({ seed, id }) {
|
|
556
|
+
let h = 2166136261 ^ seed >>> 0;
|
|
557
|
+
h = Math.imul(h, 16777619);
|
|
558
|
+
h ^= Math.floor(seed / UINT32) >>> 0;
|
|
559
|
+
h = Math.imul(h, 16777619);
|
|
560
|
+
for (let index = 0; index < id.length; index++) {
|
|
561
|
+
h ^= id.charCodeAt(index);
|
|
562
|
+
h = Math.imul(h, 16777619);
|
|
563
|
+
}
|
|
564
|
+
h ^= h >>> 16;
|
|
565
|
+
h = Math.imul(h, 2246822507);
|
|
566
|
+
h ^= h >>> 13;
|
|
567
|
+
h = Math.imul(h, 3266489909);
|
|
568
|
+
h ^= h >>> 16;
|
|
569
|
+
return (h >>> 0) / UINT32;
|
|
570
|
+
}
|
|
571
|
+
function countOf({ seed, id, range }) {
|
|
572
|
+
const [least, most] = range;
|
|
573
|
+
return least + Math.min(most - least, Math.floor(hashOf({ seed, id }) * (most - least + 1)));
|
|
574
|
+
}
|
|
575
|
+
var ordinal = (index) => String(index + 1).padStart(2, "0");
|
|
576
|
+
function planBins(size) {
|
|
577
|
+
const cells = /* @__PURE__ */ new Map();
|
|
578
|
+
const key = (i, k) => `${i},${k}`;
|
|
579
|
+
return {
|
|
580
|
+
add(x, z, item) {
|
|
581
|
+
const id = key(Math.floor(x / size), Math.floor(z / size));
|
|
582
|
+
cells.set(id, [...cells.get(id) ?? [], item]);
|
|
583
|
+
},
|
|
584
|
+
near(x, z, radius) {
|
|
585
|
+
const out = [];
|
|
586
|
+
const reach = Math.ceil(radius / size);
|
|
587
|
+
const [ci, ck] = [Math.floor(x / size), Math.floor(z / size)];
|
|
588
|
+
for (let i = ci - reach; i <= ci + reach; i++) for (let k = ck - reach; k <= ck + reach; k++) out.push(...cells.get(key(i, k)) ?? []);
|
|
589
|
+
return out;
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// src/networks/drop-rules.ts
|
|
595
|
+
function dropMisfitOf({ frontage, pole, anchor, rules }) {
|
|
596
|
+
const [poleU, poleV] = frameOf({ frame: frontage.frame, x: pole.x, z: pole.z });
|
|
597
|
+
if (Math.abs(poleV) > frontage.reach) return void 0;
|
|
598
|
+
const [anchorU, anchorV] = frameOf({ frame: frontage.frame, x: anchor[0], z: anchor[2] });
|
|
599
|
+
if (Math.sign(poleV) === frontage.side) {
|
|
600
|
+
const [low, high] = frontage.span;
|
|
601
|
+
return poleU >= low - rules.dropFrontageSlack && poleU <= high + rules.dropFrontageSlack ? void 0 : "off_frontage";
|
|
602
|
+
}
|
|
603
|
+
const skew = Math.atan2(Math.abs(poleU - anchorU), Math.abs(poleV - anchorV)) * 180 / Math.PI;
|
|
604
|
+
return skew <= rules.dropMaxSkew ? void 0 : "skewed";
|
|
605
|
+
}
|
|
606
|
+
var inside = (x, z, rect) => x > rect[0] && x < rect[2] && z > rect[1] && z < rect[3];
|
|
607
|
+
function lotUnderDrop({ from, to, lot, frontages }) {
|
|
608
|
+
const steps = Math.max(1, Math.ceil(Math.hypot(to[0] - from[0], to[1] - from[1]) / 0.25));
|
|
609
|
+
for (let index = 0; index <= steps; index++) {
|
|
610
|
+
const t = index / steps;
|
|
611
|
+
const [x, z] = [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];
|
|
612
|
+
const other = frontages.find((entry) => entry.lot !== lot && inside(x, z, entry.rect));
|
|
613
|
+
if (other) return other.lot;
|
|
614
|
+
}
|
|
615
|
+
return void 0;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// src/networks/validate-drops.ts
|
|
619
|
+
function validateDrops(context) {
|
|
620
|
+
const frontages = context.options.frontages;
|
|
621
|
+
const perPole = /* @__PURE__ */ new Map();
|
|
622
|
+
for (const edge of context.graph.edges.values()) {
|
|
623
|
+
if (edge.kind !== "service_drop" && edge.kind !== "telecom_drop") continue;
|
|
624
|
+
const ends = edgeEnds(context, edge);
|
|
625
|
+
if (!ends) continue;
|
|
626
|
+
const [pole, end] = ends;
|
|
627
|
+
if (edge.kind === "service_drop") perPole.set(pole.id, (perPole.get(pole.id) ?? 0) + 1);
|
|
628
|
+
const lot = end.lot;
|
|
629
|
+
if (frontages === void 0 || lot === void 0) continue;
|
|
630
|
+
const frontage = frontages.find((entry) => entry.lot === lot);
|
|
631
|
+
const misfit = frontage && dropMisfitOf({ frontage, pole: { x: pole.at[0], z: pole.at[2] }, anchor: end.at, rules: context.rules.power });
|
|
632
|
+
if (misfit === "skewed") context.report({ code: NETWORK_VIOLATION.DROP_SKEWED, id: edge.id, limit: context.rules.power.dropMaxSkew });
|
|
633
|
+
if (misfit === "off_frontage") context.report({ code: NETWORK_VIOLATION.DROP_OFF_FRONTAGE, id: edge.id, detail: pole.id });
|
|
634
|
+
const other = lotUnderDrop({ from: [pole.at[0], pole.at[2]], to: [end.at[0], end.at[2]], lot, frontages });
|
|
635
|
+
if (other !== void 0) context.report({ code: NETWORK_VIOLATION.DROP_OVER_OTHER_LOT, id: edge.id, detail: other });
|
|
636
|
+
}
|
|
637
|
+
for (const [pole, count] of perPole) {
|
|
638
|
+
if (count > context.rules.power.dropsPerPole) context.report({ code: NETWORK_VIOLATION.POLE_TOO_MANY_DROPS, id: pole, value: count, limit: context.rules.power.dropsPerPole });
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
540
642
|
// src/networks/validate-load.ts
|
|
541
643
|
function circuitDemand(context, transformerId) {
|
|
542
644
|
const circuit = circuitOf(context.graph, transformerId);
|
|
@@ -645,6 +747,7 @@ function validateNetworks(networks, options = {}) {
|
|
|
645
747
|
validateLots(context);
|
|
646
748
|
validateOrphans(context);
|
|
647
749
|
validateAerial(context);
|
|
750
|
+
validateDrops(context);
|
|
648
751
|
validateBuried(context);
|
|
649
752
|
validateLoad(context);
|
|
650
753
|
return violations;
|
|
@@ -658,7 +761,13 @@ var DISTRIBUTION = {
|
|
|
658
761
|
lens: { lit: 16752704, unlit: 3815994 },
|
|
659
762
|
light: { color: 16751168, intensity: 1.3, distance: 20, y: 6.4 },
|
|
660
763
|
transformer: { offset: 0.45, y: 7.7, radius: 0.32, height: 1, color: 5922402, segments: 8 },
|
|
661
|
-
slots: DEFAULT_POLE_SLOTS
|
|
764
|
+
slots: DEFAULT_POLE_SLOTS,
|
|
765
|
+
crossarm: { reach: 0.3, width: 2, height: 0.1, depth: 0.09, color: 9211014 },
|
|
766
|
+
insulators: { at: [-0.55, 0.35, 1.15], radius: 0.04, color: 14210248 },
|
|
767
|
+
bushings: { spread: 0.16, radius: 0.025, height: 0.14, color: 11055288 },
|
|
768
|
+
lowVoltage: { out: 0.2, color: 6185060 },
|
|
769
|
+
telecom: { out: 0.18, color: 6185060 },
|
|
770
|
+
guy: { reach: 3, color: 8027262 }
|
|
662
771
|
};
|
|
663
772
|
|
|
664
773
|
// src/networks/circuits.ts
|
|
@@ -727,53 +836,6 @@ function centreOf({ poles, system, span, isService }) {
|
|
|
727
836
|
return best;
|
|
728
837
|
}
|
|
729
838
|
|
|
730
|
-
// src/networks/frame.ts
|
|
731
|
-
function worldOf({ frame, u, v }) {
|
|
732
|
-
return frame.along === "x" ? [u, frame.axis + v] : [frame.axis + v, u];
|
|
733
|
-
}
|
|
734
|
-
function frameOf({ frame, x, z }) {
|
|
735
|
-
return frame.along === "x" ? [x, z - frame.axis] : [z, x - frame.axis];
|
|
736
|
-
}
|
|
737
|
-
var UINT32 = 2 ** 32;
|
|
738
|
-
function hashOf({ seed, id }) {
|
|
739
|
-
let h = 2166136261 ^ seed >>> 0;
|
|
740
|
-
h = Math.imul(h, 16777619);
|
|
741
|
-
h ^= Math.floor(seed / UINT32) >>> 0;
|
|
742
|
-
h = Math.imul(h, 16777619);
|
|
743
|
-
for (let index = 0; index < id.length; index++) {
|
|
744
|
-
h ^= id.charCodeAt(index);
|
|
745
|
-
h = Math.imul(h, 16777619);
|
|
746
|
-
}
|
|
747
|
-
h ^= h >>> 16;
|
|
748
|
-
h = Math.imul(h, 2246822507);
|
|
749
|
-
h ^= h >>> 13;
|
|
750
|
-
h = Math.imul(h, 3266489909);
|
|
751
|
-
h ^= h >>> 16;
|
|
752
|
-
return (h >>> 0) / UINT32;
|
|
753
|
-
}
|
|
754
|
-
function countOf({ seed, id, range }) {
|
|
755
|
-
const [least, most] = range;
|
|
756
|
-
return least + Math.min(most - least, Math.floor(hashOf({ seed, id }) * (most - least + 1)));
|
|
757
|
-
}
|
|
758
|
-
var ordinal = (index) => String(index + 1).padStart(2, "0");
|
|
759
|
-
function planBins(size) {
|
|
760
|
-
const cells = /* @__PURE__ */ new Map();
|
|
761
|
-
const key = (i, k) => `${i},${k}`;
|
|
762
|
-
return {
|
|
763
|
-
add(x, z, item) {
|
|
764
|
-
const id = key(Math.floor(x / size), Math.floor(z / size));
|
|
765
|
-
cells.set(id, [...cells.get(id) ?? [], item]);
|
|
766
|
-
},
|
|
767
|
-
near(x, z, radius) {
|
|
768
|
-
const out = [];
|
|
769
|
-
const reach = Math.ceil(radius / size);
|
|
770
|
-
const [ci, ck] = [Math.floor(x / size), Math.floor(z / size)];
|
|
771
|
-
for (let i = ci - reach; i <= ci + reach; i++) for (let k = ck - reach; k <= ck + reach; k++) out.push(...cells.get(key(i, k)) ?? []);
|
|
772
|
-
return out;
|
|
773
|
-
}
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
|
|
777
839
|
// src/networks/pole-tree.ts
|
|
778
840
|
var planDistance = (a, b) => Math.hypot(a.x - b.x, a.z - b.z);
|
|
779
841
|
var spotOf = (station) => `${Math.round(station.x * 20)},${Math.round(station.z * 20)}`;
|
|
@@ -890,32 +952,18 @@ function lampOf({ pole, rules, lampReach }) {
|
|
|
890
952
|
if (role === "service") return void 0;
|
|
891
953
|
return worldOf({ frame: run, u, v: side * (run.width / 2 + rules.layout.poles.curbSetback - lampReach) });
|
|
892
954
|
}
|
|
955
|
+
function poleAt(tree, at) {
|
|
956
|
+
if (at === void 0) return void 0;
|
|
957
|
+
return [...tree.poles.values()].find((pole) => Math.hypot(pole.station.x - at.x, pole.station.z - at.z) < 1e-6);
|
|
958
|
+
}
|
|
893
959
|
function dropsOf(params) {
|
|
894
960
|
const find = poleFinder(params.tree);
|
|
895
|
-
const
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
for (const [connection, index] of pick) {
|
|
900
|
-
const pole = choices.get(connection)?.[index];
|
|
901
|
-
if (pole !== void 0) out.set(pole.id, [...out.get(pole.id) ?? [], connection]);
|
|
902
|
-
}
|
|
903
|
-
return out;
|
|
904
|
-
};
|
|
905
|
-
for (let round = 0; round < params.connections.length; round++) {
|
|
906
|
-
const over = powerPlanOf({ params, drops: drops() }).flatMap((plan) => plan.circuits.filter((circuit) => circuit.over && circuit.poles.length === 1));
|
|
907
|
-
const pole = over[0]?.poles[0];
|
|
908
|
-
const moving = (drops().get(pole ?? "") ?? []).filter((connection) => {
|
|
909
|
-
const next = choices.get(connection)?.[(pick.get(connection) ?? 0) + 1];
|
|
910
|
-
return next !== void 0 && Math.hypot(next.station.x - connection.at[0], next.station.z - connection.at[2]) <= params.rules.power.dropMaxLength;
|
|
911
|
-
});
|
|
912
|
-
const at = params.tree.poles.get(pole ?? "")?.station;
|
|
913
|
-
const away = (connection) => at === void 0 ? 0 : Math.hypot(connection.at[0] - at.x, connection.at[2] - at.z);
|
|
914
|
-
const farthest = moving.sort((a, b) => away(b) - away(a))[0];
|
|
915
|
-
if (farthest === void 0) break;
|
|
916
|
-
pick.set(farthest, (pick.get(farthest) ?? 0) + 1);
|
|
961
|
+
const out = /* @__PURE__ */ new Map();
|
|
962
|
+
for (const connection of params.connections) {
|
|
963
|
+
const pole = poleAt(params.tree, params.feeds.get(`${connection.lot}:power`)) ?? find({ x: connection.at[0], z: connection.at[2], radius: params.rules.power.dropMaxLength })[0];
|
|
964
|
+
if (pole !== void 0) out.set(pole.id, [...out.get(pole.id) ?? [], connection]);
|
|
917
965
|
}
|
|
918
|
-
return
|
|
966
|
+
return out;
|
|
919
967
|
}
|
|
920
968
|
function powerPlanOf({ params, drops }) {
|
|
921
969
|
const span = ({ from, to }) => spanLength({ tree: params.tree, from, to });
|
|
@@ -923,7 +971,7 @@ function powerPlanOf({ params, drops }) {
|
|
|
923
971
|
return params.tree.systems.map((system) => {
|
|
924
972
|
const consumers = new Map(system.poles.map((pole) => [pole, (drops.get(pole) ?? []).map((connection) => connection.installedKva ?? 0)]));
|
|
925
973
|
const circuits = circuitsOf({ system, consumers, span, rules: params.rules, isService });
|
|
926
|
-
const medium =
|
|
974
|
+
const medium = new Set(system.poles.filter((pole) => !isService(pole)));
|
|
927
975
|
for (const circuit of circuits) {
|
|
928
976
|
for (let pole = circuit.transformer; pole !== void 0 && !medium.has(pole); pole = system.parent.get(pole)) medium.add(pole);
|
|
929
977
|
}
|
|
@@ -1026,11 +1074,11 @@ function piecesOf(run) {
|
|
|
1026
1074
|
out.push({ from: start, to: run.to, ends: [startEnd, run.ends[1]] });
|
|
1027
1075
|
return out.filter((piece) => piece.to - piece.from > 1);
|
|
1028
1076
|
}
|
|
1029
|
-
var
|
|
1077
|
+
var inside2 = (x, z, rect) => x > rect[0] && x < rect[2] && z > rect[1] && z < rect[3];
|
|
1030
1078
|
function lineOf(params) {
|
|
1031
1079
|
const lateral = params.side * (params.run.width / 2 + params.rules.poles.curbSetback);
|
|
1032
1080
|
const place = (u) => worldOf({ frame: params.run, u, v: lateral });
|
|
1033
|
-
return { place, isFree: (u) => !params.avoid.some((rect) =>
|
|
1081
|
+
return { place, isFree: (u) => !params.avoid.some((rect) => inside2(...place(u), rect)) };
|
|
1034
1082
|
}
|
|
1035
1083
|
function slideClear({ u, bounds, isFree, poles }) {
|
|
1036
1084
|
for (let step = 0; step <= poles.slide / poles.slideStep; step++) {
|
|
@@ -1098,6 +1146,7 @@ function poleStationsOf(params) {
|
|
|
1098
1146
|
}
|
|
1099
1147
|
|
|
1100
1148
|
// src/networks/reach.ts
|
|
1149
|
+
var feedKey = (anchor) => `${anchor.lot}:${anchor.network}`;
|
|
1101
1150
|
var distance = (station, anchor) => Math.hypot(station.x - anchor.at[0], station.z - anchor.at[2]);
|
|
1102
1151
|
function inLine({ run, stations, anchor, params }) {
|
|
1103
1152
|
const { poles } = params.rules;
|
|
@@ -1135,12 +1184,34 @@ function chainTo({ from, anchor, params }) {
|
|
|
1135
1184
|
}
|
|
1136
1185
|
return out;
|
|
1137
1186
|
}
|
|
1187
|
+
function feedsAnchor({ station, anchor, params }) {
|
|
1188
|
+
if (Math.hypot(station.x - anchor.at[0], station.z - anchor.at[2]) > params.reach - 1e-6) return false;
|
|
1189
|
+
const frontage = params.frontages.get(anchor.lot);
|
|
1190
|
+
if (!frontage) return true;
|
|
1191
|
+
if (dropMisfitOf({ frontage, pole: station, anchor: anchor.at, rules: params.power }) !== void 0) return false;
|
|
1192
|
+
return lotUnderDrop({ from: [station.x, station.z], to: [anchor.at[0], anchor.at[2]], lot: anchor.lot, frontages: [...params.frontages.values()] }) === void 0;
|
|
1193
|
+
}
|
|
1138
1194
|
function reachLots(params) {
|
|
1139
1195
|
const runs = params.runs.map((stations) => [...stations]);
|
|
1140
1196
|
const chains = [];
|
|
1197
|
+
const feeds = /* @__PURE__ */ new Map();
|
|
1198
|
+
const load = /* @__PURE__ */ new Map();
|
|
1141
1199
|
const all = () => [...runs.flat(), ...chains.flat()];
|
|
1142
|
-
|
|
1143
|
-
|
|
1200
|
+
const take = (anchor, station) => {
|
|
1201
|
+
feeds.set(feedKey(anchor), station);
|
|
1202
|
+
if (anchor.network === "power") load.set(station, (load.get(station) ?? 0) + 1);
|
|
1203
|
+
};
|
|
1204
|
+
const free = (station) => (load.get(station) ?? 0) < params.power.dropsPerPole;
|
|
1205
|
+
const anchors = [...params.anchors].sort((a, b) => (a.network === "power" ? 0 : 1) - (b.network === "power" ? 0 : 1));
|
|
1206
|
+
for (const anchor of anchors) {
|
|
1207
|
+
const isPower = anchor.network === "power";
|
|
1208
|
+
const fits = (station) => feedsAnchor({ station, anchor, params }) && (!isPower || free(station));
|
|
1209
|
+
const power = feeds.get(`${anchor.lot}:power`);
|
|
1210
|
+
const nearest = power !== void 0 && !isPower && fits(power) ? power : all().filter(fits).sort((a, b) => distance(a, anchor) - distance(b, anchor))[0];
|
|
1211
|
+
if (nearest) {
|
|
1212
|
+
take(anchor, nearest);
|
|
1213
|
+
continue;
|
|
1214
|
+
}
|
|
1144
1215
|
const served = params.served.get(anchor.lot);
|
|
1145
1216
|
const stations = runs.find((entry) => entry[0]?.run.id === served?.run.id);
|
|
1146
1217
|
if (served === void 0 || stations === void 0) continue;
|
|
@@ -1148,11 +1219,19 @@ function reachLots(params) {
|
|
|
1148
1219
|
if (added !== void 0) stations.push(added);
|
|
1149
1220
|
stations.sort((a, b) => a.u - b.u);
|
|
1150
1221
|
const from = added ?? [...stations].sort((a, b) => distance(a, anchor) - distance(b, anchor))[0];
|
|
1151
|
-
if (from === void 0
|
|
1222
|
+
if (from === void 0) continue;
|
|
1223
|
+
if (distance(from, anchor) <= params.reach - 1e-6) {
|
|
1224
|
+
if (!fits(from)) params.warn({ code: "drop_off_practice", id: anchor.lot, detail: "no pole in front of the lot or straight across the street" });
|
|
1225
|
+
take(anchor, from);
|
|
1226
|
+
continue;
|
|
1227
|
+
}
|
|
1152
1228
|
const chain = chainTo({ from, anchor, params });
|
|
1153
|
-
if (chain
|
|
1229
|
+
if (chain === void 0) continue;
|
|
1230
|
+
chains.push([from, ...chain]);
|
|
1231
|
+
take(anchor, chain[chain.length - 1] ?? from);
|
|
1154
1232
|
}
|
|
1155
|
-
|
|
1233
|
+
const renumbered = runs.map((stations) => stations.map((station, index) => ({ ...station, id: `pole:${station.run.id}:${ordinal(index)}` })));
|
|
1234
|
+
return { runs: renumbered, chains, feeds: new Map([...feeds].map(([lot, station]) => [lot, { x: station.x, z: station.z }])) };
|
|
1156
1235
|
}
|
|
1157
1236
|
|
|
1158
1237
|
// src/networks/runs.ts
|
|
@@ -1735,7 +1814,7 @@ function layTelecom(params) {
|
|
|
1735
1814
|
}
|
|
1736
1815
|
const find = poleFinder(tree);
|
|
1737
1816
|
for (const connection of params.connections) {
|
|
1738
|
-
const pole = find({ x: connection.at[0], z: connection.at[2], radius: rules.telecom.dropMaxLength })[0];
|
|
1817
|
+
const pole = poleAt(tree, params.feeds.get(`${connection.lot}:telecom`)) ?? find({ x: connection.at[0], z: connection.at[2], radius: rules.telecom.dropMaxLength })[0];
|
|
1739
1818
|
if (pole === void 0) continue;
|
|
1740
1819
|
const node = `lot:${connection.lot}:telecom`;
|
|
1741
1820
|
sink.nodes.push({ id: node, kind: "connection", at: connection.at, carries: ["telecom"], lot: connection.lot });
|
|
@@ -1820,11 +1899,15 @@ function polesOf({ params, layout, sink }) {
|
|
|
1820
1899
|
const anchors = layout.connections.filter((connection) => connection.network === "power" || connection.network === "telecom");
|
|
1821
1900
|
const isFree = (x, z) => !avoid.some((rect) => x > rect[0] && x < rect[2] && z > rect[1] && z < rect[3]);
|
|
1822
1901
|
const surface = surfaceOf({ runs, sidewalk: rules.layout.sidewalk });
|
|
1823
|
-
const
|
|
1824
|
-
const canServe = ({ x, z, lot }) => surface(x, z) !== "road" && !params.lots.some((other) => other.id !== lot &&
|
|
1902
|
+
const inside3 = (x, z, rect) => x > rect[0] && x < rect[2] && z > rect[1] && z < rect[3];
|
|
1903
|
+
const canServe = ({ x, z, lot }) => surface(x, z) !== "road" && !params.lots.some((other) => other.id !== lot && inside3(x, z, other.rect));
|
|
1825
1904
|
const reach = Math.min(rules.power.dropMaxLength, rules.telecom.dropMaxLength);
|
|
1826
|
-
const
|
|
1827
|
-
|
|
1905
|
+
const frontages = new Map(frontagesOf({ served, sidewalk: rules.layout.sidewalk }).map((frontage) => [frontage.lot, frontage]));
|
|
1906
|
+
const reached = reachLots({ runs: stations, anchors, served: new Map(served.map((entry) => [entry.lot.id, entry])), reach, rules: rules.layout, isFree, canServe, warn, frontages, power: rules.power });
|
|
1907
|
+
return { tree: poleTreeOf({ chains: [...reached.runs, ...reached.chains], sides, setback: rules.layout.poles.curbSetback }), feeds: reached.feeds };
|
|
1908
|
+
}
|
|
1909
|
+
function frontagesOf({ served, sidewalk }) {
|
|
1910
|
+
return served.map((entry) => ({ lot: entry.lot.id, rect: entry.lot.rect, frame: { along: entry.run.along, axis: entry.run.axis }, reach: entry.run.width / 2 + sidewalk, side: entry.side, span: entry.span }));
|
|
1828
1911
|
}
|
|
1829
1912
|
function generateNetworks(params) {
|
|
1830
1913
|
const rules = resolveNetworkRules(params.rules);
|
|
@@ -1834,15 +1917,15 @@ function generateNetworks(params) {
|
|
|
1834
1917
|
const sides = poleSidesOf({ runs, served });
|
|
1835
1918
|
const connections = lotConnectionsOf({ served, declared: params.connections ?? [], rules, groundAt: groundAt2 });
|
|
1836
1919
|
const sink = { nodes: [], edges: [], warnings: [] };
|
|
1837
|
-
const tree = polesOf({ params, layout: { rules, runs, served, sides, connections }, sink });
|
|
1920
|
+
const { tree, feeds } = polesOf({ params, layout: { rules, runs, served, sides, connections }, sink });
|
|
1838
1921
|
const pole = params.pole ?? { id: "concrete_distribution", spec: DISTRIBUTION };
|
|
1839
1922
|
const heights = poleHeightsOf(pole.spec.slots);
|
|
1840
1923
|
const isPeriphery = peripheryOf({ plan: params.plan, kinds: rules.layout.periphery.kinds });
|
|
1841
1924
|
const unmetered = new Set(
|
|
1842
1925
|
served.filter(({ lot }) => isPeriphery((lot.rect[0] + lot.rect[2]) / 2, (lot.rect[1] + lot.rect[3]) / 2) && hashOf({ seed: params.seed, id: `hookup:${lot.id}` }) < rules.layout.periphery.hookupShare).map((entry) => entry.lot.id)
|
|
1843
1926
|
);
|
|
1844
|
-
layPower({ tree, connections: ofNetwork2({ connections, network: "power" }), rules, heights, pole: { id: pole.id, lampReach: pole.spec.lamp.reach }, unmetered, sink });
|
|
1845
|
-
layTelecom({ tree, connections: ofNetwork2({ connections, network: "telecom" }), rules, heights, seed: params.seed, isPeriphery, sink });
|
|
1927
|
+
layPower({ tree, connections: ofNetwork2({ connections, network: "power" }), rules, heights, pole: { id: pole.id, lampReach: pole.spec.lamp.reach }, unmetered, feeds, sink });
|
|
1928
|
+
layTelecom({ tree, connections: ofNetwork2({ connections, network: "telecom" }), rules, heights, seed: params.seed, isPeriphery, feeds, sink });
|
|
1846
1929
|
const [width, depth] = params.plan.size ?? [0, 0];
|
|
1847
1930
|
const rivers = (params.plan.lines ?? []).filter((line) => line.kind === "river");
|
|
1848
1931
|
const context = { runs, sides, served: new Map(served.map((entry) => [entry.lot.id, entry])), rules, groundAt: groundAt2, rivers, border: [width / 2, depth / 2], sink };
|
|
@@ -1850,13 +1933,112 @@ function generateNetworks(params) {
|
|
|
1850
1933
|
layWater({ context, connections: ofNetwork2({ connections, network: "water" }) });
|
|
1851
1934
|
laySewer({ context, connections: ofNetwork2({ connections, network: "sewer" }), above: storm });
|
|
1852
1935
|
const networks = { nodes: sink.nodes, edges: sink.edges, seed: params.seed, rules };
|
|
1853
|
-
return { networks, connections, surfaceAt: surfaceOf({ runs, sidewalk: rules.layout.sidewalk }), warnings: sink.warnings };
|
|
1936
|
+
return { networks, connections, surfaceAt: surfaceOf({ runs, sidewalk: rules.layout.sidewalk }), frontages: frontagesOf({ served, sidewalk: rules.layout.sidewalk }), warnings: sink.warnings };
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
// src/lamps.ts
|
|
1940
|
+
var UINT322 = 2 ** 32;
|
|
1941
|
+
var PHASE_SALT = 1597463007;
|
|
1942
|
+
var SEED_BITS = new DataView(new ArrayBuffer(8));
|
|
1943
|
+
var hashLamp = (seed, x, z) => {
|
|
1944
|
+
SEED_BITS.setFloat64(0, seed);
|
|
1945
|
+
let h = 2166136261;
|
|
1946
|
+
for (const value of [SEED_BITS.getUint32(0), SEED_BITS.getUint32(4), Math.round(x * 100), Math.round(z * 100)]) {
|
|
1947
|
+
h ^= value & 65535;
|
|
1948
|
+
h = Math.imul(h, 16777619);
|
|
1949
|
+
h ^= value >>> 16 & 65535;
|
|
1950
|
+
h = Math.imul(h, 16777619);
|
|
1951
|
+
}
|
|
1952
|
+
return (h >>> 0) / UINT322;
|
|
1953
|
+
};
|
|
1954
|
+
var flickerPhaseOf = (x, z) => hashLamp(PHASE_SALT, x, z) * 2 * Math.PI;
|
|
1955
|
+
function assertLampShares(shares) {
|
|
1956
|
+
const { lit, flicker } = shares;
|
|
1957
|
+
if (!(lit >= 0 && lit <= 1)) throw new RangeError(`lamp shares: lit must be in [0, 1], got ${lit}`);
|
|
1958
|
+
if (!(flicker >= 0 && flicker <= lit)) throw new RangeError(`lamp shares: flicker must be in [0, lit], got ${flicker}`);
|
|
1959
|
+
}
|
|
1960
|
+
function lampStateOf({ seed, x, z, shares }) {
|
|
1961
|
+
assertLampShares(shares);
|
|
1962
|
+
const roll = hashLamp(seed, x, z);
|
|
1963
|
+
if (roll >= shares.lit) return { on: false, flicker: false };
|
|
1964
|
+
return { on: true, flicker: roll >= shares.lit - shares.flicker };
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
// src/networks/lamps.ts
|
|
1968
|
+
function networkLampsOf({ networks, shares, isNight }) {
|
|
1969
|
+
const feeds = new Map(networks.edges.filter((edge) => edge.kind === "light_feed").map((edge) => [edge.to, edge.from]));
|
|
1970
|
+
return networks.nodes.filter((node) => node.kind === "light").map((node) => {
|
|
1971
|
+
const [x, , z] = node.at;
|
|
1972
|
+
const state = isNight ? lampStateOf({ seed: networks.seed, x, z, shares }) : { on: false, flicker: false };
|
|
1973
|
+
return { id: node.id, pole: feeds.get(node.id) ?? "", at: node.at, ...state, ...state.flicker ? { flickerPhase: flickerPhaseOf(x, z) } : {} };
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
// src/pole-hardware.ts
|
|
1978
|
+
var GAP = 2e-3;
|
|
1979
|
+
function mediumVoltage(spec) {
|
|
1980
|
+
const { crossarm, insulators, slots } = spec;
|
|
1981
|
+
const [bottom, top] = slots.bands.mv;
|
|
1982
|
+
const pin = top - bottom - crossarm.height - GAP;
|
|
1983
|
+
const boxes = [{ role: "crossarm", x: crossarm.reach, y: bottom, z: 0, width: crossarm.width, height: crossarm.height, depth: crossarm.depth, color: crossarm.color }];
|
|
1984
|
+
for (const x of insulators.at) boxes.push({ role: "insulator", x, y: bottom + crossarm.height + GAP, z: 0, width: insulators.radius * 2, height: pin, depth: insulators.radius * 2, color: insulators.color });
|
|
1985
|
+
return { boxes, mv: insulators.at.map((x) => [x, top, 0]) };
|
|
1986
|
+
}
|
|
1987
|
+
function transformerOf(spec) {
|
|
1988
|
+
const t = spec.transformer;
|
|
1989
|
+
const x = -t.offset;
|
|
1990
|
+
const tank = { role: "tank", x, y: t.y, z: 0, radius: t.radius, height: t.height, color: t.color, segments: t.segments };
|
|
1991
|
+
const { bushings } = spec;
|
|
1992
|
+
const lid = t.y + t.height + GAP;
|
|
1993
|
+
const zs = [-bushings.spread, 0, bushings.spread];
|
|
1994
|
+
const boxes = [
|
|
1995
|
+
{ role: "bracket", x: x / 2, y: t.y + t.height * 0.6, z: 0, width: t.offset, height: 0.08, depth: 0.1, color: spec.lowVoltage.color },
|
|
1996
|
+
...zs.map((z) => ({ role: "bushing", x, y: lid, z, width: bushings.radius * 2, height: bushings.height, depth: bushings.radius * 2, color: bushings.color }))
|
|
1997
|
+
];
|
|
1998
|
+
return { boxes, tank, points: { mv: zs.map((z) => [x, lid + bushings.height, z]), lv: [x + t.radius, t.y + t.height * 0.3, 0] } };
|
|
1999
|
+
}
|
|
2000
|
+
function lampOf2(spec) {
|
|
2001
|
+
const { arm, lamp } = spec;
|
|
2002
|
+
const lensHeight = 0.03;
|
|
2003
|
+
return {
|
|
2004
|
+
boxes: [
|
|
2005
|
+
{ role: "arm", x: arm.reach, y: arm.y, z: 0, width: arm.width, height: arm.height, depth: arm.depth, color: arm.color },
|
|
2006
|
+
{ role: "lamp", x: lamp.reach, y: lamp.y, z: 0, width: lamp.width, height: lamp.height, depth: lamp.depth, color: arm.color }
|
|
2007
|
+
],
|
|
2008
|
+
lens: { role: "lamp", x: lamp.reach, y: lamp.y - lensHeight - GAP, z: 0, width: lamp.width * 0.8, height: lensHeight, depth: lamp.depth * 0.8, color: spec.lens.unlit }
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
function distributionHardwareOf(spec, o) {
|
|
2012
|
+
const heights = poleHeightsOf(spec.slots);
|
|
2013
|
+
const boxes = [];
|
|
2014
|
+
const cylinders = [];
|
|
2015
|
+
const mv = mediumVoltage(spec);
|
|
2016
|
+
if (o.mv || o.transformer) boxes.push(...mv.boxes);
|
|
2017
|
+
const lvAt = [-spec.lowVoltage.out, heights.lv, 0];
|
|
2018
|
+
boxes.push({ role: "lv_clamp", x: -spec.lowVoltage.out / 2 - spec.mast.radiusTop / 2, y: heights.lv - 0.06, z: 0, width: spec.lowVoltage.out - spec.mast.radiusTop + 0.06, height: 0.12, depth: 0.08, color: spec.lowVoltage.color });
|
|
2019
|
+
const { telecom } = spec;
|
|
2020
|
+
const cables = Math.max(o.cables, 0);
|
|
2021
|
+
const telecomAt = Array.from({ length: cables }, (_, index) => [-telecom.out, heights.telecom - index * o.cableGap, 0]);
|
|
2022
|
+
if (cables > 0) {
|
|
2023
|
+
const bottom = heights.telecom - (cables - 1) * o.cableGap - 0.05;
|
|
2024
|
+
boxes.push({ role: "telecom_clamp", x: -telecom.out / 2 - spec.mast.radiusTop / 2, y: bottom, z: 0, width: telecom.out - spec.mast.radiusTop + 0.04, height: heights.telecom + 0.05 - bottom, depth: 0.06, color: telecom.color });
|
|
2025
|
+
}
|
|
2026
|
+
const transformer = o.transformer ? transformerOf(spec) : void 0;
|
|
2027
|
+
if (transformer) {
|
|
2028
|
+
boxes.push(...transformer.boxes);
|
|
2029
|
+
cylinders.push(transformer.tank);
|
|
2030
|
+
}
|
|
2031
|
+
const lamp = o.lamp ? lampOf2(spec) : void 0;
|
|
2032
|
+
if (lamp) boxes.push(...lamp.boxes);
|
|
2033
|
+
const attachments = { mv: mv.mv, lv: lvAt, telecom: telecomAt, guy: [0, spec.slots.bands.mv[0] - 0.15, 0], ...transformer ? { transformer: transformer.points } : {} };
|
|
2034
|
+
return { boxes, cylinders, ...lamp ? { lens: lamp.lens } : {}, attachments };
|
|
1854
2035
|
}
|
|
1855
2036
|
export {
|
|
1856
2037
|
CONNECTION_NETWORK,
|
|
1857
2038
|
DEFAULT_NETWORK_LAYOUT,
|
|
1858
2039
|
DEFAULT_NETWORK_RULES,
|
|
1859
2040
|
DEFAULT_POLE_SLOTS,
|
|
2041
|
+
DISTRIBUTION,
|
|
1860
2042
|
EDGE_CLASS,
|
|
1861
2043
|
EDGE_NETWORK,
|
|
1862
2044
|
NETWORK_ENDS,
|
|
@@ -1869,11 +2051,17 @@ export {
|
|
|
1869
2051
|
circuitOf,
|
|
1870
2052
|
connectedNodes,
|
|
1871
2053
|
defaultConnectionsOf,
|
|
2054
|
+
distributionHardwareOf,
|
|
1872
2055
|
diversifiedDemand,
|
|
2056
|
+
dropMisfitOf,
|
|
1873
2057
|
edgeLength,
|
|
2058
|
+
frontagesOf,
|
|
1874
2059
|
generateNetworks,
|
|
1875
2060
|
isAerialEdgeKind,
|
|
2061
|
+
lotUnderDrop,
|
|
2062
|
+
networkLampsOf,
|
|
1876
2063
|
pickTransformer,
|
|
2064
|
+
poleHeightsOf,
|
|
1877
2065
|
resolveNetworkRules,
|
|
1878
2066
|
slotsOfPole,
|
|
1879
2067
|
surfaceOf,
|