settlemaker 3.0.0 → 3.0.1
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 +162 -277
- package/dist/output/geojson-builder.d.ts +1 -1
- package/dist/output/geojson-builder.js +1 -1
- package/dist/settlemaker.browser.js +1 -1
- package/docs/README.md +54 -0
- package/docs/api.md +175 -0
- package/docs/artwork-integration.md +104 -0
- package/docs/current-symbol-library.md +62 -42
- package/docs/development.md +102 -0
- package/docs/examples/gallery/coastal-city.png +0 -0
- package/docs/examples/gallery/coastal-city.svg +4253 -0
- package/docs/examples/gallery/coastal-village.png +0 -0
- package/docs/examples/gallery/coastal-village.svg +1211 -0
- package/docs/examples/gallery/copperline-city.png +0 -0
- package/docs/examples/gallery/copperline-city.svg +1139 -0
- package/docs/examples/gallery/copperline-village.png +0 -0
- package/docs/examples/gallery/copperline-village.svg +2382 -0
- package/docs/examples/gallery/desert-city.png +0 -0
- package/docs/examples/gallery/desert-city.svg +3509 -0
- package/docs/examples/gallery/desert-village.png +0 -0
- package/docs/examples/gallery/desert-village.svg +455 -0
- package/docs/examples/gallery/fixtures.json +449 -0
- package/docs/examples/gallery/temperate-city-night.png +0 -0
- package/docs/examples/gallery/temperate-city-night.svg +3511 -0
- package/docs/examples/gallery/temperate-city.png +0 -0
- package/docs/examples/gallery/temperate-city.svg +3511 -0
- package/docs/examples/gallery/temperate-village.png +0 -0
- package/docs/examples/gallery/temperate-village.svg +3227 -0
- package/docs/examples/gallery/tropical-city.png +0 -0
- package/docs/examples/gallery/tropical-city.svg +3508 -0
- package/docs/examples/gallery/tropical-village.png +0 -0
- package/docs/examples/gallery/tropical-village.svg +3761 -0
- package/docs/examples/gallery/tundra-city.png +0 -0
- package/docs/examples/gallery/tundra-city.svg +3509 -0
- package/docs/examples/gallery/tundra-village.png +0 -0
- package/docs/examples/gallery/tundra-village.svg +1549 -0
- package/docs/fmg-embed-zoom.md +54 -0
- package/docs/gallery.md +139 -0
- package/docs/geojson.md +188 -0
- package/docs/getting-started.md +157 -0
- package/docs/landscape-character-review.md +55 -0
- package/docs/releases/3.0.1.md +18 -0
- package/docs/scene-schema.md +160 -0
- package/docs/schema-v3.md +38 -0
- package/docs/skins.md +52 -0
- package/docs/test-urls.md +39 -0
- package/docs/url-api.md +252 -0
- package/docs/water-context-v1.md +384 -0
- package/package.json +15 -8
- package/scripts/check-docs.mjs +106 -0
- package/scripts/generate-copperline.mjs +255 -0
- package/scripts/generate-examples.mjs +54 -0
- package/scripts/render-copperline.mjs +36 -0
- package/src/output/geojson-builder.ts +1 -1
- package/symbols/copperline/README.md +10 -3
|
@@ -582,7 +582,7 @@ var Fd=Object.create;var U2=Object.defineProperty;var Gd=Object.getOwnPropertyDe
|
|
|
582
582
|
${$5(a,s.refined)}
|
|
583
583
|
${s.refined?Ii(X):""}
|
|
584
584
|
</style>`),H.push(`<rect data-bg="paper" x="${d.min_x.toFixed(1)}" y="${d.min_y.toFixed(1)}" width="${h.toFixed(1)}" height="${c.toFixed(1)}" fill="${a.paper}"/>`),k.fields.length>0){H.push('<g id="fields">');for(let B of k.fields)H.push(`<path class="plot" d="${tr(B.ring)}"/>`);if(R||F.length)for(let B of k.fields){if(B.hatch===!1)continue;let U=C(B.angleDeg);if(B.glyph&&s.glyphs?.[B.glyph]){H.push(`<path data-field-glyph="${B.glyph}" d="${tr(B.ring)}" fill="url(#${j(B)})"/>`),H.push(Pa(B.ring,B.glyph,1/(e.metersPerUnit??1),`${n}-${k.fields.indexOf(B)}`));continue}R&&H.push(`<path class="hatch" d="${tr(B.ring)}" fill="url(#${n}-field-a${U})"/>`)}H.push("</g>")}if(k.greens.length>0||k.vegetation.length>0){H.push('<g id="greens">');for(let B of k.greens){let U=B.ring.map(J=>J.x),$=B.ring.map(J=>J.y);H.push(Br(tr(B.ring),e.biome,{unit:.6,id:`${n}-${k.greens.indexOf(B)}`,bounds:[Math.min(...U),Math.min(...$),Math.max(...U)-Math.min(...U),Math.max(...$)-Math.min(...$)]}));for(let J of B.paths??[])H.push(`<path class="park-path" d="${l2(J)}" stroke-width="${Mt(B.pathWidth??.7)}"/>`)}for(let B of k.vegetation){if(s.glyphs?.[B.kind]||!s.symbols[B.kind])continue;let U=B.scale;H.push(`<use href="#asset-${B.kind}" x="${Mt(-1)}" y="${Mt(-1)}" width="2" height="2" transform="translate(${Mt(B.at.x)},${Mt(B.at.y)}) scale(${Mt(U/2)}) rotate(${B.rotationDeg})"/>`)}H.push("</g>")}if(a.water!==null&&k.water.rings.length>0){let B=k.water.rings.map(tr).join(" ");H.push(`<g id="water" clip-path="url(#${n})">`),H.push(`<path class="fill" d="${B}" fill-rule="evenodd"/>`),a.waterEdge!==null&&H.push(`<path class="shore" d="${B}"/>`),H.push("</g>")}if(k.roads.length>0){let B=`${n}-road-land`;k.water.rings.length&&H.push(`<defs><mask id="${B}" maskUnits="userSpaceOnUse" x="${d.min_x}" y="${d.min_y}" width="${h}" height="${c}"><rect x="${d.min_x}" y="${d.min_y}" width="${h}" height="${c}" fill="white"/><path d="${k.water.rings.map(tr).join(" ")}" fill="black" fill-rule="evenodd"/></mask></defs>`),H.push(`<g id="roads" clip-path="url(#${n})"${k.water.rings.length?` mask="url(#${B})"`:""}>`);let U=k.roads.map($=>({path:l2($.path),width:$.width??($.kind==="artery"?a.arteryWidth:a.roadWidth),alley:$.kind==="alley"}));for(let $ of U)$.alley||H.push(`<path class="casing" d="${$.path}" stroke-width="${Mt($.width+a.casingDelta*2)}"/>`);for(let $ of U)H.push(`<path class="core" d="${$.path}" stroke-width="${Mt($.width)}"/>`);H.push("</g>")}if(k.bridges?.length){H.push('<g id="bridges">');for(let B of k.bridges)H.push(`<g data-bridge="${B.id}">${Za(B.path,B.width,e.biome,!0)}</g>`);H.push("</g>")}let nt=B=>B.glyphBacked===!0&&B.id!==void 0&&m.has(B.id),mt=k.buildings.filter(B=>!nt(B));if(mt.length>0||f.length>0){let{dx:B,dy:U}=a.shadowOffset;H.push(`<g id="shadows" transform="translate(${Mt(B)},${Mt(U)})">`);for(let $ of mt)H.push(`<path${Po($.id)} d="${tr($.ring)}"/>`);for(let $ of f)s.glyphs[$.id].sil&&H.push(`<use href="#glyph-${$.id}-sil"${Po($.buildingId)} transform="${pi($.at,$.scale,$.rotationDeg,s.glyphs[$.id].viewBox,s.glyphs[$.id].anchor,$.scaleY)}"/>`);H.push("</g>")}let O=B=>{if(s.name!=="settlement"||t.palette||t.theme?.buildingFill||r?.city.buildingFill||!B.ring.length)return"";let U=B.ring[0],$=Je(Math.round(U.x*10),Math.round(U.y*10),1380929350);return $<.45?"":` style="fill:${n2(e.biome,1+Math.floor(($-.45)/.55*4))}"`},Y=k.buildings.filter(B=>!B.landmark&&!nt(B));if(Y.length>0||k.piers.length>0){H.push('<g id="buildings">');for(let B of Y)H.push(`<path class="${B.kind}"${Po(B.id)}${B.landmark?"":O(B)} d="${tr(B.ring)}"/>`);for(let B of k.piers)H.push(`<path class="pier" d="${tr(B.ring)}"/>`);H.push("</g>")}let rt=k.buildings.filter(B=>B.landmark&&!nt(B));if(rt.length>0){H.push('<g id="landmarks">');for(let B of rt)H.push(`<path class="${B.kind}"${Po(B.id)}${B.landmark?"":O(B)} d="${tr(B.ring)}"/>`);H.push("</g>")}if(f.length>0){H.push('<g id="symbols">');for(let B of[...f].sort((U,$)=>U.at.y-$.at.y))H.push(`<use href="#${b(B)}"${Po(B.buildingId)} transform="${pi(B.at,B.scale,B.rotationDeg,s.glyphs[B.id].viewBox,s.glyphs[B.id].anchor,B.scaleY)}"/>`);H.push("</g>")}if(k.walls.length>0){H.push('<g id="walls">');for(let B of k.walls){if(s.name==="settlement"){H.push(xa(B,e.biome));let $=s.glyphs?.[x];if($)for(let J of B.towers)B.gates.some(lt=>Math.hypot(J.x-(lt.p1.x+lt.p2.x)/2,J.y-(lt.p1.y+lt.p2.y)/2)<4)||H.push(`<use href="#glyph-${x}" transform="${pi(J,B.large?6:4.8,0,$.viewBox,$.anchor)}"/>`);continue}for(let $ of B.polylines)H.push(`<path d="${l2($)}"/>`);for(let $ of B.gates)H.push(`<line class="gate" x1="${Mt($.p1.x)}" y1="${Mt($.p1.y)}" x2="${Mt($.p2.x)}" y2="${Mt($.p2.y)}"/>`);let U=d2*(B.large?1.5:1);for(let $ of B.towers)H.push(`<circle cx="${Mt($.x)}" cy="${Mt($.y)}" r="${Mt(U)}"/>`)}H.push("</g>")}let yt=k.vegetation.filter(B=>s.glyphs?.[B.kind]!==void 0);if(yt.length>0){H.push('<g id="canopy">');for(let B of[...yt].sort((U,$)=>U.at.y-$.at.y))H.push(`<use href="#glyph-${B.kind}" transform="${pi(B.at,B.scale,B.rotationDeg,s.glyphs[B.kind].viewBox,s.glyphs[B.kind].anchor)}"/>`);H.push("</g>")}if(v.length>0){H.push('<g id="marks">');for(let B of[...v].sort((U,$)=>U.at.y-$.at.y))H.push(`<use href="#${b(B)}"${Po(B.buildingId)} transform="${pi(B.at,B.scale,B.rotationDeg,s.glyphs[B.id].viewBox,s.glyphs[B.id].anchor,B.scaleY)}"/>`);H.push("</g>")}return H.push("</svg>"),Ai(H.join(`
|
|
585
|
-
`),X)}function k2(e,t={}){let r=s2(e,{shift:t.shift??kr,padding:t.padding??20});return h2(r,{skin:t.skin,skinBiome:t.skinBiome,assetSet:t.assetSet,palette:t.palette,theme:t.theme,clipId:t.clipId,symbols:t.symbols})}var N5=new Set(["pier","well","market","mill"]);var vi=4,wi="3.0.0";function er(e,t){return ga(e.x,e.y,t)}function c2(e,t={}){let r=[],o=new Fr,i=wo(e),a=t.shift??kr;for(let n of e.patches)if(n.ward){r.push({type:"Feature",properties:{layer:"ward",wardType:n.ward.type,label:n.ward.getLabel(),withinCity:n.withinCity,withinWalls:n.withinWalls},geometry:mi(n.shape,a)});for(let l of n.ward.geometry){let d=i.get(l);r.push({type:"Feature",properties:{layer:"building",wardType:n.ward.type,building_id:d},geometry:mi(l,a)})}if(n.ward instanceof Rt)for(let l of n.ward.gardens)r.push({type:"Feature",properties:{layer:"green",kind:"garden",wardType:n.ward.type},geometry:mi(l.ring,a)});if(n.ward instanceof Me)for(let l of n.ward.piers)r.push({type:"Feature",properties:{layer:"pier",wardType:n.ward.type},geometry:mi(l,a)})}for(let n of e.arteries)r.push({type:"Feature",properties:{layer:"street",streetType:"artery",street_id:o.alloc("s")},geometry:{type:"LineString",coordinates:n.vertices.map(l=>er(l,a))}});for(let n of e.roads)r.push({type:"Feature",properties:{layer:"street",streetType:"road",street_id:o.alloc("s")},geometry:{type:"LineString",coordinates:n.vertices.map(l=>er(l,a))}});for(let n of e.patches){for(let l of n.ward?.lanes??[])r.push({type:"Feature",properties:{layer:"street",streetType:"alley",width:l.width,street_id:o.alloc("s")},geometry:{type:"LineString",coordinates:[er(l.a,a),er(l.b,a)]}});if(n.ward instanceof Ge&&n.ward.geometry.length)for(let l of n.ward.paths)r.push({type:"Feature",properties:{layer:"street",streetType:"park",width:n.ward.pathWidth,street_id:o.alloc("s")},geometry:{type:"LineString",coordinates:l.map(d=>er(d,a))}})}e.wall!==null&&D5(r,e.wall,"city_wall",a),e.citadel!==null&&e.citadel.ward instanceof Xe&&D5(r,e.citadel.ward.wall,"citadel_wall",a),sk(r,e,a);let s=ra(e,e.params.population,o,i);for(let n of s){if(n.buildingId===null&&!N5.has(n.kind))throw new Error(`POI kind ${n.kind} emitted without a building_id \u2014 selector bug`);let l={layer:"poi",poi_id:o.alloc("p"),kind:n.kind,ward_type:n.wardType,building_id:n.buildingId};r.push({type:"Feature",properties:l,geometry:{type:"Point",coordinates:er(n.point,a)}})}return{type:"FeatureCollection",features:r,metadata:ok(e,e.params,t,a)}}function ok(e,t,r,o){let i=xo(t.population).diameterMeters,a=va(e);return{...t.population>1e3?{building_capacity:e.getBuildingCapacity()}:{},schema_version:vi,settlemaker_version:r.settlemakerVersion??wi,settlement_generation_version:ik(t,o),coordinate_system:"local_origin_y_down",coordinate_units:"settlement_units",generated_at:r.generatedAt??new Date().toISOString(),local_bounds:qr(e,r.padding??20,o),scale:{meters_per_unit:i/a,diameter_meters:i,diameter_local:a,source:"population_heuristic_v1"},stable_ids:{prefixes:{entrance:"g",poi:"p",street:"s",building:"b"}},poi_density:ei(t.population),degraded_flags:[...e.degradedFlags].sort(),local_origin_shift:o}}function ik(e,t){let r={schema:vi,settlemakerVersion:wi,seed:e.seed,population:e.population,nPatches:e.nPatches,urbanDensity:e.urbanDensity??null,walls:e.wallsNeeded,citadel:e.citadelNeeded,plaza:e.plazaNeeded,temple:e.templeNeeded,shanty:e.shantyNeeded,capital:e.capitalNeeded,oceanBearing:e.oceanBearing??null,harbourSize:e.harbourSize??null,roadBearings:e.roadEntryPoints?.map(o=>({b:Math.round(o.bearingDeg*10)/10,r:o.routeId??null,k:o.kind??null}))??null,coastlineGeometry:e.coastlineGeometry?.map(o=>o.map(i=>[Math.round(i.x*100)/100,Math.round(i.y*100)/100]))??null,originShift:{dx:Math.round(t.dx*100)/100,dy:Math.round(t.dy*100)/100,source:t.source}};return ak(JSON.stringify(r)).toString(36)}function ak(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t+e.charCodeAt(r)&2147483647;return t||1}function sk(e,t,r){if(t.border===null)return;let o=t.border,i=va(t);for(let a of t.gates){let s=o.gateMeta.get(a);s&&e.push(nk(a,s,o,t,i,r))}}function nk(e,t,r,o,i,a){let s=t.kind==="sea"||lk(e,o),n=s?"harbour":"land",l=s?"harbour":t.kind==="foot"?"foot":"road",d=`g${t.wallVertexIndex}`,h=dk(e,r),c=Math.hypot(e.x,e.y),k=Math.min(3,.05*i),p=c>0?(c-k)/c:0,f=[Math.round(e.x*p*100)/100,Math.round(e.y*p*100)/100],m=er({x:f[0],y:f[1]},a),v={layer:"entrance",entrance_id:d,kind:n,sub_kind:l,wall_vertex_index:t.wallVertexIndex,bearing_deg:t.bearingDeg,arrival_local:m};t.routeId!=null&&(v.matched_route_id=t.routeId),t.matchDeltaDeg!=null&&(v.bearing_match_delta_deg=t.matchDeltaDeg);let L=t.routes.map(w=>w.routeId).filter(w=>w!=null);return L.length>0&&(v.matched_route_ids=L),t.routes.length>0&&(v.matched_routes=t.routes.map(w=>{let M={requested_bearing_deg:Math.round(w.requestedBearingDeg*10)/10,match_delta_deg:w.matchDeltaDeg};return w.routeId!=null&&(M.route_id=w.routeId),w.kind!=null&&(M.kind=w.kind),M})),h.prev!=null&&(v.prev_entrance_id=h.prev),h.next!=null&&(v.next_entrance_id=h.next),{type:"Feature",properties:v,geometry:{type:"Point",coordinates:er(e,a)}}}function lk(e,t){return t.harbour===null?!1:t.harbour.shape.contains(e)}function dk(e,t){let r=t.shape.vertices,o=r.length,i=r.indexOf(e);if(i===-1)return{};let a=new Set(t.gateMeta.keys()),s=n=>{for(let l=1;l<o;l++){let d=r[((i+n*l)%o+o)%o];if(d!==e&&a.has(d))return`g${t.gateMeta.get(d).wallVertexIndex}`}};return{next:s(1),prev:s(-1)}}function D5(e,t,r,o){e.push({type:"Feature",properties:{layer:"wall",wallType:r},geometry:mi(t.shape,o)});for(let i of t.towers)e.push({type:"Feature",properties:{layer:"tower",wallType:r},geometry:{type:"Point",coordinates:er(i,o)}})}function mi(e,t){let r=e.vertices.map(o=>er(o,t));return r.length>0&&r.push([r[0][0],r[0][1]]),{type:"Polygon",coordinates:[r]}}var Sa=1,ge=class extends Error{constructor(r,o){super(o);this.reason=r;this.name="UrlCodecError"}};async function F5(e,t){let r=new Blob([e]).stream().pipeThrough(t);return new Uint8Array(await new Response(r).arrayBuffer())}function hk(e){let t="";for(let r of e)t+=String.fromCharCode(r);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function kk(e){let t=e.replace(/-/g,"+").replace(/_/g,"/"),r;try{r=atob(t)}catch{throw new ge("base64","parameter is not valid base64url")}let o=new Uint8Array(r.length);for(let i=0;i<r.length;i++)o[i]=r.charCodeAt(i);return o}async function G5(e){let t=new TextEncoder().encode(JSON.stringify(e));return hk(await F5(t,new CompressionStream("deflate-raw")))}async function Ca(e){let t=kk(e),r;try{r=await F5(t,new DecompressionStream("deflate-raw"))}catch{throw new ge("inflate","parameter is not valid deflate-raw data")}try{return JSON.parse(new TextDecoder().decode(r))}catch{throw new ge("json","decompressed payload is not valid JSON")}}async function ck(e,t){return G5({v:Sa,burg:e,...t!==void 0?{seed:t}:{}})}async function p2(e){let t=await Ca(e);if(typeof t!="object"||t===null)throw new ge("shape","payload is not an object");let r=t;if(r.v!==Sa)throw new ge("version",`unsupported payload version ${String(r.v)} (expected ${Sa})`);let o=r.burg;if(typeof o!="object"||o===null||typeof o.name!="string"||typeof o.population!="number")throw new ge("shape","payload has no plausible burg (name + population required)");return Ar(o),{burg:o,...typeof r.seed=="number"?{seed:r.seed}:{}}}var pk=/^#[0-9a-fA-F]{3,8}$/,fk=["paper","fieldFill","fieldFurrow","greenFill","treeFill","roadCasing","roadCore","buildingFill","buildingStroke","landmarkFill","shadowColor","smInk","smStone","smTimber","smVoid","smCanopy1","smCanopy2"],mk=["water","waterEdge"],vk=["shadowOpacity","arteryWidth","roadWidth","casingDelta","seamStroke","shoreWidth"];function W5(e){return typeof e=="string"&&pk.test(e)}function f2(e){return typeof e=="number"&&Number.isFinite(e)}function wk(e){let t={};if(e===null||typeof e!="object")return t;let r=e;for(let i of fk){let a=r[i];W5(a)&&(t[i]=a)}for(let i of mk){let a=r[i];(a===null||W5(a))&&(t[i]=a===null?null:a)}for(let i of vk){let a=r[i];f2(a)&&(t[i]=a)}let o=r.shadowOffset;if(o!==null&&typeof o=="object"){let{dx:i,dy:a}=o;f2(i)&&f2(a)&&(t.shadowOffset={dx:i,dy:a})}return t}var Lk=["name","pop","seed","port","citadel","walls","plaza","temple","shanty","capital","trade","oceanBearing","harbourSize","biome","urbanDensity","coreCapacity","roads"];function yk(e){return e<0||e>=360?(e%360+360)%360:e}function Mk(e){let t=[];for(let r of e.split(",")){let o=r.trim();if(o==="")continue;let[i,a,s]=o.split(":").map(d=>d.trim()),n=Number(i);if(!Number.isFinite(n))throw new ge("roads",`roads="${o}" \u2014 bearing must be a number, e.g. roads=45 or roads=45:main:through`);let l=a===void 0||a===""?"main":a;if(!Ye.includes(l))throw new ge("roads",`roads="${o}" \u2014 unknown class "${l}"; known classes: ${Ye.join(", ")}`);if(s!==void 0&&s!==""&&s!=="through")throw new ge("roads",`roads="${o}" \u2014 third field may only be "through"`);t.push({bearing_deg:yk(n),kind:l,through:s==="through"})}return t}function Zr(e,t){let r=e.get(t);return r==="1"||r==="true"}function Kr(e,t){let r=e.get(t);if(r===null||r==="")return;let o=Number(r);return Number.isFinite(o)?o:void 0}function uk(e){let t=200+Math.abs(e)%4800;return{name:`Burg ${Math.abs(e)%1e4}`,population:t,port:!1,citadel:t>3500,walls:t>1500,plaza:t>800,temple:t>2e3,shanty:!1,capital:!1}}async function gk(e,t={}){let r,o,i=!1,a=e.get("i");if(a!==null){let h=await p2(a);r=h.burg,o=h.seed}else if(Lk.some(h=>e.has(h))){let h=e.get("name")??`Burg ${Kr(e,"seed")??Kr(e,"pop")??0}`,c=e.get("roads"),k=e.get("harbourSize"),p=Kr(e,"urbanDensity"),f=Kr(e,"coreCapacity"),m=Kr(e,"oceanBearing");r={name:h,population:Kr(e,"pop")??300,port:Zr(e,"port"),citadel:Zr(e,"citadel"),walls:Zr(e,"walls"),plaza:Zr(e,"plaza"),temple:Zr(e,"temple"),shanty:Zr(e,"shanty"),capital:Zr(e,"capital"),...Zr(e,"trade")?{trade:!0}:{},...m!==void 0?{oceanBearing:m}:{},...k==="large"||k==="small"?{harbourSize:k}:{},...e.get("biome")!==null?{biome:e.get("biome")}:{},...c!==null?{roadBearings:Mk(c)}:{},...p!==void 0&&p>0?{urbanDensity:p}:{},...f!==void 0&&f>0?{coreCapacity:f}:{}},o=Kr(e,"seed")}else{let h=(t.randomSeed??(()=>Math.floor(Math.random()*2147483648)))();r=uk(h),o=h,i=!0}let s=e.get("style"),n=s!==null?wk(await Ca(s)):void 0,l=e.get("theme")??void 0,d=e.get("villageTheme")??void 0;if(d!==void 0&&!Qr.includes(d))throw new ge("villageTheme",`villageTheme="${d}" \u2014 known village themes: ${Qr.join(", ")}`);return{burg:r,...o!==void 0?{seedOverride:o}:{},...l!==void 0?{paletteName:l}:{},...n!==void 0?{themeOverrides:n}:{},...d!==void 0?{villageThemeName:d}:{},random:i}}var U5=q2(w2(),1);var So=new WeakMap,q5=new WeakMap,bk=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y)<1e-7;function K5(e,t){let r;try{let n=e.map(l=>[l.map(d=>[d.x,d.y])]);r=n.length?U5.default.union(n[0],...n.slice(1)):[]}catch{throw new je("water-context-invalid","Water polygon union could not be constructed.")}let o=r.map(n=>n.map(l=>l.map(([d,h])=>new Z(d,h)))),i=o.flat(),a=[],s=(n,l)=>[n.x,n.y].some((d,h)=>Math.abs(Math.abs(d)-t)<1e-6&&Math.abs(d-(h===0?l.x:l.y))<1e-6);for(let n of i){let l=n.length-1,d=n.slice(0,-1).findIndex((c,k)=>s(c,n[k+1]));if(d<0){a.push(n);continue}let h=[];for(let c=1;c<=l;c++){let k=(d+c)%l,p=n[k],f=n[k+1];s(p,f)?(h.length>1&&a.push(h),h=[]):(h.length||h.push(p),h.push(f))}h.length>1&&a.push(h)}for(let n of e)q5.set(n,t);So.set(e,{radius:t,paths:a,rings:i,polygons:o,segments:a.flatMap(n=>n.slice(1).map((l,d)=>[n[d],l]))})}function Pr(e){return So.get(e)?.paths??e.filter(t=>t.length>1).map(t=>bk(t[0],t.at(-1))?t:[...t,t[0]])}function be(e){return So.get(e)?.segments??Pr(e).flatMap(t=>t.slice(1).map((r,o)=>[t[o],r]))}function Y5(e){return So.get(e)?.rings}function Tt(e,t,r=0){let o=So.get(e);o&&Math.hypot(t.x,t.y)+r>o.radius+1e-7&&Uo(Math.hypot(t.x,t.y)+r)}function X5(e,t,r){let o=q5.get(e);o!==void 0&&Math.hypot(t.x,t.y)+r>o&&Uo(Math.hypot(t.x,t.y)+r)}function J5(e){return So.get(e)?.polygons}function fe(e){return(e%360+360)%360}function Lt(e){let t=e*Math.PI/180;return new Z(Math.sin(t),-Math.cos(t))}function pt(e,t){return fe(Math.atan2(t.x-e.x,-(t.y-e.y))*180/Math.PI)}function Qe(e,t){return Math.abs((fe(e)-fe(t)+540)%360-180)}function Ba(e,t){return(fe(t)-fe(e)+540)%360-180}function We(e,t){let r=Math.hypot(e,t);return r===0?new Z(0,0):new Z(e/r,t/r)}function A(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function Gt(e){let t=0;for(let r=1;r<e.length;r++)t+=A(e[r],e[r-1]);return t}function gt(e){let t=[0];for(let r=1;r<e.length;r++)t.push(t[r-1]+A(e[r],e[r-1]));return t}function ut(e,t,r){let o=t[t.length-1],i=Math.min(Math.max(r,0),o),a=1;for(;a<t.length-1&&t[a]<i;)a++;let s=t[a]-t[a-1]||1,n=(i-t[a-1])/s,l=e[a-1],d=e[a];return{p:new Z(l.x+(d.x-l.x)*n,l.y+(d.y-l.y)*n),dirDeg:pt(l,d)}}function kt(e,t){return Tt(t,e),t.some(r=>bt(e,r))}function st(e,t,r){let o=r.x-t.x,i=r.y-t.y,a=o*o+i*i;if(a===0)return new Z(t.x,t.y);let s=Math.max(0,Math.min(1,((e.x-t.x)*o+(e.y-t.y)*i)/a));return new Z(t.x+o*s,t.y+i*s)}function Yr(e,t){if(t.length===0)return{distance:1/0,point:e};if(t.length===1)return{distance:A(e,t[0]),point:t[0]};let r={distance:1/0,point:t[0]};for(let o=1;o<t.length;o++){let i=st(e,t[o-1],t[o]),a=A(e,i);a<r.distance&&(r={distance:a,point:i})}return r}function Ct(e){return e.diameter/2*Lo+gr}function Wt(e,t,r,o){let i=t.x-e.x,a=t.y-e.y,s=o.x-r.x,n=o.y-r.y,l=i*n-a*s;if(Math.abs(l)<1e-12)return null;let d=((r.x-e.x)*n-(r.y-e.y)*s)/l,h=((r.x-e.x)*a-(r.y-e.y)*i)/l,c=1e-6;return d<=c||d>=1-c||h<=c||h>=1-c?null:new Z(e.x+i*d,e.y+a*d)}function t1(e,t){let r=i=>i.x>=t.minX&&i.x<=t.maxX&&i.y>=t.minY&&i.y<=t.maxY;if(e.length===0||!r(e[0]))return[];let o=[e[0]];for(let i=1;i<e.length;i++){let a=e[i-1],s=e[i];if(r(s)){o.push(s);continue}let n=1,l=(d,h)=>{if(h===0)return;let c=d/h;c>=0&&c<n&&(n=c)};return l(t.minX-a.x,s.x-a.x),l(t.maxX-a.x,s.x-a.x),l(t.minY-a.y,s.y-a.y),l(t.maxY-a.y,s.y-a.y),o.push(new Z(a.x+(s.x-a.x)*n,a.y+(s.y-a.y)*n)),o}return o}function e1(e){let t=(Math.round(e)%360+360)%360;return String(t).padStart(3,"0")}function y2(e){return`arm-${e1(e)}`}function Li(e){return`lane-${e1(e)}`}function yi(e,t){let r=String(Math.round(t*100)).padStart(2,"0");return`${e}/b${r}`}function M2(e,t="outer"){return`${e}/a${t==="inner"?"0":""}`}function Ot(e){return/\/a\d*(~|$)/.test(e)}function Ea(e,t,r){return`${e}:${t===1?"R":"L"}${r}`}var L2="+r";function r1(e,t,r,o){return`${Ea(e,t,r)}${L2}${o}`}var xk=1e3;function Mi(e){let t=e.lastIndexOf(L2);if(t<0){let i=/(\d+)$/.exec(e);return i?parseInt(i[1],10):0}let r=parseInt(e.slice(t+L2.length),10)||0,o=/(\d+)$/.exec(e.slice(0,t));return r*xk+(o?parseInt(o[1],10):0)}function _a(e){return`bld:${e}`}function Co(e,t){return e??String(Math.round(t*100)/100)}function Ra(e,t,r,o){let i=t?t.replace(/\//g,"_"):Co(t,r);return`trunk-${e}-${i}${o?"~far":""}`}var Zk=.12,Pk=6,Sk=70;function u2(e,t,r){return A(t,r)<.05||Qe(pt(e,t),pt(t,r))<=Sk}function Ck(e,t,r){let o=[e],i=(a,s,n,l)=>{let d=new Z((a.x+2*s.x+n.x)/4,(a.y+2*s.y+n.y)/4);if(l>=7||A(d,st(d,a,n))<=Zk){o.push(n);return}let h=new Z((a.x+s.x)/2,(a.y+s.y)/2),c=new Z((s.x+n.x)/2,(s.y+n.y)/2);i(a,h,d,l+1),i(d,c,n,l+1)};return i(e,t,r,0),o}function Xr(e,t=[]){if(e.length<3)return e;let r=[e[0]];for(let o=1;o<e.length-1;o++){let i=e[o-1],a=e[o],s=e[o+1],n=A(i,a),l=A(a,s);if(n<.01||l<.01)continue;let d=Qe(pt(i,a),pt(a,s));if(d>120)return null;let h=t.some(f=>f.points.slice(1).some((m,v)=>A(a,st(a,f.points[v],m))<.05));if(d<4||h){r.push(a);continue}let c=Math.min(Pk,n*.4,l*.4),k=new Z(a.x+(i.x-a.x)*c/n,a.y+(i.y-a.y)*c/n),p=new Z(a.x+(s.x-a.x)*c/l,a.y+(s.y-a.y)*c/l);r.push(...Ck(k,a,p))}return r.push(e[e.length-1]),r.filter((o,i)=>i===0||A(o,r[i-1])>1e-6)}function xe(e,t){for(let a of e)Tt(t,a);if(!t.length)return[];let r=[],o,i=0;for(let a=1;a<e.length;a++){let s=e[a-1],n=e[a],l=A(s,n);if(l<1e-8)continue;let d=[0,1],h=n.x-s.x,c=n.y-s.y;for(let p of t)for(let f=0;f<p.length;f++){let m=p[f],v=p[(f+1)%p.length],L=v.x-m.x,w=v.y-m.y,M=h*w-c*L;if(Math.abs(M)<1e-9)continue;let x=((m.x-s.x)*w-(m.y-s.y)*L)/M,b=((m.x-s.x)*c-(m.y-s.y)*h)/M;x>0&&x<1&&b>=0&&b<=1&&d.push(x)}d.sort((p,f)=>p-f);let k=p=>p===0?s:p===1?n:new Z(s.x+h*p,s.y+c*p);for(let p=1;p<d.length;p++){let f=d[p-1],m=d[p];m-f<1e-9||(kt(k((f+m)/2),t)?(o||(o={points:[k(f)],startM:i+f*l,endM:0},r.push(o)),o.points.push(k(m)),o.endM=i+m*l):o=void 0)}i+=l}return r}function Qa(e,t){let r=xe(e,t);if(!r.some(s=>s.endM-s.startM>10))return e;let o=e[0],i=e.at(-1);if(kt(o,t)||kt(i,t))return e;if(!xe([o,i],t).length)return[o,i];let a;for(let s of r){let n=gt(s.points),l=ut(s.points,n,n.at(-1)/2).p,d=be(t).map(([h,c])=>{let k=st(l,h,c);return{a:h,b:c,p:k,distance:A(l,k)}}).sort((h,c)=>h.distance-c.distance).slice(0,4);for(let{a:h,b:c,p:k}of d){let p=A(h,c);if(p<.1)continue;let f=(c.x-h.x)/p,m=(c.y-h.y)/p;for(let v of[0,-8,8,-16,16,-24,24]){let L=new Z(k.x+f*v,k.y+m*v),w=P=>new Z(L.x-m*P,L.y+f*P),M=xe([w(-20),w(20)],t);if(M.length!==1)continue;let x=M[0];if(x.endM-x.startM>10)continue;let b=w(x.startM-20-8),u=w(x.endM-20+8);for(let[P,C]of[[b,u],[u,b]]){if(xe([o,P],t).length||xe([C,i],t).length)continue;let Q=Xr([o,P,C,i]);if(!Q)continue;let R=xe(Q,t);if(R.length!==1||R[0].endM-R[0].startM>10)continue;let V=gt(Q).at(-1);(!a||V<a.length)&&(a={points:Q,length:V})}}}}return a?.points??e}function Jr(e,t,r=0){for(let s of e)Tt(t,s,r);if(!t.length)return!0;if(e.length<2||kt(e[0],t)||kt(e.at(-1),t))return!1;let o=xe(e,t);if(o.some(s=>s.endM-s.startM>10))return!1;if(!(r>0))return!0;let i=gt(e),a=i.at(-1);for(let s=0;s<=a;s+=2){if(o.some(l=>s>=l.startM-r-5&&s<=l.endM+r+5))continue;let n=ut(e,i,s).p;for(let[l,d]of be(t))if(!(n.x<Math.min(l.x,d.x)-r||n.x>Math.max(l.x,d.x)+r||n.y<Math.min(l.y,d.y)-r||n.y>Math.max(l.y,d.y)+r)&&A(n,st(n,l,d))<r)return!1}return!0}var g2=3;function b2(e,t,r){Tt(t,e,r);let o,i=r+1;for(let[a,s]of be(t)){if(e.x<Math.min(a.x,s.x)-r||e.x>Math.max(a.x,s.x)+r||e.y<Math.min(a.y,s.y)-r||e.y>Math.max(a.y,s.y)+r)continue;let n=st(e,a,s),l=A(e,n);l<i&&(i=l,o=n)}return!o||i>=r||i<1e-8||kt(e,t)?e:new Z(o.x+(e.x-o.x)*(r+.3)/i,o.y+(e.y-o.y)*(r+.3)/i)}function ui(e,t,r){if(e.length<2||!t.length)return e;if(kt(e[0],t)){let p=e.findIndex(f=>!kt(f,t));return p<0?e:[...e.slice(0,p),...ui(e.slice(p),t,r)]}if(kt(e.at(-1),t))return e;let o=e;for(let p of[...xe(o,t)].reverse()){if(p.endM-p.startM<=10)continue;let f=gt(o),m=f.at(-1),v=Math.max(0,p.startM-45),L=Math.min(m,p.endM+45),w=[ut(o,f,v).p,...o.filter((x,b)=>f[b]>v&&f[b]<L),ut(o,f,L).p],M=Qa(w,t);o=[...o.filter((x,b)=>f[b]<v),...M,...o.filter((x,b)=>f[b]>L)]}let i=gt(o),a=i.at(-1),s=xe(o,t),n=r+g2,l=Math.ceil(a/4),d=Array.from({length:l+1},(p,f)=>a*f/l),h=d.map(p=>ut(o,i,p).p),c=d.map((p,f)=>f===0||f===l||s.some(m=>p>=m.startM-n-4&&p<=m.endM+n+4)),k=h;for(let p=0;p<10;p++)k=k.map((f,m)=>{if(c[m])return f;let v=k[m-1],L=k[m+1],w=new Z((v.x+2*f.x+L.x)/4,(v.y+2*f.y+L.y)/4);return b2(kt(w,t)?f:w,t,n)});return k}function Bk(e){return Math.max(e*d5,h5)}function o1(e,t){return Math.atan2(t.x-e.x,-(t.y-e.y))*180/Math.PI}function Ek(e,t){let r=e.points;if(r.length<2||t<=0)return[];let o=r[r.length-1],i=o1(r[r.length-2],o),a=i,s=0;for(let p of e.id)s=Math.imul(s,31)+p.charCodeAt(0)|0;let n=(s>>>0)/4294967296*Math.PI*2,l=0;if(r.length>=3){let p=o1(r[r.length-3],r[r.length-2]),f=Ba(p,i)*k5;l=Math.max(-Ys,Math.min(Ys,f))}let d=[o.clone()],h=o,c=0,k=0;for(;c<t;){let p=Math.min(Ks,t-c);Math.abs(k)<c5&&(i+=l,k+=l);let f=Math.min(1,c/70),m=13*Math.sin(c*Math.PI*2/420+n)*f*f,L=(a+Math.max(-30,Math.min(30,i-a+m)))*Math.PI/180;h=new Z(h.x+Math.sin(L)*p,h.y-Math.cos(L)*p),d.push(h),c+=p}return d}var i1=8;function _k(e){return Math.max(e*p5,f5)}var Ia=1;function n1(e,t,r){for(let o=Ia;o<=uo;o+=Ia)if(!kt(new Z(e.x+t.x*o,e.y+t.y*o),r))return o>=br;return!0}function l1(e,t){let r=A(e,t);return r===0?null:new Z((t.x-e.x)/r,(t.y-e.y)/r)}function Rk(e,t){for(let r=1;r<e.length;r++){let o=e[r-1],i=e[r],a=l1(o,i);if(!a)continue;let s=[];for(let n of Pr(t))for(let l=0;l<n.length-1;l++){let d=Wt(o,i,n[l],n[(l+1)%n.length]);d&&s.push({point:d,ring:n,edge:l,d:A(o,d)})}s.sort((n,l)=>n.d-l.d||n.edge-l.edge);for(let n of s){let l=new Z(n.point.x+a.x*Ia,n.point.y+a.y*Ia);if(kt(l,t)&&n1(n.point,a,t))return{index:r,point:n.point,ring:n.ring,edge:n.edge}}}return null}function a1(e,t){Tt(t,e);let r=null,o=1/0;for(let i of Pr(t))for(let a=0;a<i.length-1;a++){let s=st(e,i[a],i[(a+1)%i.length]),n=A(e,s);n<o&&(o=n,r={index:1,point:s,ring:i,edge:a})}return r}var Qk=4;function Ik(e,t,r,o,i){let a=A(t[0],t.at(-1))<1e-7,s=a?t.length-1:t.length,n=c=>(c%s+s)%s,l=o===1?r+1:r,d=[e],h=0;for(let c=0;c<s&&h<i;c++){let k=l+o*c;if(!a&&(k<0||k>=s))break;let p=t[n(k)],f=A(d[d.length-1],p);f!==0&&(h+=f,d.push(p))}return d}function Ak(e,t){let r=[e[0]],o=0;for(let i=1;i<e.length;i++){let a=e[i-1],s=e[i],n=A(a,s);for(;n>0&&o+n>=t;){let l=(t-o)/n,d=new Z(a.x+(s.x-a.x)*l,a.y+(s.y-a.y)*l);r.push(d),a=d,n=A(a,s),o=0}o+=n}return r}function Tk(e){return e.length<3?e:e.map((t,r)=>{if(r===0||r===e.length-1)return t;let o=e[r-1],i=e[r+1];return new Z((o.x+t.x+i.x)/3,(o.y+t.y+i.y)/3)})}function Ok(e,t){let r=[];for(let o of e){if(r.length>=3){let i=r[r.length-1];for(let a=1;a<r.length-1;a++){let s=Wt(i,o,r[a-1],r[a]);if(s&&!kt(s,t)){r.length=a,r.push(s);break}}}r.push(o)}return r}var d1=4;function s1(e,t,r,o,i,a){let s=Tk(Ak(Ik(e,t,r,o,Xs*Qk),Ks)),n=[],l=0,d=0,h=!1,c=0;for(let k=0;k<s.length&&!h&&l<Xs;k++){let p=s[Math.max(k-1,0)],f=s[Math.min(k+1,s.length-1)],m=A(p,f);if(m===0)continue;let v=-(f.y-p.y)/m,L=(f.x-p.x)/m,w=(b,u)=>new Z(s[k].x+b*v*ma*u,s[k].y+b*L*ma*u),M=null;for(let b=1;b<=d1&&!M;b++){let u=c===0?[1,-1]:[c];for(let P of u){let C=w(P,b);if(!kt(C,i)&&!(n.length&&xe([n[n.length-1],C],i).length)){M=C,c=P;break}}}if(!M)continue;n.length>0&&(l+=A(n[n.length-1],M)),n.push(M);let x=Math.hypot(M.x,M.y);x>d&&(d=x),x>=a&&(h=!0)}return{points:n,runM:l,escaped:h,furthestM:d}}function Hk(e,t){if(e.points.length===0!=(t.points.length===0))return e.points.length>0?e:t;if(e.escaped!==t.escaped)return e.escaped?e:t;if(e.escaped&&e.runM!==t.runM)return e.runM<t.runM?e:t;if(!e.escaped&&e.furthestM!==t.furthestM)return e.furthestM>t.furthestM?e:t;let r=e.points[e.points.length-1],o=t.points[t.points.length-1];return!r||!o?e:r.x!==o.x?r.x<o.x?e:t:r.y<=o.y?e:t}function zk(e,t){for(let r=1;r<e.length;r++){if(!kt(e[r],t))continue;let o=l1(e[r-1],e[r]);if(!(!o||!n1(e[r],o,t)))return r}return null}function Vk(e,t,r,o){let i=kt(t[0],r),a=i?a1(t[0],r):Rk(t,r);if(!a&&!i){let k=zk(t,r);if(k!==null){let p=a1(t[k-1],r);if(a=p?{...p,index:k}:null,!a)return{points:t.slice(0,k),diagnostics:[`coast: ${e} runs into water with no waterline to follow and ends at the last dry ground it had`]}}}if(!a)return{points:t,diagnostics:[]};let s=i?`water: ${e} leaves the village from a contract entry that is itself in the water; its approach road goes ashore before following the coast`:null,n=t.slice(0,a.index),l=s1(a.point,a.ring,a.edge,1,r,o),d=s1(a.point,a.ring,a.edge,-1,r,o),h=Hk(l,d),c=h.points[0];for(;c&&n.length>=2&&A(n[n.length-1],c)>A(n[n.length-2],c);)n.pop();return h.points.length===0?{points:n,diagnostics:[...s?[s]:[],`coast: ${e} meets water with no dry ground within ${ma*d1} m of the shore and ends there`]}:h.escaped?{points:Ok([...n,...h.points],r),diagnostics:s?[s]:[]}:{points:[...n,h.points[0]],diagnostics:[...s?[s]:[],`coast: ${e} follows the shore for ${Math.round(h.runM)} m without leaving the tile and ends at the water`]}}function h1(e,t,r,o=[]){let i=Bk(r),a=_k(r),s=[],n=[],l=[],d=[...e].filter(k=>k.points.length>=2).sort((k,p)=>k.id.localeCompare(p.id)),h=[],c=new Set;for(let k of d){let p=k.points[k.points.length-1],f=t.filter(m=>A(m.point,p)<=i1);if(f.length!==0){for(let m of f)c.add(m);h.push({id:M2(k.id,"outer"),lane:k,from:k})}}for(let k of d){let p=k.points[0];t.some(f=>!c.has(f)&&A(f.point,p)<=i1)&&h.push({id:M2(k.id,"inner"),lane:k,from:{...k,points:[...k.points].reverse()}})}h.sort((k,p)=>k.lane.id.localeCompare(p.lane.id)||k.id.localeCompare(p.id));for(let k of h){let p=k.lane,f=Ek(k.from,i);if(f.length<2)continue;for(let L of f)Tt(o,L,uo);let m=k.id;if(o.length>0){let L=Vk(m,f,o,a);if(f=ui(L.points,o,Qt(p).surfaceM/2),l.push(...L.diagnostics),f.length<2)continue}let v=qs[p.type];for(let L=1;L<f.length;L++){let w=null,M=1/0,x=f[L];for(let b of s){let u=Yr(f[L],b.points);u.distance<=v&&u.distance<M&&(w=b,M=u.distance,x=u.point)}if(w){f=[...f.slice(0,L),x];let b=[m,w.id].sort();n.push({id:`j:${b.join("+")}`,position:x,laneIds:b});break}}s.push({id:m,type:p.type,widthM:p.widthM,points:f,...p.sourceRouteIds?{sourceRouteIds:p.sourceRouteIds}:{},...p.routeRole?{routeRole:"approach"}:{}})}return{lanes:s,junctions:n,diagnostics:l}}function x2(e,t,r){let o=A(e,t),i=Math.max(1,Math.ceil(o)),a=0,s=0;for(let n=0;n<=i;n++){let l=n/i;if(kt(new Z(e.x+(t.x-e.x)*l,e.y+(t.y-e.y)*l),r.water)){if(a+=o/i,s+=o/i,s>12)return 1/0}else s=0}return o+a*8}function jk(e){return ft(e)<=ft("town")?"town":e==="local"?"local":"footpath"}function k1(e,t,r,o,i){let a=Math.min(1,i/600),s=t==="footpath"?1:t==="town"?2.2+a*.6:1.3+a*.7;return{id:e,routeRole:"street",type:t,points:r,widthM:s+.4,surfaceWidthM:s,setbackM:.6,sourceRouteIds:o}}function $k(e,t,r,o){let i=Math.max(18,t/3.5),a=t*1.7+i*2,s=new Tr(o.x-a*3,o.y-a*3,o.x+a*3,o.y+a*3),n=r.float()*Math.PI*2,l=Math.cos(n),d=Math.sin(n);for(let f=-a;f<=a;f+=i)for(let m=-a;m<=a;m+=i){let v=m+(r.float()-.5)*i*.8,L=f+(r.float()-.5)*i*.8;s.addPoint(new Z(o.x+v*l-L*d,o.y+v*d+L*l))}let h=s.triangulation().filter(f=>Number.isFinite(f.c.x)&&Number.isFinite(f.c.y)&&A(f.c,o)<=t*1.65+i),c=h.map(f=>({p:f.c,edges:[]})),k=new Map(s.points.map((f,m)=>[f,m])),p=new Map;return h.forEach((f,m)=>{for(let[v,L]of[[f.p1,f.p2],[f.p2,f.p3],[f.p3,f.p1]]){let w=[k.get(v),k.get(L)].sort((u,P)=>u-P).join(":"),M=p.get(w);if(M===void 0){p.set(w,m);continue}if(kt(c[m].p,e.water)||kt(c[M].p,e.water))continue;let x=x2(c[m].p,c[M].p,e);if(!Number.isFinite(x))continue;let b={a:m,b:M,cost:x,sources:new Set};c[m].edges.push(b),c[M].edges.push(b)}}),c}function Nk(e,t,r){let o=e.map(()=>1/0),i=new Map,a=new Set;for(o[t]=0;;){let n=-1,l=1/0;for(let d=0;d<e.length;d++)!a.has(d)&&o[d]<l&&(l=o[d],n=d);if(n<0)return null;if(n===r)break;a.add(n);for(let d of e[n].edges){let h=d.a===n?d.b:d.a,c=l+d.cost*(d.type?.65:1);c<o[h]&&(o[h]=c,i.set(h,d))}}let s=[];for(let n=r;n!==t;){let l=i.get(n);s.push(l),n=l.a===n?l.b:l.a}return s}function Dk(e){let t=new Map;for(let r of e)for(let o of[r.points[0],r.points[r.points.length-1]]){let i=t.get(o)??[];i.push(r.id),t.set(o,i)}return[...t].filter(([,r])=>r.length>=2).map(([r,o],i)=>({id:`j:routed-${i}`,position:r,laneIds:o.sort()}))}function c1(e,t,r,o,i){let a={trunks:[],junctions:[],pattern:"terminal",aim:i,ring:[],diagnostics:[]};if(!t.length)return a;let s=[...t].sort((b,u)=>ft(b.route.type)-ft(u.route.type)||b.bearingDeg-u.bearingDeg||(b.route.routeId??"").localeCompare(u.route.routeId??"")),n=s[0],l=s.find(b=>b!==n&&b.route.type===n.route.type&&ft(b.route.type)<=ft("market")&&Qe(b.bearingDeg,n.bearingDeg)>=120);if(e.population<=120&&t.length===2&&l&&e.water.length===0){let b=n.route.type,u=p1(n.point,l.point,b,o),P={id:Ra(b,n.route.routeId,n.bearingDeg,!1),type:b,points:u,routeRole:"through",widthM:ve(b),sourceRouteIds:[...new Set(t.map(C=>Co(C.route.routeId,C.bearingDeg)))].sort()};return{...a,trunks:[P],pattern:"main-street"}}let d=$k(e,r,o,i),h=b=>d.map((u,P)=>({node:u,i:P,d:A(b,u.p)})).filter(u=>u.node.edges.length&&!kt(u.node.p,e.water)).sort((u,P)=>u.d-P.d),c=h(i)[0]?.i;if(c===void 0)throw new Error("No dry street junction near the village centre");let k=d[c].p,p=new Map,f=new Set,m=[];for(let b of s){let u=Lt(b.bearingDeg),P=new Z(i.x+u.x*r*1.15,i.y+u.y*r*1.15),C=m.find(X=>Qe(X.entry.bearingDeg,b.bearingDeg)<12),Q=C?.node??-1,R=null;for(let X of C?[{i:C.node}]:h(P))if(R=Nk(d,X.i,c),R){Q=X.i;break}if(Q<0||!R)throw new Error("No connected street for an incoming route");let V=jk(b.route.type),j=Co(b.route.routeId,b.bearingDeg);for(let X of R)(!X.type||ft(V)<ft(X.type))&&(X.type=V),X.sources.add(j),f.add(X);let F=new Z(b.point.x-u.x*12,b.point.y-u.y*12),K=Q,H=new Z(b.point.x*.72+i.x*.28,b.point.y*.72+i.y*.28);for(let X of C?[F,b.point]:[H,F,b.point]){let nt=d.length;d.push({p:X,edges:[]});let mt={a:K,b:nt,cost:A(d[K].p,X),type:V,sources:new Set([j])};d[K].edges.push(mt),d[nt].edges.push(mt),f.add(mt),K=nt,X===H&&m.push({entry:b,node:nt})}p.set(K,b)}let v=d.map(b=>b.edges.filter(u=>f.has(u))),L=new Set,w=[],M=new Set,x=b=>{let u=b;for(let P=2;M.has(u);P++)u=`${b}~${P}`;return M.add(u),u};for(let b=0;b<d.length;b++)if(!(v[b].length===2&&b!==c))for(let u of v[b]){if(L.has(u))continue;let P=[b],C=new Set,Q=b,R=u,V="footpath";for(;;){L.add(R);for(let J of R.sources)C.add(J);if(ft(R.type)<ft(V)&&(V=R.type),Q=R.a===Q?R.b:R.a,P.push(Q),v[Q].length!==2||Q===c)break;let $=v[Q].find(J=>J!==R);if(L.has($))break;R=$}p.has(P[0])&&P.reverse();let j=Qa(P.map($=>d[$].p),e.water);for(let $=1;$+1<j.length;$++){let J=j[$-1],lt=j[$],xt=j[$+1];(A(lt,st(lt,J,xt))<3||Qe(pt(J,lt),pt(lt,xt))>110)&&Number.isFinite(x2(J,xt,e))&&(j.splice($,1),$=Math.max(0,$-2))}let F=Xr(j)??j,K=F.some(($,J)=>J>0&&!Number.isFinite(x2(F[J-1],$,e)))?j:F,H=[K[0]];for(let $=1;$<K.length;$++){let J=K[$-1],lt=K[$],xt=Math.max(1,Math.ceil(A(J,lt)/3));for(let zt=1;zt<=xt;zt++)H.push(zt===xt?lt:new Z(J.x+(lt.x-J.x)*zt/xt,J.y+(lt.y-J.y)*zt/xt))}let X=[...C].sort(),nt=p.get(P[P.length-1]),mt=nt?.route.type??s.filter($=>X.includes(Co($.route.routeId,$.bearingDeg))).map($=>$.route.type).sort(($,J)=>ft($)-ft(J))[0]??V;if(!nt&&H.every($=>A($,k)<r*1.15)){w.push(k1(x(`trunk-street-${w.length}`),V,H,X,e.population));continue}A(H[0],k)>A(H[H.length-1],k)&&H.reverse();let O=r*1.15,Y=H.findIndex(($,J)=>J>0&&A($,k)>=O);Y<1&&(Y=1),Y>=H.length-1&&(Y=H.length-2);let rt=H.every($=>A($,k)>=O),yt=rt?[]:H.slice(0,Y+1),B=rt?H:H.slice(Y);yt.length>=2&&w.push(k1(x(`trunk-street-${w.length}`),V,yt,X,e.population));let U=mt;w.push({id:x(nt?Ra(U,nt.route.routeId,nt.bearingDeg,!1):`trunk-approach-${w.length}`),type:U,points:B,routeRole:"approach",widthM:ve(U),sourceRouteIds:X})}return{...a,trunks:w,junctions:Dk(w),aim:k,pattern:t.length>1?"routed":"terminal"}}var Fk=.12,f1=.55,Gk=6;var Wk=1.5,Uk=45;function L1(e,t,r,o){let i=1-o,a=i*i,s=2*i*o,n=o*o;return new Z(a*e.x+s*t.x+n*r.x,a*e.y+s*t.y+n*r.y)}function qk(e,t,r){let i=0,a=e;for(let s=1;s<=24;s++){let n=L1(e,t,r,s/24);i+=Z.distance(a,n),a=n}return i}function Z2(e,t,r){let o=qk(e,t,r),i=Math.max(1,Math.ceil(o/Gk)),a=[];for(let s=1;s<=i;s++)a.push(L1(e,t,r,s/i));return a}function p1(e,t,r,o){let i=t.x-e.x,a=t.y-e.y,s=Math.hypot(i,a),n=l5[r];if(s===0)return[e.clone(),t.clone()];let l=new Z(-a/s,i/s),d=c=>{let k=o.float()<.5?-1:1,p=f1+o.float()*(1-f1);return k*p*c*s},h=[e.clone()];if(n>=Fk){let c=d(n*.5),k=d(n),p=new Z(e.x*.75+t.x*.25+l.x*c,e.y*.75+t.y*.25+l.y*c),f=new Z(e.x*.25+t.x*.75+l.x*k,e.y*.25+t.y*.75+l.y*k),m=new Z((p.x+f.x)/2,(p.y+f.y)/2);h.push(...Z2(e,p,m)),h.push(...Z2(m,f,t))}else{let c=d(n),k=new Z((e.x+t.x)/2+l.x*c,(e.y+t.y)/2+l.y*c);h.push(...Z2(e,k,t))}return h}function y1(e){return e*n5}function Ce(e){return e.startsWith("trunk-")&&!e.includes("/b")}function Kk(e,t){let r=[];for(let o of e.routes)r.push(Yk(o,o.bearingDeg,t,!1));return r.sort((o,i)=>o.bearingDeg!==i.bearingDeg?o.bearingDeg-i.bearingDeg:o.farSide!==i.farSide?o.farSide?1:-1:(o.route.routeId??"").localeCompare(i.route.routeId??"")),r}function Yk(e,t,r,o){let i=Lt(t);return{point:new Z(i.x*r,i.y*r),bearingDeg:t,route:e,farSide:o}}function P2(e){let t=[...e];for(let r=0;r<6&&t.length>3;r++){let o=Math.atan2(t[1].y-t[0].y,t[1].x-t[0].x),i=Math.atan2(t[2].y-t[1].y,t[2].x-t[1].x),a=Math.abs((i-o)*180/Math.PI);if(a>180&&(a=360-a),a<=Uk)break;t.splice(1,1)}return t}function m1(e){return[...e].sort()}function v1(e){return P2([...e].reverse()).reverse()}function w1(e){return e.replace(/[^a-zA-Z0-9]/g,"_")}function Xk(e,t){for(let r=1;r<e.length;r++)for(let o=1;o<t.length;o++){let i=Wt(e[r-1],e[r],t[o-1],t[o]);if(i)return{aIdx:r-1,bIdx:o-1,point:i}}return null}function Jk(e){for(let t=0;t<e.length;t++)for(let r=t+1;r<e.length;r++){let o=Xk(e[t].points,e[r].points);if(o)return{i:t,j:r,hit:o}}return null}function t4(e,t){let r=e,o=t,i=e.length*e.length+8;for(let a=0;a<i;a++){let s=Jk(r);if(!s)return{trunks:r,junctions:o};let{i:n,j:l,hit:d}=s,h=r[n],c=r[l],k={...h,points:v1([...h.points.slice(0,d.aIdx+1),d.point])},p={...h,id:`${h.id}~x${w1(c.id)}`,points:P2([d.point,...h.points.slice(d.aIdx+1)])},f={...c,points:v1([...c.points.slice(0,d.bIdx+1),d.point])},m={...c,id:`${c.id}~x${w1(h.id)}`,points:P2([d.point,...c.points.slice(d.bIdx+1)])},v=[...r];v[n]=k,v[l]=f,v.push(p,m),r=v,o=[...o,{id:`j:${m1([k.id,p.id,f.id,m.id]).join("+")}`,position:d.point,laneIds:m1([k.id,p.id,f.id,m.id])}]}throw new Error("resolveCrossings exceeded its iteration cap -- the no-proper-crossing invariant loop should always terminate given a finite, fixed set of underlying segments; this means a real bug (e.g. a split that does not shrink the crossing count), not a legitimately busy network.")}function e4(e,t){let r=new Set(e.filter(a=>a.points.length>=2).map(a=>a.id)),o=[],i=new Set;for(let a of t){if(!e.some(d=>d.points.length>=2&&Yr(a.position,d.points).distance<=Wk))continue;let n=a.laneIds.filter(d=>r.has(d));if(n.length===0)continue;let l={...a,laneIds:n};i.has(l.id)||(i.add(l.id),o.push(l))}return o}function M1(e,t,r,o,i=new Z(0,0)){let a=Kk(e,t),s=c1(e,a,r,o,i),n=k=>`${k.x.toFixed(6)},${k.y.toFixed(6)}`,l=new Map;for(let k of s.trunks)for(let p of[k.points[0],k.points.at(-1)]){if(a.some(m=>A(m.point,p)<.001))continue;let f=Qt(k).surfaceM/2+g2;f>(l.get(n(p))?.clearance??0)&&l.set(n(p),{p,clearance:f})}for(let k of l.values())k.p=b2(k.p,e.water,k.clearance);let d=k=>l.get(n(k))?.p??k;s.junctions=s.junctions.map(k=>({...k,position:d(k.position)})),s.aim=d(s.aim),s.trunks=s.trunks.map(k=>({...k,points:k.points.map((p,f)=>f===0||f===k.points.length-1?d(p):p)})),s.trunks=s.trunks.map(k=>({...k,points:ui(k.points,e.water,Qt(k).surfaceM/2)}));let h=h1(s.trunks,a,t,e.water),c=t4([...s.trunks,...h.lanes],[...s.junctions,...h.junctions]);return{...s,trunks:c.trunks,junctions:e4(c.trunks,c.junctions),entries:a,contractRadiusM:t,diagnostics:[...s.diagnostics,...h.diagnostics]}}function Qt(e){return{corridorM:e.widthM,surfaceM:e.surfaceWidthM??e.widthM*(ft(e.type)<ft("local")?1:Il),setbackM:e.setbackM??z3[e.type]??2}}function Be(e){let t=Qt(e);return t.corridorM/2+t.setbackM}function Aa(e,t){if(Ce(e.id)||(e={...e,routeRole:"street",type:ft(e.type)<=ft("town")?"town":e.type==="local"?"local":"footpath"},e.surfaceWidthM!==void 0))return e;let r=Math.min(1,Math.max(0,(t-8)/80)),o=e.type==="footpath"?1:e.type==="trail"?1.4:1.2+1.2*r;return{...e,widthM:o+.4,surfaceWidthM:o,setbackM:.5+.2*r}}var S2=q2(w2(),1);function u1(e,t,r,o,i=[]){if(e.length>=3&&i.length){let s=i.filter(c=>S2.default.intersection([e.map(k=>[k.x,k.y])],[c.map(k=>[k.x,k.y])]).length>0),n=[e,...s].map(c=>[c.map(k=>[k.x,k.y])]),l=S2.default.union(n[0],...n.slice(1)),d=c=>Math.abs(c.reduce((k,p,f)=>{let m=c[(f+1)%c.length];return k+p[0]*m[1]-m[0]*p[1]},0)),h=l.map(c=>c[0]).sort((c,k)=>d(k)-d(c))[0];h&&(e=h.slice(0,-1).map(([c,k])=>new Z(c,k)))}let a={polylines:[],gates:[],towers:[],large:!1,material:o==="desert"?"rubble":"palisade"};for(let s=0;s<e.length;s++){let n=e[s],l=e[(s+1)%e.length],d=l.x-n.x,h=l.y-n.y,c=Math.hypot(d,h);for(let k of dr(n,l,r)){let p=a.polylines.at(-1);p&&Math.hypot(p.at(-1).x-k[0].x,p.at(-1).y-k[0].y)<1e-6?p.push(k[1]):a.polylines.push([...k])}for(let k of t)for(let p=1;p<k.points.length;p++){let f=k.points[p-1],m=k.points[p],v=m.x-f.x,L=m.y-f.y,w=d*L-h*v;if(Math.abs(w)<1e-8)continue;let M=((f.x-n.x)*L-(f.y-n.y)*v)/w,x=((f.x-n.x)*h-(f.y-n.y)*d)/w;if(M<0||M>1||x<0||x>1)continue;let b=n.x+M*d,u=n.y+M*h;if(a.gates.some(Q=>Math.hypot((Q.p1.x+Q.p2.x)/2-b,(Q.p1.y+Q.p2.y)/2-u)<.5))continue;let P=Math.abs(w)/(c*Math.hypot(v,L)),C=(Qt(k).surfaceM+1)/2/Math.max(.12,P);a.gates.push({p1:{x:b-d/c*C,y:u-h/c*C},p2:{x:b+d/c*C,y:u+h/c*C},routeIds:k.sourceRouteIds??[]})}}return a}function g1(e,t,r){let o=[];for(let a of[...e,...t.filter(s=>!["stone-circle","boathouse"].includes(s.kind))]){let s="footprint"in a?a.footprint:re(a.glyph),n=pe(a.glyph,s),l=a.bearingDeg*Math.PI/180,d=Math.cos(l),h=Math.sin(l);for(let c of[-n.width/2,n.width/2])for(let k of[-n.depth/2,n.depth/2])o.push(new Z(a.position.x+c*d-k*h,a.position.y+k*d+c*h))}let i=po(o);return i.length<3?r:i.map((a,s)=>{let n=i[(s+i.length-1)%i.length],l=i[(s+1)%i.length],d=Z.distance(n,a),h=Z.distance(a,l),c={x:(a.y-n.y)/d,y:(n.x-a.x)/d},k={x:(l.y-a.y)/h,y:(a.x-l.x)/h},p=3.5/(1+c.x*k.x+c.y*k.y);return new Z(a.x+(c.x+k.x)*p,a.y+(c.y+k.y)*p)})}function Ze(e,t,r){if(e.length<2)return[];let o=[];for(let a=0;a<e.length-1;a++){let s=We(e[a+1].x-e[a].x,e[a+1].y-e[a].y);o.push(new Z(-s.y*r,s.x*r))}let i=[];for(let a=0;a<e.length;a++){let s=o[Math.max(0,a-1)],n=o[Math.min(a,o.length-1)],l=We(s.x+n.x,s.y+n.y),d=l.x*n.x+l.y*n.y,h=d===0?1:1/d,c=Math.min(Math.abs(h),4)*Math.sign(h||1);i.push(new Z(e[a].x+l.x*t*c,e[a].y+l.y*t*c))}return i}function wt(e){let t=Lt(e.bearingDeg),r=new Z(-t.x,-t.y),o=new Z(-t.y,t.x),i=e.depthM/2;return{center:new Z(e.front.x+r.x*i,e.front.y+r.y*i),tangent:o,normal:r,halfW:e.frontageM/2,halfD:i}}function oe(e,t,r=0){let o=new Z(t.center.x-e.center.x,t.center.y-e.center.y);for(let i of[e.tangent,e.normal,t.tangent,t.normal]){let a=Math.abs(o.x*i.x+o.y*i.y),s=Math.abs(e.tangent.x*i.x+e.tangent.y*i.y)*e.halfW+Math.abs(e.normal.x*i.x+e.normal.y*i.y)*e.halfD,n=Math.abs(t.tangent.x*i.x+t.tangent.y*i.y)*t.halfW+Math.abs(t.normal.x*i.x+t.normal.y*i.y)*t.halfD;if(a>=s+n-r)return!1}return!0}function gi(e,t,r=0){let o=new Z(e.x-t.center.x,e.y-t.center.y),i=Math.abs(o.x*t.tangent.x+o.y*t.tangent.y),a=Math.abs(o.x*t.normal.x+o.y*t.normal.y);return i<=t.halfW+r&&a<=t.halfD+r}function Bo(e){return wt({...e,depthM:Math.min(e.depthM,$3)})}function we(e,t){let r=0,o=e.depthM;for(let i=0;i<8;i++){let a=(r+o)/2,s=wt({...e,depthM:a});oe(s,t)?o=a:r=a}return r}function r4(e,t){let r=new Set,o=new Map,i=new Map;for(let a of e){let s=`${a.laneId} ${a.side}`,n=i.get(s);n?n.push(a):i.set(s,[a])}for(let a of i.values()){if(a.length<2)continue;let s=[...a].sort((h,c)=>Mi(h.id)-Mi(c.id)),l=s.reduce((h,c)=>h+c.frontageM,0)/s.length*V3,d=s[0];for(let h=1;h<s.length;h++){let c=s[h];if(A(d.front,c.front)<l){r.add(c.id),t?.set(c.id,"inner-fold");continue}let k=wt(d);if(!oe(k,wt(c))){d=c;continue}if(!oe(Bo(d),Bo(c))){let v=we(d,Bo(c));o.set(d.id,v);let L=we(c,wt({...d,depthM:v}));o.set(c.id,L),d={...c,depthM:L};continue}let p=we(c,k);if(p>=Bs){o.set(c.id,p),d={...c,depthM:p};continue}let f=Math.min(d.depthM,Re),m=we(c,wt({...d,depthM:f}));if(m>=Re){let v=Math.min(d.depthM,Math.max(f,we(d,wt({...c,depthM:m}))));o.set(d.id,v);let L=we(c,wt({...d,depthM:v}));o.set(c.id,L),d={...c,depthM:L};continue}r.add(c.id),t?.set(c.id,"inner-wander")}}return e.filter(a=>!r.has(a.id)).map(a=>o.has(a.id)?{...a,depthM:o.get(a.id)}:a)}function b1(e,t){if(e==="green")return-1;let r=t.get(e);return r?ft(r):ft("footpath")}function o4(e,t,r,o){let i=new Map(t.map(k=>[k.id,k.type])),a=new Map(t.map(k=>[k.id,k])),s=k=>A(k.front,r.centre),n=k=>Math.hypot(k.frontageM/2,k.depthM),l=[...e].sort((k,p)=>k.id.localeCompare(p.id)),d=new Map,h=new Set,c=k=>{let p=d.get(k.id);return p===void 0?k:{...k,depthM:p}};for(let k=0;k<l.length;k++){let p=l[k];if(!h.has(p.id))for(let f=k+1;f<l.length;f++){let m=l[f];if(h.has(m.id)||p.laneId===m.laneId&&p.side===m.side&&Math.abs(Mi(p.id)-Mi(m.id))===1&&p.laneId!=="green")continue;let w=c(p),M=c(m);if(A(w.front,M.front)>n(w)+n(M)||!oe(wt(w),wt(M)))continue;let x=b1(w.laneId,i),b=b1(M.laneId,i),u=w,P=M;if(x!==b)b<x&&(u=M,P=w);else{let j=s(w),F=s(M);j!==F?F<j&&(u=M,P=w):w.laneId!==M.laneId?M.laneId.localeCompare(w.laneId)<0&&(u=M,P=w):M.id.localeCompare(w.id)<0&&(u=M,P=w)}let C=j=>{o&&o.set(P.id,`${a4(P,u,a)}/${j}`)};if(!oe(Bo(u),Bo(P))){let j=we(u,Bo(P));d.set(u.id,j);let F=we(P,wt({...u,depthM:j}));d.set(P.id,F);continue}let Q=j=>wt({...j,depthM:Math.min(j.depthM,Re)});if(!oe(Q(u),Q(P))){let j=Math.min(u.depthM,Math.max(Re,we(u,Q(P)))),F=we(P,wt({...u,depthM:j}));if(F>=Re){d.set(u.id,j),d.set(P.id,F);continue}}let R=wt(u);if(gi(P.front,R)){h.add(P.id),C("front-inside");continue}let V=we(P,R);V<Bs?(h.add(P.id),C("too-shallow")):d.set(P.id,V)}}return e.filter(k=>!h.has(k.id)).map(k=>c(k))}function x1(e,t,r,o){return o4(r4(e,o),t,r,o)}var i4=20;function a4(e,t,r){if(e.laneId===t.laneId)return"cross-same-lane";if(t.laneId==="green"||e.laneId==="green")return"cross-green-ring";let o=r.get(e.laneId),i=r.get(t.laneId);if(!o||!i)return"cross-other-lane";let a=1/0;for(let s=1;s<o.points.length;s++)for(let n=0;n<i.points.length;n++){let l=st(i.points[n],o.points[s-1],o.points[s]);A(i.points[n],l)<=1.5&&(a=Math.min(a,A(e.front,l)))}return a<=i4?"cross-junction-mouth":"cross-parallel-lanes"}function Z1(e){let t=Math.min(1,Math.max(0,(e-Cs)/(I3-Cs)));return Ss+(Q3-Ss)*t}function bi(e,t,r){let o=t<=0?0:Math.min(da,e/t);return r*(1+la*Math.pow(o,na))}function P1(e,t,r,o,i,a,s=0,n=1/0,l=1/0){let d=typeof l=="function"?l:()=>l,h=[],c=Be(e);for(let k of[1,-1]){let p=Ze(e.points,c,k);if(p.length<2)continue;let f=gt(p),m=f[f.length-1],v=0,L=0;for(;v<m;){let{p:w}=ut(p,f,v),M=A(w,t.centre),x=1+(a.float()-.5)*2*A3,b=Math.max(s,n),u=Math.min(b,Math.max(s,o*ha,bi(M,r,o)*x));if(v+u>m)break;let P=ut(p,f,v+u/2),C=(P.dirDeg+(k===1?-90:90)+360)%360;if(M>d(w)){v+=u,L++;continue}h.push({id:Ea(e.id,k,L),laneId:e.id,side:k,front:P.p,bearingDeg:C,frontageM:u,depthM:i,score:0});let Q=Ba(ut(p,f,v).dirDeg,ut(p,f,Math.min(m,v+u)).dirDeg),V=(k===1?Q>0:Q<0)?i*Math.abs(Q*Math.PI/180):0;v+=u+V+Mo,L++}}return h}function S1(e,t,r,o,i=[]){let a=e.diameter/2*Lo+gr,s=2*Math.PI*a,n=Math.PI*2,l=o.float()*(n/Math.max(4,Math.floor(s/t))),d=[],h=a+t;for(let f of i){let m=(f.widthM/2+t*O3)/a;for(let v=1;v<f.points.length;v++){let L=f.points[v-1],w=f.points[v],M=A(L,w),x=Math.max(1,Math.ceil(M/2));for(let b=0;b<=x;b++){let u=new Z(L.x+(w.x-L.x)*b/x,L.y+(w.y-L.y)*b/x);if(A(u,e.centre)>h)continue;let P=Math.atan2(u.x-e.centre.x,-(u.y-e.centre.y));d.push([P-m,P+m])}}}let c;if(d.length===0)c=[[l,l+n]];else{let f=d.map(([m,v])=>[(m%n+n)%n,v-m]).map(([m,v])=>[m,m+v]).sort((m,v)=>m[0]-v[0]).reduce((m,[v,L])=>{let w=m[m.length-1];return w&&v<=w[1]?w[1]=Math.max(w[1],L):m.push([v,L]),m},[]);c=[];for(let m=0;m<f.length;m++){let v=f[m][1],L=m===f.length-1?f[0][0]+n:f[m+1][0];L>v&&c.push([v,L])}}let k=[],p=0;for(let[f,m]of c){let v=(m-f)*a,L=d.length===0?Math.max(4,Math.floor(v/t)):Math.floor(v/t);if(L<1)continue;let w=(m-f)/L;for(let M=0;M<L;M++){let x=f+(M+.5)*w,b=new Z(e.centre.x+a*Math.sin(x),e.centre.y-a*Math.cos(x)),u=pt(b,e.centre);k.push({id:Ea("green",1,p),laneId:"green",side:1,front:b,bearingDeg:u,frontageM:v/L,depthM:r,score:0}),p++}}return k}function s4(e,t){if(Tt(t,e.front,Math.hypot(e.frontageM/2,e.depthM)),t.length===0)return!1;let r=wt(e),o=r.tangent,i=r.normal,a=(n,l)=>new Z(r.center.x+o.x*n*r.halfW+i.x*l*r.halfD,r.center.y+o.y*n*r.halfW+i.y*l*r.halfD),s=[a(-1,-1),a(1,-1),a(1,1),a(-1,1)];if(kt(r.center,t)||s.some(n=>kt(n,t)))return!0;for(let n=0;n<s.length;n++){let l=s[n],d=s[(n+1)%s.length];for(let h of t)for(let c=0;c<h.length;c++){let k=h[c],p=h[(c+1)%h.length];if(Wt(l,d,k,p))return!0}}return!1}function C2(e,t,r){let o=t.diameter/2;return e.filter(i=>{if(s4(i,r))return!1;let a=A(i.front,t.centre);return!(i.laneId!=="green"&&a<o)})}function C1(e,t,r){return e.map(o=>{let i=A(o.front,t.centre),a=r.get(o.laneId),s=a?(7-ft(a))*el:0,n=o.laneId==="green"?rl:0;return{...o,score:J3-i*tl+s+n}})}function Eo(e){return[...e].sort((t,r)=>r.score-t.score||t.id.localeCompare(r.id))}var n4=1+la*Math.pow(da,na);function l4(e,t,r,o){if(o<=0)return 0;let i=A(e.front,t.centre),a=bi(i,r,o)/o;if(a<=ka)return 0;let s=n4-ka;return(s<=0?1:Math.min(1,(a-ka)/s))*ll}function B2(e){let t=Lt(e.bearingDeg),r=new Z(-t.x,-t.y);return{tangent:new Z(-t.y,t.x),normal:r}}function d4(e,t){if(!t)return e.depthM;let{normal:r}=B2(e),i=(t.position.x-e.front.x)*r.x+(t.position.y-e.front.y)*r.y+pe(t.glyph,t.footprint).depth/2+hl;return Math.min(e.depthM,Math.max(0,i))}function B1(e,t,r){let{tangent:o,normal:i}=B2(e),a=(e.depthM+r-t)/2,s=t+a;return{center:new Z(e.front.x+i.x*s,e.front.y+i.y*s),tangent:o,normal:i,halfW:e.frontageM/2,halfD:a}}function E1(e){let{center:t,tangent:r,normal:o,halfW:i,halfD:a}=e,s=[];for(let n of[-1,1])for(let l of[-1,1])s.push(new Z(t.x+r.x*i*n+o.x*a*l,t.y+r.y*i*n+o.y*a*l));return s.push(new Z(t.x+o.x*a,t.y+o.y*a)),s.push(new Z(t.x-o.x*a,t.y-o.y*a)),s.push(new Z(t.x+r.x*i,t.y+r.y*i)),s.push(new Z(t.x-r.x*i,t.y-r.y*i)),s}function h4(e){return Be(e)}function k4(e,t){if(t.points.length<2)return!1;let r=h4(t);for(let o=1;o<t.points.length;o++){let i=t.points[o-1],a=t.points[o],s=A(i,a),n=Math.max(1,Math.ceil(s/2));for(let l=0;l<=n;l++){let d=new Z(i.x+(a.x-i.x)*l/n,i.y+(a.y-i.y)*l/n);if(gi(d,e,r))return!0}}return!1}function c4(e,t){let r=Ct(t);return E1(e).some(o=>A(o,t.centre)<r)}function p4(e,t){return E1(e).some(r=>kt(r,t))}function f4(e,t,r,o,i,a,s,n){let l=c=>{let k=B1(e,t,c);if(!(k.halfD>0))return!0;if(o.some(p=>k4(k,p))||c4(k,i)||p4(k,a))return!1;for(let p of s)if(p.id!==e.id&&oe(k,wt(p)))return!1;for(let p of n)if(oe(k,p))return!1;return!0};if(l(r))return r;let d=0,h=r;for(let c=0;c<10;c++){let k=(d+h)/2;l(k)?d=k:h=k}return d}function m4(e,t,r){let{tangent:o,normal:i}=B2(e),a=e.frontageM/2,s=new Z(e.front.x+i.x*t,e.front.y+i.y*t),n=e.depthM+r,l=new Z(e.front.x+i.x*n,e.front.y+i.y*n),d=new Z(s.x-o.x*a,s.y-o.y*a),h=new Z(s.x+o.x*a,s.y+o.y*a),c=new Z(l.x-o.x*a,l.y-o.y*a),k=new Z(l.x+o.x*a,l.y+o.y*a);return[d,h,k,c]}function _1(e,t,r,o,i,a,s){let n=new Map(t.map(c=>[c.lotId,c])),l=Eo(e).filter(c=>n.has(c.id)),d=[],h=[];for(let c of l){let k=l4(c,r,a,s);if(k<=0)continue;let p=d4(c,n.get(c.id)),f=f4(c,p,k,o,r,i,e,h);if(f<dl)continue;let m=`croft:${c.id}`,v=m4(c,p,f);d.push({id:m,lotId:c.id,polygon:v,depthM:f}),h.push(B1(c,p,f))}return d}function R1(e,t,r){let i={...As[e]??As.temperate};t<sl&&(i.none=(i.none??0)+nl);let a=ai.reduce((n,l)=>n+(i[l]??0),0);if(a<=0)return"none";let s=r.float()*a;for(let n of ai)if(s-=i[n]??0,s<=0)return n;return ai[ai.length-1]}var ie=Math.round(360/fa);function Q1(e,t,r){let o=i=>{let a=((i/fa-.5)%ie+ie)%ie,s=Math.floor(a),n=a-s;return t[s%ie]+(t[(s+1)%ie]-t[s%ie])*n};return{atBearing:o,at:i=>o(pt(e,i)),maxM:Math.max(r,...t),plus:i=>Q1(e,t.map(a=>a+i),r+i)}}function xi(e,t,r,o=1){let i=Array.from({length:ie},()=>[]);for(let l of t){let d=(Math.floor(pt(e,l)/fa)%ie+ie)%ie;i[d].push(A(e,l))}let a=i.map(l=>{if(l.length===0)return null;let d=l.sort((c,k)=>c-k),h=Math.min(d.length-1,Math.max(0,Math.round(o*(d.length-1))));return d[h]}),s=a.map((l,d)=>{if(l!==null)return l;for(let h=1;h<=ie;h++){let c=a[(d+h)%ie],k=a[(d-h+ie)%ie];if(c!==null&&k!==null)return(c+k)/2;if(c!==null)return c;if(k!==null)return k}return r}),n=s.map((l,d)=>(s[(d-1+ie)%ie]+s[d]+s[(d+1)%ie])/3);return Q1(e,n.map(l=>Math.max(r,l)),r)}function _2(e){let{center:t,tangent:r,normal:o,halfW:i,halfD:a}=e,s=(n,l)=>new Z(t.x+r.x*i*n+o.x*a*l,t.y+r.y*i*n+o.y*a*l);return[s(-1,-1),s(1,-1),s(1,1),s(-1,1)]}function v4(e,t,r,o){let i=[];for(let a of t){if(o&&!o.has(a.id))continue;let s=wt(a),n=0;for(let l of _2(s))n=Math.max(n,A(e.centre,l));i.push(n)}for(let a of r){if(a.polygon.length===0)continue;let s=0;for(let n of a.polygon)s=Math.max(s,A(e.centre,n));i.push(s)}return i}function R2(e,t,r,o){let i=Ct(e);for(let a of v4(e,t,r,o))i=Math.max(i,a);return i}function Ta(e,t,r){let o=[];for(let i of e)r&&!r.has(i.id)||o.push(..._2(wt(i)));for(let i of t)o.push(...i.polygon);return o}function w4(e,t,r,o){let i=Ct(e)+gr+pl;return xi(e.centre,Ta(t,r,o),i,cl)}function L4(e,t,r){let o=ml,i=360/o,a=[];for(let l=0;l<o;l++)a.push(Ts+r.float()*(fl-Ts));let s=a.map((l,d)=>(a[(d-1+o)%o]+a[d]*2+a[(d+1)%o])/4),n=[];for(let l=0;l<o;l++){let d=l*i,h=0;for(let p=-6;p<=6;p++)h=Math.max(h,t.atBearing(d+p*i/12));let c=Lt(d),k=h+s[l];n.push(new Z(e.centre.x+c.x*k,e.centre.y+c.y*k))}return n}function y4(e,t,r,o){let i=vl,a=[],s=[];for(let k=0;k<i;k++)a.push(fe(k*360/i+(o.float()*2-1)*wl)),s.push(1+(o.float()*2-1)*Ll);let n=a.map(k=>{let p=0;for(let f of t)Math.abs((pt(e.centre,f)-k+540)%360-180)<360/i&&(p=Math.max(p,A(e.centre,f)));if(p===0)for(let f of t)p=Math.max(p,A(e.centre,f));return p}),l=$e(t),d=k=>po(a.map((p,f)=>{let m=Lt(p),v=n[f]+k*s[f];return new Z(e.centre.x+m.x*v,e.centre.y+m.y*v)})),h=yl,c=Ml;if($e(d(c))-l<=r)return d(c);if($e(d(h))-l>=r)return d(h);for(let k=0;k<40;k++){let p=(h+c)/2;$e(d(p))-l<r?h=p:c=p}return d((h+c)/2)}function M4(e,t,r){let o=t.filter(s=>Ot(s.id)&&s.points.length>=1),i=s=>{if(s.points.length===0)return!1;let n=s.points[s.points.length-1];return o.some(l=>A(l.points[0],n)<=1e-6)},a=[];for(let s of t){if(s.parentId!==void 0||i(s)||s.points.length<2)continue;let n=s.points[s.points.length-1],l=s.points[s.points.length-2];if(!bt(n,r)){let d=pt(l,n),h=Lt(d);a.push({p:n,dirDeg:d,halfWidthM:Be(s)+Bl,outX:h.x,outY:h.y})}}return a}function u4(e,t,r,o,i=[]){let a=[],s=l=>{if(l.length<3)return;let d=co(l),h=0;for(let c of l)h=Math.max(h,A(d,c));a.push({poly:l,centre:d,radiusM:h})};for(let l of e)s(_2(wt(l)));for(let l of t)s(l.polygon);for(let l of i)s(l);let n=[];for(let l of r){let d=Be(l);for(let h=1;h<l.points.length;h++)n.push({a:l.points[h-1],b:l.points[h],clearanceM:d})}return{claims:a,segs:n,water:o}}function g4(e,t){if(kt(e,t.water))return{kind:"water"};for(let r of t.claims)if(!(A(e,r.centre)>r.radiusM+si)&&(bt(e,r.poly)||H1(e,r.poly)<=si/2))return{kind:"claim",obstacle:r};for(let r of t.segs)if(A(e,st(e,r.a,r.b))<=r.clearanceM)return{kind:"lane",seg:r};return null}function T1(e){let t=[];for(let r=0;r<e.length;r++){let o=e[r],i=e[(r+1)%e.length],a=Math.max(1,Math.ceil(A(o,i)/Ql));for(let s=0;s<a;s++){let n=s/a;t.push(new Z(o.x+(i.x-o.x)*n,o.y+(i.y-o.y)*n))}}return t.push(co(e)),t}function I1(e,t){for(let r of T1(e)){let o=g4(r,t);if(o!==null)return{at:r,blocker:o}}return null}function b4(e,t){let r=e;for(let o=0;o<Vs;o++){let i=I1(r,t);if(i===null)return r;if(i.blocker.kind==="water")return[];let a=[];if(i.blocker.kind==="claim"){let l=i.blocker.obstacle.poly,d=0;for(let c=0;c<l.length;c++){let k=l[c],p=l[(c+1)%l.length];d+=k.x*p.y-p.x*k.y}let h=d>=0?1:-1;for(let c=0;c<l.length;c++){let k=l[c],p=l[(c+1)%l.length],f=Math.hypot(p.x-k.x,p.y-k.y);if(f<1e-9)continue;let m=-h*(p.y-k.y)/f,v=h*(p.x-k.x)/f;a.push({nx:m,ny:v,c:m*k.x+v*k.y-si})}}else{let{a:l,b:d,clearanceM:h}=i.blocker.seg,c=Math.hypot(d.x-l.x,d.y-l.y);if(c<1e-9)return[];let k=(d.x-l.x)/c,p=(d.y-l.y)/c,f=h+si;a.push({nx:p,ny:-k,c:p*l.x-k*l.y-f}),a.push({nx:-p,ny:k,c:-p*l.x+k*l.y-f}),a.push({nx:k,ny:p,c:k*l.x+p*l.y-f}),a.push({nx:-k,ny:-p,c:-(k*d.x+p*d.y)-f})}let s=[],n=0;for(let l of a){if(l.nx*i.at.x+l.ny*i.at.y<=l.c+1e-9)continue;let d=Lr(r,l.nx,l.ny,l.c),h=d.length>=3?$e(d):0;h>n&&(n=h,s=d)}if(s.length<3)return[];r=s}return I1(r,t)===null?r:[]}function O1(e,t){let r=0;for(let a=0;a<t.length;a++){let s=t[a],n=t[(a+1)%t.length];r+=s.x*n.y-n.x*s.y}let o=r>=0?1:-1,i=e;for(let a=0;a<Vs;a++){let s=null;for(let d of T1(i))if(bt(d,t)){s=d;break}if(s===null)return i;let n=[],l=0;for(let d=0;d<t.length;d++){let h=t[d],c=t[(d+1)%t.length],k=c.x-h.x,p=c.y-h.y,f=Math.hypot(k,p);if(f<1e-9)continue;let m=-o*p/f,v=o*k/f,L=m*h.x+v*h.y;if(m*s.x+v*s.y<=L+1e-9)continue;let w=Lr(i,m,v,L),M=w.length>=3?$e(w):0;M>l&&(l=M,n=w)}if(n.length<3)return[];i=n}return i}function x4(e,t){if(t.length===0)return null;let r=co(e),o=null;for(let i of t){if((r.x-i.p.x)*i.outX+(r.y-i.p.y)*i.outY<-i.halfWidthM)continue;let a=(i.dirDeg+90)*Math.PI/180,s=Math.sin(a),n=-Math.cos(a),l=Math.abs(s*(r.x-i.p.x)+n*(r.y-i.p.y));(o===null||l<o.distM)&&(o={road:i,distM:l})}return o}function Z4(e,t){let r=(t.dirDeg+90)*Math.PI/180,o=Math.sin(r),i=-Math.cos(r),a=o*t.p.x+i*t.p.y,s=1/0,n=-1/0;for(let d of e){let h=o*d.x+i*d.y;h<s&&(s=h),h>n&&(n=h)}if(s>=a+t.halfWidthM||n<=a-t.halfWidthM)return!1;let l=co(e);return(l.x-t.p.x)*t.outX+(l.y-t.p.y)*t.outY>-t.halfWidthM*2}function P4(e){return(e%180+180)%180}function A1(e,t){return(P4(e-t)+90)%180-90}function E2(e,t,r,o,i,a){let s=i.float(),n=i.float(),l=i.float(),d=$e(e);if(d<1e-6)return;let h=d<=Os*xl?O1(e,r):e;if(h.length<3)return;let c=$e(h);if(c<1e-6)return;if(t<Hs)for(let w of o){if(!Z4(h,w))continue;let M=t3(h,w.p,w.dirDeg,w.halfWidthM),x=o.filter(b=>b!==w);for(let b of M)E2(b,t+1,r,x,i,a);return}let k=Os*(1+(l*2-1)*gl);if(c<=k*bl||t>=Hs){a.push(h);return}let p=vs(h),f=Xn(h),m=x4(h,o);if(m!==null&&m.distM<=Cl){let w=m.road.dirDeg,M=m.road.dirDeg+90;f=Math.abs(A1(w,p))<=Math.abs(A1(M,p))?w:M}f+=(s*2-1)*Zl;let v=.5+(n-.5)*Pl,L=Jn(h,f,v,Sl);if(L.length<2){a.push(h);return}for(let w of L)E2(w,t+1,r,o,i,a)}function H1(e,t){let r=1/0;for(let o=0;o<t.length;o++){let i=t[o],a=t[(o+1)%t.length],s=a.x-i.x,n=a.y-i.y,l=s*s+n*n,d=l<1e-12?0:Math.max(0,Math.min(1,((e.x-i.x)*s+(e.y-i.y)*n)/l));r=Math.min(r,Math.hypot(e.x-(i.x+s*d),e.y-(i.y+n*d)))}return r}function z1(e,t,r,o,i,a,s,n=[]){let l=R2(t,o,i,s),d=w4(t,o,i,s),h=L4(t,d,a),c=Math.max(0,e.population)*kl,k=y4(t,h,c/ul,a),p=u4(o,i,r,e.water,n),f=M4(t,r,h),m=[];E2(k,0,h,f,a,m);let v=no(e.biome,e.biome==="desert"||e.freshwaterIrrigation===!0);if(!v.length)return{blocks:[],edges:[],outerRadius:l,regionPolygon:k};let L=[],w=l,M=0;for(let x of m){a.float();let b=a.float(),u=a.float(),P=O1(x,h);if(P.length<3)continue;let C=Yn(P,zs);if(C.length<3||$e(C)<js||u<_l&&C.some(nt=>H1(nt,k)<=zs+Rl))continue;let Q=b4(C,p);if(Q.length<3)continue;let R=$e(Q);if(R<js)continue;let V=vs(Q),j=Ji(Q,V),F=Ji(Q,V+90),K=j.hi-j.lo,H=F.hi-F.lo;if(!(K>0)||H<El*K)continue;let X=fe(V+b*$s-$s/2);L.push({id:`field:P${M}`,furlongId:`furlong:${Math.floor(pt(t.centre,co(Q))/30)}`,glyph:v[M%v.length],polygon:Q,furrowBearingDeg:X,areaM2:R}),M+=1;for(let nt of Q)w=Math.max(w,A(t.centre,nt))}return{blocks:L,edges:[],outerRadius:w,regionPolygon:k,...e.flags.walls?{innerBoundary:h}:{}}}function V1(e,t,r,o,i,a,s,n,l=0){let d=new Map,h=24;function c(p,f,m){if(!p.length)return;let v=Math.floor((Math.min(...p.map(x=>x.x))-f-l)/h),L=Math.floor((Math.max(...p.map(x=>x.x))+f+l)/h),w=Math.floor((Math.min(...p.map(x=>x.y))-f-l)/h),M=Math.floor((Math.max(...p.map(x=>x.y))+f+l)/h);for(let x=v;x<=L;x++)for(let b=w;b<=M;b++){let u=`${x},${b}`,P=d.get(u);P?P.push(m):d.set(u,[m])}}function k(p,f){c(p,f,(m,v=0)=>bt(m,p)||p.some((L,w)=>A(m,st(m,L,p[(w+1)%p.length]))<=Math.max(f,v)))}for(let p of t)for(let f=1;f<p.points.length;f++){let m=p.points[f-1],v=p.points[f],L=p.widthM/2+Math.max(3,Ol);c([m,v],L,(w,M=0)=>A(w,st(w,m,v))<=L+M)}for(let p of r){let f=wt(p),m=Math.hypot(f.halfW,f.halfD)+3;c([new Z(f.center.x-m,f.center.y-m),new Z(f.center.x+m,f.center.y+m)],0,(v,L=0)=>gi(v,f,Math.max(1.5,L)))}for(let p of o)k(p.polygon,1.5);for(let p of i)k(p.polygon,1.5);for(let p of n)k(p,3);return(p,f=0)=>{if(Tt(a,p),A(p,e.centre)<Ct(e)+Math.max(1.5,f)||d.get(`${Math.floor(p.x/h)},${Math.floor(p.y/h)}`)?.some(m=>m(p,f)))return!0;for(let m of a)if(bt(p,m))return!0;return!!(f>0&&be(a).some(([m,v])=>A(p,st(p,m,v))<f)||A(p,e.centre)<=s&&be(a).some(([m,v])=>A(p,st(p,m,v))<=Hl))}}function S4(e,t){return e<t?Al:0}function Oa(e,t){let r=_t[e]?.footprint?.[0]??1,o=fr[e]?.bounds??[8,8,56,56];return Math.max(32-o[0],32-o[1],o[2]-32,o[3]-32)*r/64*t}function j1(e,t,r){let o=Math.floor(e),i=Math.floor(t),a=(d,h)=>{let c=Math.imul(d,374761393)^Math.imul(h,668265263)^r;return c=Math.imul(c^c>>>13,1274126177),((c^c>>>16)>>>0)/4294967296},s=d=>d*d*(3-2*d),n=s(e-o),l=s(t-i);return(a(o,i)*(1-n)+a(o+1,i)*n)*(1-l)+(a(o,i+1)*(1-n)+a(o+1,i+1)*n)*l}function $1(e,t,r,o,i,a,s,n,l,d,h=[]){let c=n.plus(Ds),k=c.maxM;if(!(k>0))return[];let p=Math.max(...Rr(e.biome,!0).map(C=>Oa(C,ca))),f=V1(t,r,o,i,a,e.water,l,h,p),m=be(e.water),v=d.getSeed(),L=C=>vo(e.biome,C.x,C.y,v,d.float(),m.some(([Q,R])=>A(C,st(C,Q,R))<15)),w=[],M=Math.max(0,Math.ceil(s.maxM/xr));for(let C=-M;C<=M;C++)for(let Q=-M;Q<=M;Q++){let R=new Z(t.centre.x+C*xr,t.centre.y+Q*xr),V=new Z(R.x+xr/2,R.y+xr/2),j=S4(A(V,t.centre),s.at(V));if(!(d.float()<j))continue;let K=d.float(),H=d.float(),X=new Z(R.x+K*xr,R.y+H*xr),nt=L(X),mt=ni+d.float()*(ca-ni),O=`veg:${C}x${Q}`;if(f(X,Oa(nt,mt)))continue;w.push({id:O,glyph:nt,position:X,scale:mt});let[Y,rt]=Tl,yt=d.int(Y,rt);for(let B=1;B<=yt;B++){let U=d.float()*zl,$=d.float()*2*Math.PI,J=U*Math.sin($),lt=-U*Math.cos($),xt=new Z(X.x+J,X.y+lt);f(xt,Oa(nt,mt))||w.push({id:`${O}:${B}`,glyph:nt,position:xt,scale:mt})}}let x=e.biome==="desert"?6:e.biome==="tundra"?4.8:3.8,b=e.biome==="desert"?.64:e.biome==="coastal"?.56:e.biome==="tundra"?.46:e.biome==="tropical"?.3:.36,u=Math.floor(d.float()*4294967296),P=Math.ceil(k/x);for(let C=-P;C<=P;C++)for(let Q=-P;Q<=P;Q++){let R=new Z(t.centre.x+(C+.15+d.float()*.7)*x,t.centre.y+(Q+.15+d.float()*.7)*x),V=A(R,t.centre);if(V<s.at(R)||V>c.at(R))continue;let j=Math.max(0,(V-n.at(R))/Ds);if(.75*j1(R.x/48,R.y/48,u)+.25*j1(R.x/19,R.y/19,u^1540483477)<b+j*.48||f(R))continue;let K=L(R),H=ni+d.float()*(ca-ni);f(R,Oa(K,H))||w.push({id:`wood:${C}x${Q}:0`,position:R,glyph:K,scale:H})}return w}function C4(e,t,r){let[o,i]=re(e.glyph),a=e.sizeFactor,s=1+(r.float()-.5)*2*N3,n=pe(e.glyph,[o,i]).width,l=t.frontageM/(n*a),d=Math.min(Rs,Math.max(D3,l>1.6?Rs:Math.min(1,l))),h=a*s*d;return[o*h,i*h]}function _o(e,t,r=0,o=!1){let i=a3(e);return i==="invariant"?0:i==="snap-cardinal"?fe(Math.round((t+180)/90)*90):i!=="free"?fe(t+180):fe(t+180+(o?90:0)+r)}function N1(e,t,r,o=!0){let i=C4(e,t,r),a=r.float()*F3,s=Lt(t.bearingDeg),n=new Z(-s.x,-s.y),l=(i[1]-pe(e.glyph,i).depth)/2,d=a+i[1]/2-l,h=(r.float()*2-1)*G3,c=r.bool(W3)&&o;return{id:_a(t.id),lotId:t.id,glyph:e.glyph,position:new Z(t.front.x+n.x*d,t.front.y+n.y*d),bearingDeg:_o(e.glyph,t.bearingDeg,h,c),footprint:i,occupancy:Math.round(e.occupancy*e.sizeFactor)}}function Q2(e){let t=pe(e.glyph,e.footprint),r=Lt(e.bearingDeg);return{tangent:new Z(-r.y,r.x),normal:r,halfW:t.width/2,halfD:t.depth/2}}var I2=.05;function B4(e,t){let r=Q2(e),o=Q2(t),i=new Z(t.position.x-e.position.x,t.position.y-e.position.y);for(let a of[r.tangent,r.normal,o.tangent,o.normal]){let s=Math.abs(i.x*a.x+i.y*a.y),n=Math.abs(r.tangent.x*a.x+r.tangent.y*a.y)*r.halfW+Math.abs(r.normal.x*a.x+r.normal.y*a.y)*r.halfD,l=Math.abs(o.tangent.x*a.x+o.tangent.y*a.y)*o.halfW+Math.abs(o.normal.x*a.x+o.normal.y*a.y)*o.halfD;if(s>=n+l-I2)return!1}return!0}function E4(e,t){if(Tt(t,e.position,Math.hypot(...e.footprint)/2),t.length===0)return!1;let r=pe(e.glyph,e.footprint),o=r.width/2,i=r.depth/2,a=e.bearingDeg*Math.PI/180,s=Math.cos(a),n=Math.sin(a),l=(h,c)=>new Z(e.position.x+h*s-c*n,e.position.y+h*n+c*s),d=[l(-o,-i),l(o,-i),l(o,i),l(-o,i)];if(kt(e.position,t)||d.some(h=>kt(h,t)))return!0;for(let h=0;h<d.length;h++){let c=d[h],k=d[(h+1)%d.length];for(let p of t)for(let f=0;f<p.length;f++)if(Wt(c,k,p[f],p[(f+1)%p.length]))return!0}return!1}function Ie(e,t){let r=Q2(e);for(let o of t){let i=o.widthM/2;for(let a=1;a<o.points.length;a++){let s=st(e.position,o.points[a-1],o.points[a]),n=s.x-e.position.x,l=s.y-e.position.y,d=Math.abs(n*r.tangent.x+l*r.tangent.y),h=Math.abs(n*r.normal.x+l*r.normal.y);if(d<r.halfW+i-I2&&h<r.halfD+i-I2)return!0}}return!1}var _4=[0,.25,-.25,.45,-.45],R4=[0,.15,-.15,.25,-.25,.35,-.35,.45,-.45,.5,-.5];function D1(e,t,r,o,i=[],a,s=!1,n=[]){let l=Eo(e),d=new Set(n.map(m=>m.lotId)),h=new Set,c=[...n],k=n.reduce((m,v)=>m+v.occupancy,0),p=(m,v)=>{let L=Lt(v.bearingDeg),w=new Z(-L.y,L.x),M=0,x=0,b=0;for(let u of s?R4:_4){let P=u*v.frontageM,C=u===0?m:{...m,position:new Z(m.position.x+w.x*P,m.position.y+w.y*P)};if(Ie(C,i)){M++;continue}if(E4(C,r.water)){b++;continue}if(c.some(Q=>B4(C,Q))){x++;continue}return C}return b>=M&&b>=x?"in-water":M>=x?"lane-intrusion":"building-overlap"},f=m=>typeof m!="string";for(let m of t.filter(v=>v.cap==="one"))for(let v of l){if(d.has(v.id)||!r2(m,r,v.frontageM))continue;let L=p(N1(m,v,o),v);if(f(L)){c.push(L),d.add(v.id),h.add(m.glyph),a?.set(v.id,"seated"),k+=L.occupancy;break}}for(let m of l){if(k>=r.population)break;if(d.has(m.id))continue;let v=x5(t,r,m.frontageM,h,o);if(!v){a?.set(m.id,"no-deck-entry");continue}let L=p(N1(v,m,o),m);if(!f(L)){a?.set(m.id,L);continue}c.push(L),d.add(m.id),a?.set(m.id,"seated"),k+=L.occupancy}if(a)for(let m of l)a.has(m.id)||a.set(m.id,"census-satisfied");return{buildings:c,housed:k,unhoused:Math.max(0,r.population-k)}}function A2(e,t){let r=1/0;for(let o=1;o<t.points.length;o++)r=Math.min(r,A(e,st(e,t.points[o-1],t.points[o])));return r}function Q4(e,t){let r=1/0,o=null;for(let i=1;i<t.points.length;i++){let a=t.points[i-1],s=t.points[i],n=A(e,st(e,a,s));n<r&&(r=n,o=[a,s])}return o}function I4(e,t,r){let o=Fe(r,"sm-well");if(!ce(o))return null;let[i,a]=re(o),s=Math.max(i,a),n=w=>w.widthM/2+s/2+jl,l=t.map(w=>({lane:w,distance:A2(e.centre,w),clearance:n(w)})).filter(w=>w.distance<w.clearance).sort((w,M)=>w.distance-M.distance);if(l.length===0)return{id:"poi:well",kind:"well",glyph:o,position:e.centre,bearingDeg:0};let d=Q4(e.centre,l[0].lane);if(!d)return{id:"poi:well",kind:"well",glyph:o,position:e.centre,bearingDeg:0};let[h,c]=d,k=We(c.x-h.x,c.y-h.y),p=new Z(-k.y,k.x),f=Ct(e)*$l,m=w=>t.every(M=>A2(w,M)>=n(M)),v=w=>{for(let M=Fs;M<=f+1e-9;M+=Fs){let x=new Z(e.centre.x+p.x*w*M,e.centre.y+p.y*w*M);if(m(x))return x}return null},L=v(1)??v(-1)??e.centre;return{id:"poi:well",kind:"well",glyph:o,position:L,bearingDeg:0}}function A4(e,t){let r=new Z(e.x-t.center.x,e.y-t.center.y),o=Math.max(-t.halfW,Math.min(t.halfW,r.x*t.tangent.x+r.y*t.tangent.y)),i=Math.max(-t.halfD,Math.min(t.halfD,r.x*t.normal.x+r.y*t.normal.y));return new Z(t.center.x+t.tangent.x*o+t.normal.x*i,t.center.y+t.tangent.y*o+t.normal.y*i)}function Ro(e,t,r){if(X5(r,e,t),r.length<2)return!1;if(bt(e,r))return!0;for(let o=0;o<r.length;o++){let i=r[o],a=r[(o+1)%r.length];if(A(e,st(e,i,a))<t)return!0}return!1}function Zi(e,t,r,o,i,a){for(let s of r)if(A2(e,s)<t+s.widthM/2)return!1;for(let s of o)if(A(e,A4(e,wt(s)))<t)return!1;for(let s of i)if(Ro(e,t,s.polygon))return!1;for(let s of a)if(Ro(e,t,s.polygon))return!1;return!0}function T4(e,t,r,o,i,a,s,n,l,d="temperate"){if(!l.bool(Nl))return null;let h=Kt(d),c=["lintelled-ring","broken-ring","double-ring","horseshoe","oval-ring","ruined-ring"],k=l.float(),p=`sm-henge-${c[Math.floor(k*c.length)]}-${"abc"[Math.floor(k*18)%3]}${h==="temperate"?"":`--${h}`}`;if(!ce(p))return null;let f=t*Dl;for(let m=0;m<Fl;m++){let v=l.int(0,360),L=Lt(v),w=new Z(e.centre.x+L.x*f,e.centre.y+L.y*f);if(!(!Zi(w,go,r,o,i,a)||s.some(x=>Ro(w,go,x))||n.some(x=>A(w,x.position)<go+Gl)))return{id:"poi:stone-circle",kind:"stone-circle",glyph:p,position:w,bearingDeg:0}}return null}function O4(e,t){let r=null;Tt(t,e);for(let o of Pr(t)){if(o.length<2)continue;let i=o,a=gt(i);for(let s=0;s<o.length-1;s++){let n=i[s],l=i[s+1],d=st(e,n,l),h=A(e,d);(!r||h<r.distance)&&(r={ring:o,acc:a,s:a[s]+A(n,d),point:d,distance:h})}}return r}function H4(e,t,r){let o=Lt(t),i=new Z(-o.y,o.x),a=new Z(e.x+i.x*.5,e.y+i.y*.5);return kt(a,r)?new Z(-i.x,-i.y):i}function z4(e,t){let r=[0];for(let o=t;o<=e+1e-9;o+=t)r.push(o,-o);return r}function V4(e,t,r,o,i,a,s){if(!e.flags.port||e.water.length===0)return null;let n=O4(t.centre,e.water);if(!n||n.distance>r)return null;let l="sm-boathouse--coastal";if(!ce(l))return null;let[d,h]=re(l),c=Math.max(d,h)/2,k=h/2-h*ql,p=n.acc[n.acc.length-1],f=n.ring;for(let m of z4(Wl,Ul)){let v=n.s+m;if(v<0||v>p)continue;let L=ut(f,n.acc,v),w=H4(L.p,L.dirDeg,e.water),M=new Z(L.p.x+w.x*k,L.p.y+w.y*k);if(!Zi(M,c,o,i,a,s))continue;let x=pt(M,L.p),b=new Z(-w.x,-w.y),u=M.x+b.x*(h/2),P=M.y+b.y*(h/2),C=h*Kl,Q=C/Gs,R=0;for(let j=pa;j<=Q;j+=pa){let F=new Z(u+b.x*j,P+b.y*j);if(!kt(F,e.water))break;R=j}let V=R>=Q?C:R*Gs;return V<pa?{id:"poi:boathouse",kind:"boathouse",glyph:l,position:M,bearingDeg:_o(l,x)}:{id:"poi:boathouse",kind:"boathouse",glyph:l,position:M,bearingDeg:_o(l,x),jetty:{from:new Z(u,P),to:new Z(u+b.x*V,P+b.y*V),widthM:d*Yl}}}return null}function F1(e,t,r,o,i,a,s,n,l,d,h){let c=[];if(e.population>=Vl){let f=I4(t,r,e.biome);f&&c.push(f)}let k=h??T4(t,n,r,o,i,a,e.water,s,d,e.biome);k&&c.push(k);let p=V4(e,t,l,r,o,i,a);return p&&c.push(p),c}function G1(e,t,r,o,i,a){if(!e.flags.temple||!ce("sm-stone-circle"))return null;let s=go,n,l=Math.max(a+50,Ct(t)+60),d=r.length?r:[{id:"green",type:"footpath",widthM:1,points:[t.centre,new Z(t.centre.x+Ct(t),t.centre.y)]}];for(let h of[...d].sort((c,k)=>c.id.localeCompare(k.id))){let c=gt(h.points);for(let k=0;k<=c.at(-1);k+=6){let p=ut(h.points,c,k).p;if(A(p,t.centre)>l)continue;let f=ut(h.points,c,Math.max(0,k-.5)).p,m=ut(h.points,c,Math.min(c.at(-1),k+.5)).p,v=A(f,m);if(!(v<1e-6))for(let L of[-1,1])for(let w of[0,8,16]){let M=s+h.widthM/2+3+w,x=-(m.y-f.y)/v*L,b=(m.x-f.x)/v*L,u=new Z(p.x+x*M,p.y+b*M);if(A(u,t.centre)<Ct(t)+s+2)continue;let P=A(u,t.centre)+w*.5;if(n&&P>=n.score||!Zi(u,s+2,r,o,i,[])||e.water.some(V=>Ro(u,s+2,V)))continue;let C=new Z(u.x-x*(s+1),u.y-b*(s+1)),Q=!0,R=Math.max(1,Math.ceil(A(p,C)));for(let V=0;V<=R&&Q;V++){let j=new Z(p.x+(C.x-p.x)*V/R,p.y+(C.y-p.y)*V/R);Q=Zi(j,.7,[],o,i,[])&&!e.water.some(F=>Ro(j,.7,F))}Q&&(n={score:P,poi:{id:"poi:stone-circle",kind:"stone-circle",glyph:"sm-stone-circle",position:u,bearingDeg:0},clearing:Array.from({length:24},(V,j)=>new Z(u.x+Math.cos(j*Math.PI/12)*(s+2)/Math.cos(Math.PI/24),u.y+Math.sin(j*Math.PI/12)*(s+2)/Math.cos(Math.PI/24))),access:{id:"poi:stone-circle/access",type:"footpath",routeRole:"street",widthM:1.4,surfaceWidthM:1,setbackM:.3,points:[p,C],...h.id!=="green"?{parentId:h.id}:{}}})}}}if(n){let h=Math.abs(Math.round(n.poi.position.x*127+n.poi.position.y*311)),c=["lintelled-ring","broken-ring","double-ring","horseshoe","oval-ring","ruined-ring"][h%6],k=Kt(e.biome);n.poi.glyph=`sm-henge-${c}-${"abc"[Math.floor(h/6)%3]}${k==="temperate"?"":`--${k}`}`}return n??null}function W1(e){let{site:t,green:r,lanes:o,lots:i,buildings:a,builtRadiusM:s,f0:n,rng:l}=e,d=R1(t.biome,t.population,l),h=new Set(a.map(F=>F.lotId)),c=_1(i,a,r,o,t.water,s,n),k=R2(r,i,c,h),p=G1(t,r,o,i.filter(F=>h.has(F.id)),c,k),f=p?[p.access]:[],m=[...o,...f],v=p?[p.clearing]:[],{blocks:L,edges:w,outerRadius:M,regionPolygon:x,innerBoundary:b}=z1(t,r,m,i,c,l,h,v),u=xi(r.centre,Ta(i,c,h),Ct(r)),P=[];for(let F=0;F<x.length;F++){let K=x[F],H=x[(F+1)%x.length],X=Math.max(1,Math.ceil(Math.hypot(H.x-K.x,H.y-K.y)/5));for(let nt=0;nt<X;nt++)P.push(new Z(K.x+(H.x-K.x)*nt/X,K.y+(H.y-K.y)*nt/X))}let C=xi(r.centre,[...Ta(i,c,h),...L.flatMap(F=>F.polygon),...P],Ct(r)),Q=k*al,R=$1(t,r,m,i.filter(F=>h.has(F.id)),c,L,u,C,Q,l,v),V=Math.max(M,k),j=F1(t,r,m,i,c,L,R,V,Q,l,p?.poi);return{edgeStyle:d,crofts:c,fields:L,fieldEdges:w,vegetation:R,pois:j,accessLanes:f,diagnostics:t.flags.temple&&!p?["temple: no dry, accessible clearing could accommodate the requested henge"]:[],...b?{wall:u1(g1(a,j,b),m,t.water,t.biome,v)}:{}}}function U1(e){let t=[e.greenCentre.x],r=[e.greenCentre.y],o=i=>{t.push(i.x),r.push(i.y)};for(let i of e.buildings)o(i);for(let i of e.dressing)o(i);for(let i of e.lanes)if(!Ot(i.id))for(let a of i.points)o(a);return{minX:Math.min(...t)-di,minY:Math.min(...r)-di,maxX:Math.max(...t)+di,maxY:Math.max(...r)+di}}function q1(e,t){let r=[];for(let o of e){if(!Ot(o.id)){r.push(o);continue}let i=t1(o.points,t);i.length>=2&&r.push({...o,points:i})}return r}function K1(e){e.cut.clear(),e.fates.clear(),e.staleAfterTrim.clear(),e.convergeDetail.clear()}function j4(e,t){if(e.length===0)return t>0?[[0,t]]:[];let r=[...e].sort((s,n)=>s[0]-n[0]),o=[];for(let[s,n]of r){let l=o[o.length-1];l&&s<=l[1]?l[1]=Math.max(l[1],n):o.push([s,n])}let i=[],a=0;for(let[s,n]of o)s>a&&i.push([a,Math.min(s,t)]),a=Math.max(a,n);return a<t&&i.push([a,t]),i.filter(([s,n])=>n>s)}function $4(e,t,r){let o=1/0,i=0;for(let a=1;a<e.length;a++){let s=st(r,e[a-1],e[a]),n=A(r,s);n<o&&(o=n,i=t[a-1]+A(e[a-1],s))}return i}function N4(e){return e.flatMap(t=>t.points.slice(1).flatMap((r,o)=>{let i=t.points[o],a=A(i,r);if(a<=0)return[];let s=new Z((r.x-i.x)/a,(r.y-i.y)/a);return[{laneId:t.id,box:{center:new Z((i.x+r.x)/2,(i.y+r.y)/2),tangent:s,normal:new Z(-s.y,s.x),halfW:a/2,halfD:t.widthM/2}}]}))}function D4(e,t){let r=e.depthM,o=wt(e);for(let{laneId:i,box:a}of t)if(i!==e.laneId){if(r<Re)return r;oe(o,a)&&(r=we({...e,depthM:r},a),o=wt({...e,depthM:r}))}return r}function Y1(e){let{lanes:t,green:r,standing:o,builtRadiusM:i,f0:a,depthM:s,floorM:n,maxFrontageM:l,reachOf:d,pass:h}=e,c=N4(t),k=[],p=new Map,f=o.map(w=>({lot:w,depth:w.depthM})),m=new Set,v=w=>wt({...w.lot,depthM:w.depth}),L=w=>Math.hypot(w.lot.frontageM/2,w.depth);for(let w of t){let M=Be(w),x=d(w);for(let b of[1,-1]){let u=Ze(w.points,M,b);if(u.length<2)continue;let P=gt(u),C=P[P.length-1];if(C<=n)continue;let Q=[];for(let V of o){if(V.laneId!==w.id||V.side!==b)continue;let j=$4(u,P,V.front);Q.push([j-V.frontageM/2-Mo,j+V.frontageM/2+Mo])}let R=0;for(let[V,j]of j4(Q,C)){if(j-V<n)continue;let F=V;for(;F+n<=j;){let K=ut(u,P,F),H=A(K.p,r.centre),X=Math.max(n,l),nt=Math.min(X,Math.max(n,a*ha,bi(H,i,a)),j-F),mt=n/2;if(nt<n)break;let O=ut(u,P,F+nt/2);if(A(O.p,r.centre)>x(O.p)){F+=mt;continue}let Y=(O.dirDeg+(b===1?-90:90)+360)%360,rt={id:r1(w.id,b,R,h),laneId:w.id,side:b,front:O.p,bearingDeg:Y,frontageM:nt,depthM:s,score:0},yt=f.filter(lt=>A(rt.front,lt.lot.front)<=Math.hypot(nt/2,s)+L(lt)),B=D4(rt,c);for(let lt of yt){if(B<Re)break;let xt=v({...lt,depth:Math.min(lt.depth,Re)});oe(wt({...rt,depthM:B}),xt)&&(B=we({...rt,depthM:B},xt))}if(B<Re){F+=mt;continue}let U={...rt,depthM:B},$=wt(U);for(let lt of yt){if(!oe(v(lt),$))continue;let xt=Math.max(Math.min(lt.depth,Re),we({...lt.lot,depthM:lt.depth},$));lt.depth=xt,m.has(lt.lot.id)||p.set(lt.lot.id,xt)}let J={lot:U,depth:U.depthM};k.push(J),m.add(U.id),f.push(J),R++,F+=nt+Mo}}}}return{added:k.map(w=>({...w.lot,depthM:w.depth})),trimmed:p}}function Pi(e){let{lot:t,glyph:r,occupancy:o}=e,i=re(r),a=Lt(t.bearingDeg+180),s=pe(r,i).depth/2+.5;return{id:_a(t.id),lotId:t.id,glyph:r,footprint:i,occupancy:o,position:new Z(t.front.x+a.x*s,t.front.y+a.y*s),bearingDeg:_o(r,t.bearingDeg,0,!1)}}function F4(e){return e.biome==="temperate"&&e.population>=700?{kind:"faith",glyph:"sm-temple",minPop:700,occupancy:0}:{kind:"faith",glyph:Fe(e.biome,"sm-chapel"),minPop:300,occupancy:0}}function X1(e){return[F4(e),{kind:"inn",glyph:Fe(e.biome,"sm-inn"),minPop:180,occupancy:6},{kind:"manor",glyph:Fe(e.biome,"sm-house-large-tiled"),minPop:250,occupancy:6}]}function G4(e){return Be(e)}function W4(e,t){let r=new Z(e.x-t.center.x,e.y-t.center.y),o=Math.max(-t.halfW,Math.min(t.halfW,r.x*t.tangent.x+r.y*t.tangent.y)),i=Math.max(-t.halfD,Math.min(t.halfD,r.x*t.normal.x+r.y*t.normal.y));return new Z(t.center.x+t.tangent.x*o+t.normal.x*i,t.center.y+t.tangent.y*o+t.normal.y*i)}function U4(e,t){let r=W4(t.centre,e);return A(r,t.centre)<Ct(t)}function J1(e){let{center:t,tangent:r,normal:o,halfW:i,halfD:a}=e,s=(n,l)=>new Z(t.x+r.x*i*n+o.x*a*l,t.y+r.y*i*n+o.y*a*l);return[t,s(1,1),s(1,-1),s(-1,1),s(-1,-1)]}function q4(e,t){if(Tt(t,e.center,Math.hypot(e.halfW,e.halfD)),t.length===0)return!1;let[r,o,i,a,s]=J1(e);if([r,o,i,s,a].some(l=>kt(l,t)))return!0;let n=[o,i,s,a];for(let l=0;l<n.length;l++){let d=n[l],h=n[(l+1)%n.length];for(let c of t)for(let k=0;k<c.length;k++)if(Wt(d,h,c[k],c[(k+1)%c.length]))return!0}return!1}function K4(e,t,r){for(let o of t){if(o.id===r)continue;let i=o.widthM/2+w5;for(let a of J1(e))for(let s=1;s<o.points.length;s++)if(A(a,st(a,o.points[s-1],o.points[s]))<i)return!0}return!1}function Y4(e,t,r,o){return`landmark:${e}:${t}:${r===1?"R":"L"}${o}`}function X4(e,t,r,o,i,a){let[s,n]=re(e.glyph),[l,d]=Js[e.kind],h=l*i,c=d*i,k;for(let p of t){let f=G4(p);for(let m of[1,-1]){let v=Ze(p.points,f,m);if(v.length<2)continue;let L=gt(v),w=L[L.length-1],M=0;for(let x=t2;x<=w;x+=t2,M++){let{p:b,dirDeg:u}=ut(v,L,x),P=A(b,r.centre);if(P<h||P>c)continue;let C=(u+(m===1?-90:90)+360)%360,Q={id:Y4(e.kind,p.id,m,M),laneId:p.id,side:m,front:b,bearingDeg:C,frontageM:s,depthM:n,score:0},R=wt(Q);if(U4(R,r)||q4(R,o.water)||a.some(F=>oe(R,F))||K4(R,t,p.id))continue;let V=Ce(p.id),j=e.kind==="faith"?A(R.center,r.centre):e.kind==="inn"?(V?0:i*4)+ft(p.type)*2+Math.min(P*.6,Math.abs(P-i*.75)):Math.abs(P-i*1.05);k&&j>=k.score||Ie(Pi({lot:Q,glyph:e.glyph,kind:e.kind,occupancy:e.occupancy}),t)||(k={lot:Q,score:j})}}}return k?.lot??null}function td(e){return e.startsWith("landmark:")}function ed(e){return X1(e).filter(t=>e.population>=t.minPop&&ce(t.glyph)).length}function Ha(e,t,r,o,i){let a=[],s=[],n=[],l=[...r].sort((d,h)=>d.id<h.id?-1:d.id>h.id?1:0);for(let d of X1(e)){if(e.population<d.minPop)continue;if(!ce(d.glyph)){a.push(`landmark ${d.kind}: glyph "${d.glyph}" not in manifest, skipped`);continue}let h=X4(d,l,t,e,o,n);if(!h){a.push(`landmark ${d.kind}: no site cleared band [${Js[d.kind].join(", ")}] x builtRadiusM, green, water and prior claims across ${r.length} lane(s), skipped`);continue}n.push(wt(h)),s.push({lot:h,glyph:d.glyph,occupancy:d.occupancy,kind:d.kind})}return{landmarks:s,diagnostics:a}}var J4=.15,tc=8,ec=1.35,rd=24;function ad(e,t,r=[],o=[]){let i=new Map([["green",t.centre]]),a=[],s=new Map([["green",[]]]),n=new Map,l=Ct(t),d=p=>{let f=A(p,t.centre)<=l+1e-6?"green":`${Math.round(p.x*1e4)},${Math.round(p.y*1e4)}`;return i.has(f)||(i.set(f,p),s.set(f,[])),f},h=(p,f,m,v)=>{p!==f&&(a.push({from:p,to:f,length:m,laneId:v}),s.get(p).push({node:f,length:m,laneId:v}),s.get(f).push({node:p,length:m,laneId:v}))},c=e.flatMap(p=>p.points.length?[p.points[0],p.points[p.points.length-1]].map(f=>({p:f,laneId:p.id})):[]),k=new Map(o.map(p=>[p.id,p]));for(let p of r)k.get(p.lotId)?.laneId==="green"&&n.set(p.id,"green");for(let p of e){if(p.points.length<2)continue;let f=gt(p.points),m=p.points.map((w,M)=>({s:f[M],p:w})),v=w=>{let M={s:0,p:p.points[0],d:1/0};for(let x=1;x<p.points.length;x++){let b=st(w,p.points[x-1],p.points[x]),u=A(w,b);u<M.d&&(M={p:b,s:f[x-1]+A(p.points[x-1],b),d:u})}return M};for(let w of c){if(w.laneId===p.id)continue;let M=v(w.p);M.d<=J4&&(m.push(M),h(d(M.p),d(w.p),M.d,p.id))}let L=v(t.centre);L.d<=l+Qt(p).surfaceM/2+1e-6&&(m.push(L),h("green",d(L.p),Math.max(0,L.d-l),p.id));for(let w of r){if(k.get(w.lotId)?.laneId!==p.id)continue;let M=v(w.position);m.push(M),n.set(w.id,d(M.p))}m.sort((w,M)=>w.s-M.s);for(let w=1;w<m.length;w++)h(d(m[w-1].p),d(m[w].p),m[w].s-m[w-1].s,p.id)}return{points:i,edges:a,adjacency:s,buildings:n}}function od(e,t=new Set){let r=new Map,o=0;for(let i of e.points.keys()){if(r.has(i))continue;let a=[i];for(r.set(i,o);a.length;)for(let s of e.adjacency.get(a.pop())??[])t.has(s.laneId)||r.has(s.node)||(r.set(s.node,o),a.push(s.node));o++}return r}function id(e,t,r=new Set){let o=new Map([[t,0]]),i=[[t,0]],a=s=>{let n=i.length;for(i.push(s);n>0;){let l=n-1>>1;if(i[l][1]<=s[1])break;i[n]=i[l],n=l}i[n]=s};for(;i.length;){let[s,n]=i[0],l=i.pop();if(i.length){let d=0;for(;d*2+1<i.length;){let h=d*2+1;if(h+1<i.length&&i[h+1][1]<i[h][1]&&h++,i[h][1]>=l[1])break;i[d]=i[h],d=h}i[d]=l}if(n===o.get(s))for(let d of e.adjacency.get(s)??[]){if(r.has(d.laneId))continue;let h=n+d.length;h<(o.get(d.node)??1/0)&&(o.set(d.node,h),a([d.node,h]))}}return o}function T2(e,t,r,o){let i=ad(e,t,r,o),a=od(i),s=new Set(r.map(c=>o.find(k=>k.id===c.lotId)?.laneId)),n=new Set(["green",...i.buildings.values()]);for(let c of i.edges)Ce(c.laneId)&&(n.add(c.from),n.add(c.to));let l=new Set,d=e.filter(c=>!Ce(c.id)&&!s.has(c.id)).sort((c,k)=>Gt(k.points)-Gt(c.points)||c.id.localeCompare(k.id));for(let c of d){l.add(c.id);let k=od(i,l),p=new Map,f=!0;for(let m of n){let v=a.get(m),L=k.get(m);if(v===void 0||L===void 0){f=!1;break}if(p.has(v)&&p.get(v)!==L){f=!1;break}p.set(v,L)}f||l.delete(c.id)}return e.filter(c=>!l.has(c.id)).map(c=>c.parentId&&l.has(c.parentId)?{...c,parentId:void 0}:c)}function sd(e,t,r,o,i){let a=ad([...e,t],r,o,i),s=t.points[0],n=t.points[t.points.length-1],l=L=>[...a.points].reduce((w,[M,x])=>A(L,x)<w.d?{id:M,d:A(L,x)}:w,{id:"green",d:1/0}).id,d=l(s),h=l(n),c=new Set([t.id]),k=id(a,d,c),p=id(a,h,c),f=k.get(h)??1/0,m=Gt(t.points);if(!Number.isFinite(f)||f-m<tc||f<m*ec)return!1;let v=[...a.buildings.values()];return v.some(L=>(k.get(L)??1/0)<=rd)&&v.some(L=>(p.get(L)??1/0)<=rd)}function rc(e){return e.float()*2-1}function oc(e,t,r){if(!(r>0))return 0;let o=Math.min(1,Math.max(0,t/r));return e*h3*o*o}function to(e,t,r,o){let i=Lt(t),a=new Z(-i.y,i.x),s=rc(o),n=[];for(let l=0;l<=r;l+=Wr){let d=oc(s,l,r);n.push(new Z(e.x+i.x*l+a.x*d,e.y+i.y*l+a.y*d))}return n}function O2(e,t,r,o,i){let a=Lt(t),s=0;for(let n=0;n<=ri;n+=Wr){let l=new Z(e.x+a.x*n,e.y+a.y*n);if(!Si(r,o,i,l))break;s=n}return Math.min(ri,Math.max(De,s))}function Si(e,t,r,o){let i=A(o,e.centre);return i<1e-9?!0:i<=t.ringAt(r,pt(e.centre,o))}function ld(e,t){let r=t.points[0],o=A(r,e.centre);for(let i of t.points){let a=A(i,e.centre);a<o&&(o=a,r=i)}return r}var ic=1.5;function ac(e,t){return pt(e.centre,ld(e,t))}function Va(e){let t=Xo(e,"footpath");return ft(t)<ft("local")?"local":t}function sc(e,t){return t.parentId!==void 0?!1:A(ld(e,t),e.centre)<=Ct(e)*ic}function dd(e){let t=Math.PI*Math.max(0,e);return Math.min(M3,Math.max(y3,Math.round(t/L3)))}function nc(e){return 360/dd(e)}function hd(e,t){let r=Math.max(0,t-Ct(e));return Math.min(c3,Math.max(p3,r/3))}function lc(e,t){if(e.length===0)return t.int(0,360);let r=[...e].sort((s,n)=>s-n),o=r[r.length-1],i=r[0]+360-o;for(let s=1;s<r.length;s++){let n=r[s]-r[s-1];n>i&&(i=n,o=r[s-1])}let a=(t.float()-.5)*i*.5;return(o+i/2+a+360)%360}function kd(e){return Math.min(ri,Math.max(De,m3/2*e))}function dc(e,t,r){return r<q3?t:ft(e.type)<=ft("town")?t*w3:t}function z2(e,t,r,o){return i=>dc(e,r.at(pt(t.centre,i)),o)}function cd(e,t){return Math.sqrt(hc(e,t)*E3/Math.PI)*C3}function hc(e,t){return Math.max(1,e)*t/(2*B3)}function pd(e,t,r,o){let i=[];for(let a of e){let s=gt(a.points),n=s[s.length-1];if(n<o*1.25)continue;let l=o;for(;l<=n-o*.5;){let{p:d,dirDeg:h}=ut(a.points,s,l),c=A(d,t.centre);c<=r.at(pt(t.centre,d))&&!e.some(k=>A(k.points[0],d)<o*.45)&&i.push({parent:a,at:l/n,anchor:d,dirDeg:h,distToGreen:c}),l+=o}}return i.sort((a,s)=>a.distToGreen-s.distToGreen||a.parent.id.localeCompare(s.parent.id)||a.at-s.at),i}function V2(e,t,r,o=oi,i){let a=null,s=o;for(let n of e)if(!r.has(n.id))for(let l=1;l<n.points.length;l++){let d=st(t,n.points[l-1],n.points[l]),h=A(t,d);h<s&&(!i||u2(i,t,d))&&(s=h,a=d)}return a}function Bi(e,t){return t.length>0?[...e,...t]:e}function Sr(e,t,r,o){let i=e[0];for(let a=1;a<e.length;a++){let s=null;for(let n of t)for(let l=1;l<n.points.length;l++){let d=Wt(e[a-1],e[a],n.points[l-1],n.points[l]);if(!d||n.id===o&&A(i,d)<=S3)continue;let h=A(e[a-1],d);(!s||h<s.t)&&(s={q:d,t:h})}if(s)return[...e.slice(0,a),s.q]}return e}function za(e,t){for(let r=1;r<e.length;r++)for(let o=1;o<t.length;o++)if(Wt(e[r-1],e[r],t[o-1],t[o]))return!0;return!1}function j2(e,t){if(!t)return!1;let r=0;for(let o=1;o<e.length;o++)for(let i=1;i<t.points.length;i++)if(Wt(e[o-1],e[o],t.points[i-1],t.points[i])&&(r+=1,r>1))return!0;return!1}var kc=1;function fd(e,t){let r=e.points[e.points.length-1];for(let o of t)if(o.id!==e.id)for(let i=1;i<o.points.length;i++){let a=st(r,o.points[i-1],o.points[i]);if(A(r,a)<=kc)return!0}return!1}function $2(e,t){let r=Qe(e,t);return Math.min(r,180-r)}function Ci(e,t,r,o,i=!1){let a=t.filter(d=>d.id!==o);if(a.length===0)return!0;let s=gt(e),n=s[s.length-1],l=[];for(let d=0;d<=n;d+=Wr){let{p:h,dirDeg:c}=ut(e,s,d),k=1/0;for(let p of a)for(let f=1;f<p.points.length;f++)i&&$2(c,pt(p.points[f-1],p.points[f]))>x3||(k=Math.min(k,A(h,st(h,p.points[f-1],p.points[f]))));l.push(k)}return l.length===0?!0:(l.sort((d,h)=>d-h),l[Math.floor(l.length/2)]>=xs*r)}function nd(e,t,r,o,i,a,s,n=[]){let l=Bi(e,n),d=e.filter(h=>!Ce(h.id)&&h.points.length>=2&&Gt(h.points)<a&&Si(t,o,o.radiusM,h.points[h.points.length-1])&&Si(t,o,s,h.points[h.points.length-1])&&!fd(h,e)).sort((h,c)=>Gt(h.points)-Gt(c.points)||h.id.localeCompare(c.id));for(let h of d){let c=h.points.length,k=pt(h.points[c-2],h.points[c-1]),p=Sr(to(h.points[c-1],k,O2(h.points[c-1],k,t,o,s),i),l.filter(v=>v.id!==h.id),t);if(p.length<2)continue;let f=[...p];if(f[0]=new Z(p[0].x+(p[1].x-p[0].x)*.05,p[0].y+(p[1].y-p[0].y)*.05),!l.some(v=>{if(v.id===h.id)return!1;for(let L=1;L<f.length;L++)for(let w=1;w<v.points.length;w++)if(Wt(f[L-1],f[L],v.points[w-1],v.points[w]))return!0;return!1}))return h.points=[...h.points,...p.slice(1)],!0}return!1}function cc(e,t,r,o,i,a,s,n=[]){let l=Bi(e,n);if(e.filter(c=>sc(t,c)&&c.id.startsWith("lane-")).length<dd(o.radiusM)){let c=e.filter(k=>k.parentId===void 0).map(k=>ac(t,k));for(let k=0;k<36;k++){let p=Math.round(lc(c,i))%360;if(c.some(M=>Qe(p,M)<k3)||e.some(M=>M.id===y2(p)||M.id===Li(p)))continue;let m=Lt(p),v=new Z(t.centre.x+m.x*(t.diameter/2)*Ur,t.centre.y+m.y*(t.diameter/2)*Ur),L=.7+i.float()*.6,w=Sr(to(v,p,O2(v,p,t,o,a)*L,i),l,t);if(!(w.length<2||!Ci(w,e,s)))return e.push({id:Li(p),type:"local",points:w,widthM:ve("local")}),!0}}let d=pd(e,t,o,hd(t,o.radiusM)).filter(c=>Si(t,o,a,c.anchor));return(c=>{for(let k of c){if(N2(e,t,o,k.anchor,k.parent,s,n))return!0;let p=null,f=Math.max(1,Math.min(99,Math.round(k.at*100)));for(let P=0;P<99;P++){let C=1+(f-1+P)%99,Q=yi(k.parent.id,C/100);if(!e.some(R=>R.id===Q)){p=Q;break}}if(!p)continue;let m=i.bool(.5)?1:-1,v=(k.dirDeg+m*(70+i.int(0,31))+360)%360,L=Va(k.parent.type),w=to(k.anchor,v,O2(k.anchor,v,t,o,a),i),M=V2(e,w[w.length-1],new Set([k.parent.id]),oi,w[w.length-2]);M&&(w=[...w,M]);let x=w.length;w=Sr(w,l,t,k.parent.id),(M||w.length<x)&&(L=Xo(L,"footpath"));let b=M!==null||w.length<x,u=b?aa:De;if(!(w.length<2||Gt(w)<u)&&!(b?za(w,k.parent.points):j2(w,k.parent))&&Ci(w,e,s,k.parent.id,b))return e.push({id:p,type:L,points:w,widthM:ve(L),parentId:k.parent.id}),!0}return!1})(d)||nd(e,t,r,o,i,a*2,a,n)?!0:nd(e,t,r,o,i,1/0,a,n)}function pc(e,t,r){let o=[];for(let i of t){if(r.has(i.id))continue;let a=null;for(let s=1;s<i.points.length;s++){let n=st(e,i.points[s-1],i.points[s]),l=A(e,n);(!a||l<a.distance)&&(a={point:n,distance:l})}a&&o.push(a)}return o.sort((i,a)=>i.distance-a.distance)}function fc(e,t){for(let r of t)for(let o=1;o<e.length;o++)for(let i=1;i<r.points.length;i++)if(Wt(e[o-1],e[o],r.points[i-1],r.points[i]))return!0;return!1}function md(e,t,r=[],o,i=[]){let a=[...e],s=e.filter(n=>!Ce(n.id)&&n.points.length>=2).slice().sort((n,l)=>n.id.localeCompare(l.id));for(let n of s){if(fd(n,a))continue;let l=n.points[n.points.length-1];for(let d of pc(l,a,new Set([n.id]))){if(d.distance>P3)break;if(d.distance<aa)continue;let h=n.points[n.points.length-2],c=u2(h,l,d.point);if(!c&&Qe(pt(h,l),pt(l,d.point))>100)continue;let k=Lt(pt(h,l)),p=Math.min(6,d.distance/3),f=new Z(l.x+k.x*p,l.y+k.y*p),m=c?Xr([l,f,d.point]):[l,d.point];if(!m||!Jr(m,i)||fc(m,a)||A(d.point,t.centre)<=t.diameter/2)continue;let v={id:`${n.id}/c`,type:"footpath",points:m,widthM:ve("footpath"),parentId:n.id};if(!r.some(L=>Ie(L,[v]))&&!(o&&!sd(a,v,t,r,o))){a.push(v);break}}}return a}function mc(e,t,r,o){let i=Math.round(360/ii),a=new Array(i).fill(!1),s=n=>{let l=A(n,t.centre);l<1||l>r.ringAt(o,pt(t.centre,n))||(a[Math.floor(pt(t.centre,n)/ii)%i]=!0)};for(let n of e)for(let l=0;l<n.points.length;l++){if(s(n.points[l]),l===0)continue;let d=n.points[l-1],h=n.points[l],c=Math.max(1,Math.ceil(A(d,h)/4));for(let k=1;k<c;k++)s(new Z(d.x+(h.x-d.x)*k/c,d.y+(h.y-d.y)*k/c))}return a}function vc(e){let t=e.length;if(e.every(i=>!i))return{bisectorDeg:0,widthDeg:360};let r={start:0,len:0},o=0;for(;o<t*2;){if(e[o%t]){o+=1;continue}let i=o,a=0;for(;a<t&&!e[(i+a)%t];)a+=1;a>r.len&&(r={start:i%t,len:a}),o=i+a}return{bisectorDeg:(r.start+r.len/2)*ii%360,widthDeg:r.len*ii}}function wc(e,t,r,o){let i=null,a=o*li;for(let s=-a;s<=a;s+=Zs)for(let n=-a;n<=a;n+=Zs){let l=new Z(t.centre.x+s,t.centre.y+n);if(!Si(t,r,o,l))continue;let d=null;for(let c of e)for(let k=1;k<c.points.length;k++){let p=st(l,c.points[k-1],c.points[k]),f=A(l,p);(!d||f<d.distance)&&(d={point:p,parent:c,distance:f})}if(!d)continue;(!i||d.distance>i.distance||d.distance===i.distance&&(l.x<i.point.x||l.x===i.point.x&&l.y<i.point.y))&&(i={point:l,junction:d.point,parent:d.parent,distance:d.distance})}return i}function H2(e,t){let r=null;for(let o=1;o<t.points.length;o++){let i=st(e,t.points[o-1],t.points[o]),a=A(e,i);(!r||a<r.distance)&&(r={point:i,distance:a,dirDeg:pt(t.points[o-1],t.points[o])})}return r}function Lc(e,t,r){let o=0,i=0;for(let a of e){let s=H2(t,a);!s||s.distance>b3||A(s.point,r.centre)<Ct(r)||(i+=1,$2(s.dirDeg,pt(r.centre,s.point))<=u3&&(o+=1))}return i>=2&&o*2>=i}function yc(e,t,r,o,i){let a=A(o,t.centre);if(a<Ct(t)+Wr)return null;let s=Wr/a*(180/Math.PI),n=pt(t.centre,o),l=a/Math.max(1e-6,r.at(n)),d=f=>{let m=Lt(f),v=r.at(f)*l;return new Z(t.centre.x+m.x*v,t.centre.y+m.y*v)},h=f=>{let m=[],v=o;for(let L=1;L*s<=g3/2;L++){let w=d(n+f*L*s),M=null,x=1/0;for(let b of e)for(let u=1;u<b.points.length;u++){let P=Wt(v,w,b.points[u-1],b.points[u]);if(!P)continue;let C=A(v,P);C<x&&(x=C,M=P)}if(M)return m.push(M),{pts:m,joined:!0};if(m.push(w),v=w,L*s*Math.PI/180*a>=aa){let b=V2(e,w,i,oi,m.length>1?m[m.length-2]:o);if(b)return m.push(b),{pts:m,joined:!0}}}return{pts:m,joined:!1}},c=h(-1),k=h(1),p=[...c.pts.slice().reverse(),o,...k.pts];return p.length<2?null:{points:p,joinedEnds:(c.joined?1:0)+(k.joined?1:0)}}function N2(e,t,r,o,i,a,s=[]){if(!Lc(e,o,t))return!1;let n=new Set(i?[i.id]:[]),l=yc(e,t,r,o,n);if(!l||l.joinedEnds===0)return!1;let{points:d}=l;if(Gt(d)<De||(d=Sr(d,Bi(e,s),t),d.length<2||Gt(d)<De))return!1;let h=i??(()=>{let M=e.map(x=>({l:x,d:H2(o,x)?.distance??1/0})).sort((x,b)=>x.d-b.d||x.l.id.localeCompare(b.l.id));return M.length>0&&Number.isFinite(M[0].d)?M[0].l:void 0})();if(!h||za(d,h.points)||!Ci(d,e,a,h.id,!0))return!1;{let M=gt(d),x=M[M.length-1],b=0;for(let u=0;u<=x;u+=Wr){let{p:P}=ut(d,M,u),C=1/0;for(let Q of e)for(let R=1;R<Q.points.length;R++)C=Math.min(C,A(P,st(P,Q.points[R-1],Q.points[R])));b=Math.max(b,C)}if(b<xs*a)return!1}let c=gt(h.points),k=c[c.length-1],p=H2(o,h),f=0;if(p&&k>0)for(let M=1;M<h.points.length;M++){let x=st(p.point,h.points[M-1],h.points[M]);if(A(p.point,x)<1e-6){f=c[M-1]+A(h.points[M-1],x);break}}let m=k>0?Math.min(.99,Math.max(.01,f/k)):.5,v=null,L=Math.max(1,Math.min(99,Math.round(m*100)));for(let M=0;M<99;M++){let x=1+(L-1+M)%99,b=yi(h.id,x/100);if(!e.some(u=>u.id===b)){v=b;break}}if(!v)return!1;let w=Xo(Va(h.type),"footpath");return e.push({id:v,type:w,points:d,widthM:ve(w),parentId:h.id}),!0}function Mc(e,t,r,o,i,a,s,n=[]){let l=wc(e,t,o,i);if(!l||l.distance<=Z3)return!1;if(N2(e,t,o,l.point,void 0,s,n))return!0;let d=Math.round(pt(l.junction,l.point))%360,h=Math.min(ri,Math.max(De,l.distance+kd(r)/2)),c=(()=>{let w=gt(l.parent.points),M=w[w.length-1];if(!(M>0))return .5;let x=0;for(let b=1;b<l.parent.points.length;b++){let u=l.parent.points[b-1],P=l.parent.points[b],C=st(l.junction,u,P);if(A(l.junction,C)<1e-6){x=w[b-1]+A(u,C);break}}return Math.min(.99,Math.max(.01,x/M))})(),k=null,p=Math.max(1,Math.min(99,Math.round(c*100)));for(let w=0;w<99;w++){let M=1+(p-1+w)%99,x=yi(l.parent.id,M/100);if(!e.some(b=>b.id===x)){k=x;break}}if(!k)return!1;let f=Va(l.parent.type),m=to(l.junction,d,h,a),v=V2(e,m[m.length-1],new Set([l.parent.id]),oi,m[m.length-2]);v&&(m=[...m,v]);let L=m.length;return m=Sr(m,Bi(e,n),t,l.parent.id),(v||m.length<L)&&(f=Xo(f,"footpath")),m.length<2||Gt(m)<De||j2(m,l.parent)?!1:(e.push({id:k,type:f,points:m,widthM:ve(f),parentId:l.parent.id}),!0)}function uc(e,t){let r=0,o=0;for(let i=1;i<e.points.length;i++){let a=e.points[i-1],s=e.points[i],n=A(a,s);r+=(A(a,t.centre)+A(s,t.centre))/2*n,o+=n}return o===0?A(e.points[0],t.centre):r/o}function gc(e,t){let r=0,o=0;for(let i=1;i<e.points.length;i++){let a=e.points[i-1],s=e.points[i],n=new Z((a.x+s.x)/2,(a.y+s.y)/2),l=A(a,s);r+=$2(pt(a,s),pt(t.centre,n))*l,o+=l}return o===0?0:r/o}function bc(e,t,r,o,i,a,s,n=[]){let l=vc(mc(e,t,o,i));if(l.widthDeg<=nc(i))return!1;let d=o.ringAt(i,l.bisectorDeg),h=e.filter(m=>gc(m,t)>=60).map(m=>uc(m,t)).filter(m=>m>Ct(t)&&m<=i).sort((m,v)=>v-m).map(m=>o.ringAt(m,l.bisectorDeg)),c=Ct(t)+De/2,k=[.9,.75,.6,.45].map(m=>d*m).filter(m=>m>c);for(let m of[...h,...k]){let v=Lt(l.bisectorDeg),L=new Z(t.centre.x+v.x*m,t.centre.y+v.y*m);if(N2(e,t,o,L,void 0,s,n))return!0}let p=Math.max(0,d-Ct(t));if(p<De)return!1;let f=Math.min(p,kd(r)*v3);for(let m of[0,6,-6,12,-12,18,-18]){let v=Math.round(l.bisectorDeg+m+360)%360,L=Li(v);if(e.some(b=>b.id===L||b.id===y2(v)))continue;let w=Lt(v),M=new Z(t.centre.x+w.x*(t.diameter/2)*Ur,t.centre.y+w.y*(t.diameter/2)*Ur),x=Sr(to(M,v,f,a),Bi(e,n),t);if(!(x.length<2||Gt(x)<De))return e.push({id:L,type:"local",points:x,widthM:ve("local")}),!0}return!1}function D2(e,t,r,o,i,a=1,s=1/0){let n=e.filter(f=>Ot(f.id)),l=e.filter(f=>!Ot(f.id)),d=[],h=f=>{let m=[];for(let v of f){let L=l.find(M=>M.id===v.id),w=L?v.points:Xr(v.points,l);if(!w||!L&&f.some(M=>M.id!==v.id&&za(w,M.points)))return;m.push({...v,points:w})}m.some(v=>n.some(L=>za(v.points,L.points)))||d.push([...m,...n])};for(let f=0;f<4;f++){let m=l.map(w=>({...w,points:[...w.points]})),v=o.radiusM;if((f===0?bc(m,t,r,o,v,i,a,n):f===1?Mc(m,t,r,o,v,i,a,n):cc(m,t,r,o,i,v,a,n))&&h(m),d.length>=s)return d}let k=pd(l,t,o,hd(t,o.radiusM)).map(f=>({slot:f,key:i.float()})).sort((f,m)=>f.key-m.key);for(let{slot:f}of k.slice(0,6))for(let m of[-1,1]){let v=yi(f.parent.id,f.at);if(l.some(b=>b.id===v))continue;let L=f.dirDeg+m*85,w=Math.min(48,Math.max(18,o.radiusM*.65)),M=Sr(to(f.anchor,L,w,i),e,t,f.parent.id);if(M.length<2||Gt(M)<12||j2(M,f.parent)||!Ci(M,l,a,f.parent.id))continue;let x=Va(f.parent.type);if(h([...l,{id:v,type:x,points:M,widthM:ve(x),parentId:f.parent.id}]),d.length>=s)return d}let p=i.int(0,30);for(let f=p;f<360;f+=30){let m=Li(f);if(l.some(M=>M.id===m))continue;let v=Lt(f),L=new Z(t.centre.x+v.x*t.diameter*Ur/2,t.centre.y+v.y*t.diameter*Ur/2),w=Sr(to(L,f,o.at(f),i),e,t);if(!(w.length<2||Gt(w)<12||!Ci(w,l,a))&&(h([...l,{id:m,type:"local",points:w,widthM:ve("local")}]),d.length>=s))return d}return d}function vd(e){let{lanes:t,green:r,site:o,activeDeck:i,lotProfile:a,f0:s,lotFloorM:n,lotCapM:l,terrace:d,trace:h}=e,c=a.radiusM,k=new Vt(e.seed),p=new Map(t.map(u=>[u.id,u.type]));p.set("green","main");let f=[...S1(r,s,yo,k,t),...t.filter(u=>!Ot(u.id)).flatMap(u=>P1(u,r,c,s,yo,k,n,l,z2(u,r,a,o.population)))];if(h){K1(h);for(let u of f)h.cut.set(u.id,u.frontageM)}let m=C2(f,r,o.water);if(h){let u=new Set(m.map(P=>P.id));for(let P of h.cut.keys())u.has(P)||h.fates.set(P,"clipped")}let v=m.filter(u=>u.frontageM>=n).length;if(f=x1(m,t,r,h?.convergeDetail),h){let u=new Set(f.map(P=>P.id));for(let P of m)u.has(P.id)||h.fates.set(P.id,"converging-claim")}for(let u=1;u<=j3;u++){let P=Y1({lanes:t.filter(Q=>!Ot(Q.id)),green:r,standing:f,builtRadiusM:c,f0:s,depthM:yo,floorM:n,maxFrontageM:l,reachOf:Q=>z2(Q,r,a,o.population),pass:u});if(P.added.length===0)break;let C=C2(P.added,r,o.water);if(h){for(let R of P.added)h.cut.set(R.id,R.frontageM);let Q=new Set(C.map(R=>R.id));for(let R of P.added)Q.has(R.id)||h.fates.set(R.id,"clipped")}if(C.length===0)break;P.trimmed.size>0&&(f=f.map(Q=>{let R=P.trimmed.get(Q.id);return R===void 0?Q:{...Q,depthM:R}})),v+=C.filter(Q=>Q.frontageM>=n).length,f=[...f,...C]}f=Eo(C1(f,r,p));let L=s,w=f.filter(u=>u.laneId!=="green");w.length>0&&(L=w.reduce((u,P)=>u+P.frontageM,0)/w.length);let M=e.reservedLandmarks?{landmarks:e.reservedLandmarks,diagnostics:[]}:Ha(o,r,t.filter(u=>!Ot(u.id)),c,new Vt(e.seed+19)),x=M.landmarks.map(u=>({lm:u,building:Pi(u)})).filter(({building:u})=>!Ie(u,t));f=f.filter(u=>!x.some(({lm:P})=>oe(wt(u),wt(P.lot)))),f.push(...x.map(({lm:u})=>u.lot));let b=D1(f,i,o,k,t,h?.fates,d,x.map(u=>u.building));return{lots:f,spend:b,deckUsableLotCount:v,measuredMeanFrontage:L,diagnostics:M.diagnostics}}function wd(e){Ar(e);let t=e.waterContext;if(!t)return{input:e};let r={version:1,status:t.status,issues:[]};if(t.status==="unknown-units")return r.issues.push({code:"water-units-unknown"}),{input:{...e,oceanBearing:void 0,port:!1},result:r};t.omittedRivers?.length&&r.issues.push({code:"water-river-local-width-unavailable"});let o=e.coastlineGeometry;if(!Object.hasOwn(e,"coastlineGeometry")){let i=t.bodies.filter(a=>a.distanceM<=t.surveyRadiusM);if(o=[],i.length){let a=i[0];if(i.length!==1||a.kind!=="ocean"||a.coastApproximation!=="simple-local-coast")throw new je("water-geometry-required","This coast or lake needs surveyed water polygons.");let s=Lt(a.bearingDeg),n=new Z(-s.y,s.x),l=t.surveyRadiusM*2;o=[[...Array.from({length:201},(h,c)=>{let k=(c-100)*l/100,p=a.distanceM+80*(1-Math.exp(-k*k/16e4));return new Z(s.x*p+n.x*k,s.y*p+n.y*k)}),new Z(s.x*l+n.x*l,s.y*l+n.y*l),new Z(s.x*l-n.x*l,s.y*l-n.y*l)]],r.status="approximate"}}return{input:{...e,oceanBearing:void 0,coastlineGeometry:o},result:r}}function Ld(e,t,r){let o=e.waterContext;if(!o||o.status!=="measured"||!r)return;K5(t,o.surveyRadiusM);let i=()=>{r.issues.some(l=>l.code==="water-context-conflict")||r.issues.push({code:"water-context-conflict"})},a=new Z(0,0),s=be(t);if(!s.some(([l,d])=>A(a,st(a,l,d))<1e-7)&&t.some(l=>bt(a,l)))throw new je("water-context-conflict","The supplied burg position is in water. Correct its location or shoreline survey.");if(Object.hasOwn(e,"coastlineGeometry"))for(let l of o.bodies){if(!l.polygonIndices?.length){l.distanceM<=o.surveyRadiusM&&i();continue}let d=l.polygonIndices.map(m=>t[m]),h=m=>d.some(v=>v.some((L,w)=>A(m,st(m,L,v[(w+1)%v.length]))<1e-5)),c=1/0,k=Lt(l.bearingDeg),p=new Z(k.x*l.distanceM,k.y*l.distanceM),f=1/0;for(let[m,v]of s)h(new Z((m.x+v.x)/2,(m.y+v.y)/2))&&(c=Math.min(c,A(a,st(a,m,v))),f=Math.min(f,A(p,st(p,m,v))));(l.distanceM<=o.surveyRadiusM&&(Math.abs(c-l.distanceM)>1||f>1)||c<o.surveyRadiusM&&Math.abs(c-l.distanceM)>1)&&i()}}function yd(e,t){return(e.rivers??[]).flatMap((r,o)=>{if(!(r.widthM>0)||!Number.isFinite(r.widthM))return[];let i=r.centreline.filter(v=>Number.isFinite(v.x)&&Number.isFinite(v.y)).map(v=>new Z(v.x,v.y)).filter((v,L,w)=>L===0||A(v,w[L-1])>.001);if(i.length<2)return[];let a=gt(i),s=a.at(-1),n=0,l=1/0;for(let v=1;v<i.length;v++){let L=st(new Z(0,0),i[v-1],i[v]);A(L,new Z(0,0))<l&&(l=A(L,new Z(0,0)),n=a[v-1]+A(i[v-1],L))}let d=new Vt(t*3571+o*7919+1013),h=Math.max(300,30*Math.sqrt(Math.max(1,e.population))),c=Math.min(40,h*.075,s*.05),k=d.float()*Math.PI*2,p=v=>Math.sin(v*Math.PI*2/h+k)+.18*Math.sin(v*Math.PI*2/(h*.57)+k*1.7),f=Math.ceil(s/6),m=[];for(let v=0;v<=f;v++){let L=s*v/f,w=ut(i,a,L).p,M=ut(i,a,Math.max(0,L-3)).p,x=ut(i,a,Math.min(s,L+3)).p,b=A(M,x);if(b<1e-8){m.push(w);continue}let u=Math.sin(Math.min(1,Math.min(L,s-L)/80)*Math.PI/2)**2,P=r.meander===!1?0:c*(p(L)-p(n))*u;m.push(new Z(w.x-(x.y-M.y)/b*P,w.y+(x.x-M.x)/b*P))}return[[...Ze(m,r.widthM/2,1),...Ze(m,r.widthM/2,-1).reverse()]]})}var xc=new Set(Ye),ja=5e3,Zc=24,Pc=4.6,Sc=14,Cc=1.15,Ei=[6,2.4],Bc=[.85,.15],Ec=360,_c=7919,Rc=104729;function Qc(e,t){if((e.coastlineGeometry?.length??0)>0)return[];if(e.oceanBearing==null)return[];let r=Lt(e.oceanBearing),o=new Z(-r.y,r.x),i=Pc*Math.sqrt(Math.max(1,e.population)),a=Math.max(i,Ec/Ei[0]),s=i*Cc,n=new Vt(t*_c+Rc),l=n.float()>=.25,d=Ei.map((L,w)=>w===0?l?-Math.PI/2:Math.PI/2:n.float()*Math.PI*2),h=a*Zc,k=a*Math.min(...Ei)/Sc,p=Math.ceil(2*h/k),f=[];for(let L=0;L<=p;L++){let w=-h+2*h*L/p,M=0;for(let b=0;b<Ei.length;b++)M+=Bc[b]*Math.sin(2*Math.PI*w/(a*Ei[b])+d[b]);let x=i+s+M*s;f.push(new Z(r.x*x+o.x*w,r.y*x+o.y*w))}let m=new Z(r.x*ja-o.x*h,r.y*ja-o.y*h),v=new Z(r.x*ja+o.x*h,r.y*ja+o.y*h);return[[...f,v,m]]}function Md(e,t=0){let r=e,o=wd(e);e=o.input;let i=(e.roadBearings??[]).map(s=>{if(typeof s=="number")return{bearingDeg:s,type:"main",through:!1,routeId:void 0,followsRiver:void 0,relief:void 0};let n=s.kind,l=n&&xc.has(n)?n:Nn(Ui(s.kind??(s.group==="trails"?"foot":"road"))??"foot");return l==="searoutes"?null:{bearingDeg:s.bearing_deg,type:l,through:s.through??!1,routeId:s.route_id,followsRiver:s.followsRiver,relief:s.relief}}).filter(s=>s!==null),a=(e.coastlineGeometry??[]).map(s=>s.map(n=>new Z(n.x,n.y))).concat(Qc(e,t),yd(e,t));return Ld(r,a,o.result),{...o.result?{waterContextResult:o.result}:{},...r.waterContext?.status==="measured"?{surveyRadiusM:r.waterContext.surveyRadiusM}:{},freshwaterIrrigation:(e.rivers?.length??0)>0,population:e.population,biome:Ir(e.biome),routes:i,water:a,flags:{port:e.port,temple:e.temple,trade:e.trade??!1,walls:e.walls,capital:e.capital??!1,citadel:e.citadel??!1,plaza:e.plaza??!1,shanty:e.shanty??!1}}}function ud(e,t){return[...e].sort((r,o)=>r.id.localeCompare(o.id)).flatMap(r=>xe(r.points,t).map((o,i)=>{let a=o.points[0],s=o.points[1],n=o.points.at(-1),l=o.points.at(-2),d=(m,v)=>{let L=A(m,v);return new Z(m.x+(m.x-v.x)/L,m.y+(m.y-v.y)/L)},h=[d(a,s),...o.points,d(n,l)],c=Qt(r).surfaceM/2+.35,k=[...Ze(h,c,1),...Ze(h,c,-1).reverse()],p=gt(o.points),f=o.endM-o.startM;return{id:`bridge:${r.id}:${i}`,laneId:r.id,position:ut(o.points,p,f/2).p,bearingDeg:pt(a,n),spanM:f,narrow:f<=br,centreline:h,deck:k}}))}function gd(e,t){let r=e.centre,o=Ct(e),i=[];for(let a of t)for(let s=1;s<a.points.length;s++){let n=a.points[s-1],l=a.points[s],d=l.x-n.x,h=l.y-n.y,c=n.x-r.x,k=n.y-r.y,p=d*d+h*h,f=2*(c*d+k*h),m=f*f-4*p*(c*c+k*k-o*o);if(!(p<1e-9||m<0))for(let v of[(-f-Math.sqrt(m))/(2*p),(-f+Math.sqrt(m))/(2*p)]){if(v<0||v>1)continue;let L=new Z(n.x+v*d,n.y+v*h);i.some(w=>A(L,w)<2)||i.push(L)}}return i.sort((a,s)=>pt(r,a)-pt(r,s))}function Ic(e){return e.routes}function Zd(e,t,r){let o=Math.max(1,e/t);return Math.sqrt(o*r/Math.PI)}function Ac(e,t,r){let o=e.length?e.reduce((n,l)=>ft(n.type)<=ft(l.type)?n:l):void 0,i=o?ia[o.type]??ia.local:ia.local,a=i*Math.sqrt(t/s3),s=Math.min(n3,r/l3);return Math.min(Math.max(a,i),s)}var bd=2,Tc=200,Oc=1e-6;function Pd(e,t){let r=[];for(let o=0;o<16;o++){let i=o/16*Math.PI*2;r.push(new Z(e.x+t*Math.cos(i),e.y+t*Math.sin(i)))}return r}function xd(e,t,r){return Tt(r,e,t),r.length===0?!1:[e,...Pd(e,t)].some(i=>kt(i,r))}function Hc(e,t,r){let o=Pd(e,t).filter(n=>kt(n,r));if(o.length===0)return new Z(0,1);let i=0,a=0;for(let n of o){let l=We(n.x-e.x,n.y-e.y);i+=l.x,a+=l.y}if(A(new Z(0,0),new Z(i,a))<Oc)return new Z(0,1);let s=We(i,a);return new Z(-s.x,-s.y)}function F2(e,t,r){let o=e;if(!xd(o,t,r))return{centre:o,clipped:!1};for(let i=0;i<Tc;i++){let a=Hc(o,t,r);if(o=new Z(o.x+a.x*bd,o.y+a.y*bd),!xd(o,t,r))break}return{centre:o,clipped:!0}}function zc(e){let t=e.trunks.filter(o=>o.points.length>=2&&!o.id.startsWith("trunk-loop-")&&!Ot(o.id));if(t.length===0)return null;let r=o=>o.points.slice(1).reduce((i,a,s)=>i+A(o.points[s],a),0);return t.reduce((o,i)=>{let a=ft(i.type)-ft(o.type);return a!==0?a<0?i:o:r(i)>r(o)?i:o})}function Vc(e,t){if(t<=0||t+1>=e.length)return 0;let r=e[t-1],o=e[t],i=e[t+1],a=We(o.x-r.x,o.y-r.y),s=We(i.x-o.x,i.y-o.y);return a.x*s.x+a.y*s.y}function jc(e,t,r,o){let i=[];for(let s=1;s+1<e.points.length;s++){let n=e.points[s],l=A(n,t);l>r||i.push({p:n,score:1-l/Math.max(1,r)+Vc(e.points,s)})}if(i.length===0)return Yr(t,e.points).point;i.sort((s,n)=>n.score-s.score);let a=i.slice(0,3);return a[o.int(0,a.length)].p}function Sd(e,t,r,o){let i=Ic(e),a=i.find(M=>M.through),s=Ac(i,e.population,r),l=s/2+d3,d=zc(t),h=t.junctions.filter(M=>M.laneIds.length>=3&&A(M.position,t.aim)<=r).sort((M,x)=>A(M.position,t.aim)-A(x.position,t.aim))[0],c=t.pattern==="main-street",k=c?"astride":"terminal",p=c&&d?jc(d,t.aim,r,o):h?h.position:t.aim;!c&&h&&(k="astride");let f=F2(p,l,e.water);p=f.centre;let v={shape:"sm-green-round",variant:o.bool(.5)?"a":"b",centre:p,diameter:s,bearingDeg:0},L=$c(v,t,r),w=gd(v,[...t.trunks.filter(M=>!Ot(M.id)),...L]);return w.length===3?(v.shape="sm-green-triangle",v.outline=w):w.length===2?(v.shape=a&&ft(a.type)<=ft("main")?"sm-green-lens-long":"sm-green-lens",v.bearingDeg=pt(w[0],w[1]),k="astride"):w.length>=4?v.shape="sm-green-square":k="terminal",f.clipped&&(v.shape="sm-green-d",delete v.outline),{green:v,relation:k,connectors:L}}function $c(e,t,r){let o=Ct(e),i=t.trunks.filter(h=>h.points.length>=2&&!Ot(h.id));if(i.length===0)return[];let a=i.map(h=>({t:h,hit:Yr(e.centre,h.points)})).sort((h,c)=>h.hit.distance-c.hit.distance)[0];if(a.hit.distance<=o)return[];let s=r*m5,n=a.hit.point,l=We(n.x-e.centre.x,n.y-e.centre.y),d=new Z(e.centre.x+l.x*o,e.centre.y+l.y*o);return A(d,n)>s?[]:[{id:"green-c0",type:"local",points:[d,n],widthM:ve("local")}]}var $a=1,Nc=12,Ue=Math.round(360/$a);function G2(e,t){let r=o=>{let i=fe(o)/$a,a=Math.floor(i),s=i-a,n=e[a%Ue],l=e[(a+1)%Ue];return n+(l-n)*s};return{radiusM:t,shapeAt:r,at:o=>t*r(o),scaled:o=>G2(e,t*o),ringAt:(o,i)=>o*r(i)}}function Dc(e){if(e.length===0)return{axisDeg:0,strength:0};let t=0,r=0;for(let a of e){let s=2*a*Math.PI/180;t+=Math.cos(s),r+=Math.sin(s)}let o=Math.hypot(t,r)/e.length;return{axisDeg:fe(Math.atan2(r,t)*180/Math.PI/2),strength:o}}function Fc(e,t){if(Tt(e.water,e.centre,e.radiusM*Us+uo),e.water.length===0)return 1/0;let r=Lt(t),o=e.radiusM*Us,i=a=>new Z(e.centre.x+r.x*a,e.centre.y+r.y*a);for(let a=0;a<=o;a+=bo){if(!kt(i(a),e.water))continue;let s=1/0;for(let n=bo;n<=uo;n+=bo)if(!kt(i(a+n),e.water)){s=n;break}if(s>=br){let n=i(a),l,d=1/0;for(let[c,k]of be(e.water)){let p=st(n,c,k),f=Math.hypot(n.x-p.x,n.y-p.y);f<d&&(d=f,l=[c,k])}let h=0;if(l){let[c,k]=l,p=Math.hypot(k.x-c.x,k.y-c.y),f=-(k.y-c.y)/(p||1),m=(k.x-c.x)/(p||1);for(let v of[-1,1]){let L=1/0;for(let w=bo;w<br;w+=bo)if(!kt(new Z(n.x+v*f*w,n.y+v*m*w),e.water)){L=w;break}h+=L}}else h=1/0;if(h>=br)return a;continue}a+=s}return 1/0}function Cd(e){let{rng:t}=e,r=Xl.map((v,L)=>{let w=t.float()*360,[M,x]=Jl[L];return{k:v,phaseDeg:w,amp:M+t.float()*(x-M)}}),o=Dc(e.trunkBearingsDeg),i=new Array(Ue);for(let v=0;v<Ue;v++){let L=v*$a,w=1;for(let M of r)w+=M.amp*Math.cos(M.k*(L-M.phaseDeg)*Math.PI/180);w*=1+t5*o.strength*Math.cos(2*(L-o.axisDeg)*Math.PI/180),i[v]=w}let a=i.reduce((v,L)=>v+L,0)/i.length,s=Math.sqrt(i.reduce((v,L)=>v+(L-a)**2,0)/i.length)/Math.max(1e-9,a),n=s>=Ws?1:Math.min(e5,Ws/Math.max(1e-6,s));for(let v=0;v<Ue;v++)i[v]=Math.min(li,Math.max(r5,a+(i[v]-a)*n));let l=4,d=0,h=0;for(let v=0;v<Ue;v++)for(let L=0;L<l;L++){let w=L/l,M=i[v]+(i[(v+1)%Ue]-i[v])*w;d+=M*M,h+=1}let c=1/Math.sqrt(d/h),k=i.map(v=>v*c),p=new Array(Ue).fill(1/0),f=!1;for(let v=0;v<Ue;v++){let L=Fc(e,v*$a);Number.isFinite(L)&&(f=!0,p[v]=Math.max(i5,(L-o5)/e.radiusM))}if(!f)return G2(k,e.radiusM);let m=()=>{for(let v=0;v<Ue;v++)k[v]=Math.min(k[v],p[v])};for(let v=0;v<Nc;v++){m();let L=k.reduce((M,x)=>M+x*x,0)/k.length;if(!(L>0))break;let w=1/Math.sqrt(L);if(Math.abs(w-1)<1e-9)break;for(let M=0;M<Ue;M++)k[M]=Math.min(li*1.5,k[M]*w)}return m(),G2(k,e.radiusM)}function Ed(e,t){let r=e.flatMap(o=>[o.points[0],o.points[o.points.length-1]].map(i=>({p:i,laneId:o.id})));return e.map(o=>{if(Ce(o.id))return o;let i=o.points.map(s=>new Z(s.x,s.y)),a=o.points.map(s=>new Z(s.x,s.y));for(let s=0;s<Ps;s++)for(let n=1;n<a.length-1;n++)if(!r.some(({p:l,laneId:d})=>d!==o.id&&(A(l,st(l,i[n-1],i[n]))<.15||A(l,st(l,i[n],i[n+1]))<.15)))for(let l of t){let d=pe(l.glyph,l.footprint),h=o.widthM/2+_3+Math.min(d.width,d.depth)/2,c=a[n].x-l.position.x,k=a[n].y-l.position.y,p=A(a[n],l.position);if(p===0||p>=h)continue;let f=(h-p)/Ps;a[n]=new Z(a[n].x+c/p*f,a[n].y+k/p*f)}for(let s=0;s<a.length;s++){let n=a[s].x-i[s].x,l=a[s].y-i[s].y,d=A(a[s],i[s]);d>sa&&(a[s]=new Z(i[s].x+n/d*sa,i[s].y+l/d*sa))}return{...o,points:a}})}function Gc(e,t,r){let o=`${e.id}:`;return t.filter(i=>r.has(i.lotId)?r.get(i.lotId)===e.id:i.lotId.startsWith(o))}function Wc(e,t,r){let o=1/0,i=0;for(let a=1;a<t.length;a++){let s=st(e,t[a-1],t[a]),n=A(e,s);n<o&&(o=n,i=r[a-1]+A(t[a-1],s))}return i}function Bd(e){return e.endsWith("/c")}var Uc=1.5;function qc(e){let t=new Map,r=new Set,o=new Map;for(let i of e)o.set(i.id,gt(i.points));for(let i of e)if(!(i.points.length<2))for(let[a,s]of[i.points[0],i.points[i.points.length-1]].entries())for(let n of e){if(n.id===i.id)continue;let l=o.get(n.id),d=Uc,h=-1;for(let c=1;c<n.points.length;c++){let k=st(s,n.points[c-1],n.points[c]),p=A(s,k);p<d&&(d=p,h=l[c-1]+A(n.points[c-1],k))}h>=0&&(t.set(n.id,Math.max(t.get(n.id)??0,h)),a===1&&r.add(i.id))}return{floorS:t,joiners:r}}function _d(e,t,r={}){let{weld:o=!0}=r,i=new Map(r.lots?.map(d=>[d.id,d.laneId])??[]),a=[],s=new Set(e.filter(d=>Bd(d.id)&&d.parentId!==void 0).map(d=>d.parentId)),{floorS:n,joiners:l}=o?qc(e):{floorS:new Map,joiners:new Set};for(let d of e){if(Ce(d.id)){a.push(d);continue}if(Bd(d.id)){a.push(d);continue}if(s.has(d.id)){a.push(d);continue}if(l.has(d.id)){a.push(d);continue}let h=Gc(d,t,i),c=n.get(d.id)??0;if(h.length===0&&!n.has(d.id))continue;let k=gt(d.points),p=h.reduce((L,w)=>Math.max(L,Wc(w.position,d.points,k)),0),f=Math.min(k[k.length-1],Math.max(p+R3,c)),m=d.points.filter((L,w)=>k[w]<f),v=ut(d.points,k,f).p;m.length===0&&m.push(d.points[0]),A(m[m.length-1],v)>1e-6&&m.push(v),a.push({...d,points:m.length>=2?m:d.points.slice(0,2)})}return a}var Id=1e3,Kc=96,Rd=4,Qd=3;function Yc(e,t){for(let r=1;r<e.length;r++)for(let o=1;o<t.length;o++)if(Wt(e[r-1],e[r],t[o-1],t[o]))return!0;return!1}function Ad(e,t,r){let o=new Vt(t),i=Md(e,t),a=[],{entries:s,dropped:n}=y5(i.biome,i.population,o);n.length>0&&a.push(`deck dropped (no manifest entry): ${n.join(", ")}`);let l=e2(s),d=Zd(i.population,l,H3),h=M5(s),c=u5(s),k=h*T3,p=h+Z1(i.population),f=h,m=ed(i),v=Math.ceil(i.population/g5(s))+m,L=Math.max(p,c),w=cd(v,L),M=F2(new Z(0,0),v5,i.water).centre,x=M1(i,y1(w),w,o,M);a.push(...x.diagnostics);let b=Sd(i,x,d,o),u=b.green,P=b.relation,C=p,Q=c,R=s,V=[...x.trunks,...b.connectors].map(ot=>Aa(ot,v)),j=Math.max(w,u.diameter/2+2*yo+L),F=new Vt(t*a5+s5),K=Cd({centre:u.centre,radiusM:j,trunkBearingsDeg:i.routes.map(ot=>ot.bearingDeg),water:i.water,rng:F}),H=K,X=H.radiusM,nt=!1,mt=Ha(i,u,V.filter(ot=>!Ot(ot.id)),X,new Vt(t*3571+90)),O=mt.landmarks.map(Pi);a.push(...mt.diagnostics);let Y=(ot,St=!1)=>vd({lanes:ot,green:u,site:i,activeDeck:R,lotProfile:H,f0:C,lotFloorM:Q,lotCapM:k,seed:t*3571+71,terrace:nt,reservedLandmarks:mt.landmarks,trace:St?r:void 0}),rt=Y(V),yt=()=>({evaluated:rt,lanes:V,lotProfile:H,lotRadiusM:X,f0:C,lotFloorM:Q,activeDeck:R,terrace:nt}),B=yt(),U=0,$=0,J=0,lt=1,xt=0,zt=0,ae=!1,Pe=Math.ceil((p-f)/Es);for(let ot=0;ot<Kc&&rt.spend.unhoused>0;ot++){let St=(g=1/0)=>D2(V,u,rt.measuredMeanFrontage,H,new Vt(t*7919+ot*101+37),lt,g),qt=St(Rd),Jt=!1,I;for(let g=0;g===qt.length&&!I&&!Jt&&(qt=St(),Jt=!0),!(g>=qt.length||g>=Rd&&I);g++){let _=qt[g].map(T=>Aa(T,v));if(i.water.length&&_.some(T=>!V.some(W=>W.id===T.id&&W.points===T.points)&&!Jr(T.points,i.water,Qt(T).surfaceM/2+1.5))){J++;continue}if(O.some(T=>Ie(T,_))){J++;continue}let E=Y(_),N=E.spend.housed-rt.spend.housed;if(N<=0){J++;continue}let z=Math.max(1,_.reduce((T,W)=>T+Gt(W.points),0)-V.reduce((T,W)=>T+Gt(W.points),0)),G=T=>T.reduce((W,et)=>W+et.occupancy*A(et.position,u.centre),0),D=Math.max(0,G(E.spend.buildings)-G(rt.spend.buildings))/N,tt=N/(z+8)/(1+D/X);(!I||tt>I.score)&&(I={lanes:_,result:E,score:tt})}if(!I){let g=T2(V,u,rt.spend.buildings,rt.lots);if(g.length<V.length){let S=Y(g);if(S.spend.housed>=rt.spend.housed){V=g,rt=S,B=yt();continue}}}if(!I&&U>=2)for(let g of qt.slice(0,Qd)){let S=D2(g,u,rt.measuredMeanFrontage,H,new Vt(t*31+ot*997),lt,Qd);for(let _ of S){let E=_.map(tt=>Aa(tt,v));if(i.water.length&&E.some(tt=>!V.some(T=>T.id===tt.id&&T.points===tt.points)&&!Jr(tt.points,i.water,Qt(tt).surfaceM/2+1.5))){J++;continue}if(O.some(tt=>Ie(tt,E))){J++;continue}let N=Y(E),z=N.spend.housed-rt.spend.housed;if(z<=0){J++;continue}let G=Math.max(1,E.reduce((tt,T)=>tt+Gt(T.points),0)-V.reduce((tt,T)=>tt+Gt(T.points),0)),D=z/(G+16);(!I||D>I.score)&&(I={lanes:E,result:N,score:D})}}if(I){V=I.lanes,rt=I.result,B=yt(),$++;continue}if(U++>=ol+(i.water.length?2:0))break;if(xt<Pe){let g=++xt*Es;C=Math.max(f,p-g),Q=Math.max(f,c-g),R=b5(s,g)}else ae?lt>bs?lt=Math.max(bs,lt-f3):(X=j*(1+ ++zt*il),H=K.scaled(X/j)):(ae=!0,nt=!0);let y=Y(V);y.spend.housed>=rt.spend.housed?(rt=y,B=yt()):{f0:C,lotFloorM:Q,activeDeck:R,terrace:nt}=B}({evaluated:rt,lanes:V,lotProfile:H,lotRadiusM:X,f0:C,lotFloorM:Q,activeDeck:R,terrace:nt}=B),r&&(rt=Y(V,!0));let{lots:Zt,spend:$t,deckUsableLotCount:Ut}=rt;a.push(`growth: ${$} additions accepted, ${J} trials rejected, ${U} fallback rounds`),$t.unhoused>0&&a.push(`overflow: ${$t.unhoused} of ${i.population} unhoused after bounded frontage growth`);let me=Ed(V.filter(ot=>!Ot(ot.id)),$t.buildings).map(ot=>$t.buildings.some(qt=>Ie(qt,[ot]))||!Jr(ot.points,i.water,Qt(ot).surfaceM/2+1.5)?V.find(qt=>qt.id===ot.id)??ot:ot).concat(V.filter(ot=>Ot(ot.id)));for(let ot=0;ot<4;ot++){let St=me.map((Jt,I)=>I).sort((Jt,I)=>me[Jt].id.localeCompare(me[I].id)),qt=!1;for(let Jt of St){let I=V.find(g=>g.id===me[Jt].id);if(!I||I===me[Jt])continue;me.some((g,S)=>S!==Jt&&Yc(me[Jt].points,g.points))&&(me[Jt]=I,qt=!0)}if(!qt)break}let rr=_d(T2(me,u,$t.buildings,Zt),$t.buildings,{lots:Zt}).map(ot=>Jr(ot.points,i.water,Qt(ot).surfaceM/2+1.5)&&!$t.buildings.some(St=>Ie(St,[ot]))?ot:me.find(St=>St.id===ot.id)??ot),Le=md(rr,u,$t.buildings,Zt,i.water);a.push(...rt.diagnostics);let qe=new Map(Le.map(ot=>[ot.id,ot])),ro=new Set($t.buildings.map(ot=>ot.lotId)),or=Zt.filter(ot=>{if(ro.has(ot.id)||td(ot.id))return!0;if(ot.laneId==="green"){let qt=u.diameter/2*Lo+gr;return Math.abs(A(ot.front,u.centre)-qt)<_s}let St=qe.get(ot.laneId);return St?Xc(ot,St):!1});if(r){let ot=new Set(or.map(St=>St.id));for(let St of r.cut.keys())!ot.has(St)&&r.fates.get(St)!=="clipped"&&r.fates.get(St)!=="converging-claim"&&r.staleAfterTrim.add(St)}Ut>0&&a.push(`seating: ${Math.round($t.buildings.length/Ut*100)}% (${$t.buildings.length} of ${Ut} deck-usable lots)`);let Nt=W1({site:i,green:u,lanes:Le,lots:or,buildings:$t.buildings,builtRadiusM:X,f0:C,rng:o}),Cr=[...Le,...Nt.accessLanes];if(a.push(...Nt.diagnostics),i.water.length>0){let ot=Nt.fields.reduce((qt,Jt)=>{let I=0;for(let y=0;y<Jt.polygon.length;y++){let g=Jt.polygon[y],S=Jt.polygon[(y+1)%Jt.polygon.length];I+=g.x*S.y-S.x*g.y}return qt+Math.abs(I)/2},0),St=Math.PI*X*X;St>0&&ot<St*Is&&a.push(`water: the site is hemmed in \u2014 ${(ot/1e3).toFixed(1)}k m2 of farmland, ${(ot/St).toFixed(2)}x the built area against ${Is.toFixed(1)}x expected of a village with room`)}let se=U1({lanes:Cr,buildings:$t.buildings.map(ot=>ot.position),greenCentre:u.centre,dressing:[...Nt.fields.flatMap(ot=>ot.polygon),...Nt.fieldEdges.map(ot=>ot.position),...Nt.vegetation.map(ot=>ot.position),...Nt.pois.map(ot=>ot.position)]});if(i.surveyRadiusM!==void 0){let ot=Math.max(...[se.minX,se.maxX].flatMap(St=>[se.minY,se.maxY].map(qt=>Math.hypot(St,qt))));ot+1e3>i.surveyRadiusM&&Uo(ot+1e3),i.flags.port&&!Nt.pois.some(St=>St.kind==="boathouse")&&!i.waterContextResult.issues.some(St=>St.code==="water-context-conflict")&&i.waterContextResult.issues.push({code:"water-context-conflict"})}let Xt=q1(Cr,se),oo=Le.filter(ot=>Ot(ot.id)).length-Xt.filter(ot=>Ot(ot.id)).length;return oo>0&&a.push(`apron: ${oo} approach road${oo===1?"":"s"} started outside the drawn tile and was dropped`),{site:i,green:u,lanes:Xt,lots:or,buildings:$t.buildings,edgeStyle:Nt.edgeStyle,crofts:Nt.crofts,fields:Nt.fields,fieldEdges:Nt.fieldEdges,vegetation:Nt.vegetation,pois:Nt.pois,diagnostics:a,...Nt.wall?{wall:Nt.wall}:{},contractRadiusM:x.contractRadiusM,frame:se,trunkJunctions:x.junctions.filter(ot=>ot.position.x>=se.minX&&ot.position.x<=se.maxX&&ot.position.y>=se.minY&&ot.position.y<=se.maxY),greenRelation:P,bridges:ud(Xt,i.water)}}function Xc(e,t){let r=Be(t),o=1/0;for(let i=1;i<t.points.length;i++){let a=st(e.front,t.points[i-1],t.points[i]);o=Math.min(o,A(e.front,a))}return Math.abs(o-r)<_s}function Na(e){let t=new Map;for(let r of e){if(r.points.length<2)continue;let o=Qt(r).surfaceM,i=p=>{let f=e.filter(m=>m.id!==r.id&&m.points.slice(1).some((v,L)=>A(p,st(p,m.points[L],v))<.15));return f.length?Math.min(o,Math.max(...f.map(m=>Qt(m).surfaceM))):o},a=i(r.points[0]),s=i(r.points.at(-1));if(a>=o&&s>=o)continue;let n=gt(r.points),l=n.at(-1),d=Math.min(l/3,Math.max(3,o*2));if(d<=0)continue;let h=p=>(p=Math.min(1,Math.max(0,p)),p*p*(3-2*p)),c=[];for(let p=1;p<r.points.length;p++){let f=r.points[p-1],m=r.points[p],v=A(f,m),L=Math.max(1,Math.ceil(v/1.5));for(let w=0;w<L;w++)c.push(new Z(f.x+(m.x-f.x)*w/L,f.y+(m.y-f.y)*w/L))}c.push(r.points.at(-1));let k=p=>Ze(c,o/2+.02,p).map(f=>{let m=r.points[0],v=0,L=1/0;for(let x=1;x<r.points.length;x++){let b=st(f,r.points[x-1],r.points[x]),u=A(f,b);u<L&&(m=b,L=u,v=n[x-1]+A(b,r.points[x-1]))}let M=(Math.min(a+(o-a)*h(v/d),s+(o-s)*h((l-v)/d))/2+.02)/(o/2+.02);return new Z(m.x+(f.x-m.x)*M,m.y+(f.y-m.y)*M)});t.set(r.id,[...k(1),...k(-1).reverse()])}return t}var Da=[2.6,3.6],Td=.6;function at(e){return(Math.round(e*100)/100).toString()}function Fa(e,t){return`<g id="${e}">${t}</g>`}function Ga(e,t,r){return`${e.map((o,i)=>`${i===0?"M":"L"}${at(t(o.x))},${at(r(o.y))}`).join(" ")} Z`}function Hd(e){return(Math.round(e/Ns)*Ns%360+360)%360}function Od(e,t){return`pat-${e}-r${Hd(t)}`}function zd(e,t=4,r,o={}){let i=o.skin?Vi(o.skin,o.skinBiome??e.site.biome):void 0,a=i?.assets.glyphs??Ke;r=r??i?.village??mr(e.site.biome);let s=[...e.fieldEdges],{minX:n,minY:l}=e.frame,d=(e.frame.maxX-n)*t,h=(e.frame.maxY-l)*t,c=O=>(O-n)*t,k=O=>(O-l)*t,p=[...e.buildings.map(O=>({id:O.id,glyph:O.glyph,position:O.position,bearingDeg:O.bearingDeg,footprint:O.footprint,kind:"building"})),...e.pois.map(O=>({id:O.id,glyph:O.glyph,position:O.position,bearingDeg:O.bearingDeg,footprint:re(O.glyph),kind:"poi"}))],f=Array.from(new Set(p.map(O=>O.glyph))),m=Array.from(new Set(s.map(O=>O.glyph))),v=Array.from(new Set(e.fields.map(O=>O.glyph))),L=Array.from(new Set(e.vegetation.map(O=>O.glyph))),w=Array.from(new Set([...f,...m,...v,...L])),M=Array.from(new Set([...f,...L])),x=`${e.green.shape}-${e.green.variant}`,b=ce(x)&&Object.prototype.hasOwnProperty.call(a,x),u=[];for(let O of w){let Y=a[O];Y&&(u.push(Fa(O,Y.body)),M.includes(O)&&Y.sil&&u.push(Fa(`${O}-sil`,Y.sil)))}if(b)if(i?.overrides.has(x))u.push(Fa(x,a[x].body));else{let O=Ke[x].body.match(/<path[^>]* d="([^"]+)"/)?.[1];O&&u.push(Fa(x,Br(O,e.site.biome,{id:x,seed:"abc".indexOf(e.green.variant)})))}let P=new Set,C=[],Q=16*t;for(let O of e.fields){if(!a[O.glyph])continue;let Y=Od(O.glyph,O.furrowBearingDeg);if(P.has(Y))continue;P.add(Y);let rt=Q/_t[O.glyph].viewBox[2];C.push(`<pattern id="${Y}" patternUnits="userSpaceOnUse" width="${at(Q)}" height="${at(Q)}" patternTransform="rotate(${at(Hd(O.furrowBearingDeg))})"><use href="#${O.glyph}" transform="scale(${at(rt)})"/></pattern>`)}let R=[];R.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${at(d)}" height="${at(h)}" viewBox="0 0 ${at(d)} ${at(h)}" data-contract-radius="${at(e.contractRadiusM)}" data-origin-x="${at(c(0))}" data-origin-y="${at(k(0))}" data-px-per-metre="${at(t)}">`),R.push(`<style>${Ii(r.tokens)}</style>`),R.push(`<defs>${u.join("")}${C.join("")}</defs>`),R.push(`<rect data-bg="paper" width="${at(d)}" height="${at(h)}" fill="${r.ground}"/>`);let V=e.site.water.filter(O=>O.length>=3);if(V.length>0){R.push(`<defs><clipPath id="v-water-clip"><rect width="${at(d)}" height="${at(h)}"/></clipPath></defs>`),R.push('<g data-band="water" clip-path="url(#v-water-clip)">');let O=Y5(e.site.water);if(O){R.push(`<path data-water="union" d="${O.map(rt=>Ga(rt,c,k)).join(" ")}" fill="${r.water}" fill-rule="evenodd" stroke="none"/>`);let Y=Pr(e.site.water).map(rt=>rt.map((yt,B)=>`${B?"L":"M"}${at(c(yt.x))},${at(k(yt.y))}`).join(" ")).join(" ");R.push(`<path data-shore="union" d="${Y}" fill="none" stroke="${r.waterEdge}" stroke-width="${at(Td*t)}" stroke-linejoin="round"/>`)}else V.forEach((Y,rt)=>{R.push(`<path data-water="w${rt}" d="${Ga(Y,c,k)}" fill="${r.water}" stroke="${r.waterEdge}" stroke-width="${at(Td*t)}" stroke-linejoin="round"/>`)});R.push("</g>")}let j=e.pois.flatMap(O=>O.jetty?[O.jetty]:[]);if(j.length>0){R.push('<g data-band="jetty">');for(let O of j){let Y=O.to.x-O.from.x,rt=O.to.y-O.from.y,yt=Math.hypot(Y,rt)||1,B=Y/yt,$=-(rt/yt)*O.widthM/2,J=B*O.widthM/2,lt=[[O.from.x+$,O.from.y+J],[O.to.x+$,O.to.y+J],[O.to.x-$,O.to.y-J],[O.from.x-$,O.from.y-J]].map(([ae,Pe],Zt)=>`${Zt===0?"M":"L"}${at(c(ae))},${at(k(Pe))}`).join(" ");R.push(`<path data-jetty="deck" d="${lt} Z" fill="var(--sm-timber, #d9c39a)" stroke="var(--sm-ink, #33262e)" stroke-width="${at(.25*t)}" stroke-linejoin="round"/>`);let xt=Math.max(2,Math.floor(yt/1.2)),zt=[];for(let ae=1;ae<xt;ae++){let Pe=ae/xt,Zt=O.from.x+Y*Pe,$t=O.from.y+rt*Pe;zt.push(`M${at(c(Zt+$))},${at(k($t+J))} L${at(c(Zt-$))},${at(k($t-J))}`)}zt.length>0&&R.push(`<path data-jetty="planks" d="${zt.join(" ")}" fill="none" stroke="var(--sm-ink, #33262e)" stroke-width="${at(.12*t)}" stroke-linecap="round" opacity="0.55"/>`)}R.push("</g>")}R.push('<g data-band="parcel-fields">');for(let O of e.fields){if(!a[O.glyph])continue;let Y=Od(O.glyph,O.furrowBearingDeg);R.push(`<path data-field="${O.id}" d="${Ga(O.polygon,c,k)}" fill="url(#${Y})" stroke="none"/>`),R.push(Pa(O.polygon.map(rt=>({x:c(rt.x),y:k(rt.y)})),O.glyph,t,O.id))}for(let O of s){if(!a[O.glyph])continue;let rt=re(O.glyph)[0]*t/64;R.push(`<use data-edge="${O.id}" href="#${O.glyph}" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) rotate(${at(O.bearingDeg)}) scale(${at(rt)}) translate(-32,-32)"/>`)}R.push("</g>");let F=V.map(O=>Ga(O,c,k)),H=`road-land-${(F.join("").split("").reduce((O,Y)=>Math.imul(O,31)+Y.charCodeAt(0)|0,0)>>>0).toString(36)}`;F.length&&R.push(`<defs><mask id="${H}" maskUnits="userSpaceOnUse" x="0" y="0" width="${at(d)}" height="${at(h)}"><rect width="${at(d)}" height="${at(h)}" fill="white"/>${F.map(O=>`<path d="${O}" fill="black"/>`).join("")}</mask></defs>`),R.push(`<g data-band="route" ${F.length?`mask="url(#${H})" `:""}fill="none" stroke="#8a6f4a" stroke-linecap="round" stroke-linejoin="round">`);let X=Na(e.lanes),nt=[...e.lanes].sort((O,Y)=>Y.widthM-O.widthM||O.id.localeCompare(Y.id));for(let[O,Y]of nt.entries()){let rt=X.get(Y.id),yt=rt?.map(J=>`${at(c(J.x))},${at(k(J.y))}`).join(" ")??"",B=[...yt].reduce((J,lt)=>Math.imul(J,31)+lt.charCodeAt(0)|0,0)>>>0,U=`road-surface-${O}-${B.toString(36)}`;rt&&R.push(`<defs><clipPath id="${U}"><polygon points="${yt}"/></clipPath></defs>`);let $=Y.points.map((J,lt)=>`${lt===0?"M":"L"}${at(c(J.x))},${at(k(J.y))}`).join(" ");R.push(`<path data-lane="${Y.id}" d="${$}" ${rt?`clip-path="url(#${U})" `:""}stroke-width="${at(Qt(Y).surfaceM*t)}"/>`)}if(R.push("</g>"),e.bridges.some(O=>O.narrow&&O.deck&&O.centreline)){R.push('<g data-band="bridge" fill="#c3aa80" stroke="#594e40" stroke-linejoin="round">');for(let O of e.bridges){if(!O.narrow||!O.deck||!O.centreline)continue;let Y=e.lanes.find(rt=>rt.id===O.laneId);R.push(`<g data-bridge="${O.id}">${Za(O.centreline.map(rt=>({x:c(rt.x),y:k(rt.y)})),(Qt(Y).surfaceM+.7)*t,e.site.biome,Y.type==="main")}</g>`)}R.push("</g>")}R.push('<g data-band="parcel">');let mt=e.green.diameter/2*t;if(e.green.outline&&e.green.shape==="sm-green-triangle"){let O=e.green.outline.map(B=>({x:c(B.x),y:k(B.y)})),Y=O.map(B=>B.x),rt=O.map(B=>B.y),yt=O.map((B,U)=>`${U?"L":"M"}${at(B.x)},${at(B.y)}`).join(" ")+"Z";R.push(`<g data-green="junction">${Br(yt,e.site.biome,{unit:t*.6,id:"junction",bounds:[Math.min(...Y),Math.min(...rt),Math.max(...Y)-Math.min(...Y),Math.max(...rt)-Math.min(...rt)]})}</g>`)}else b&&R.push(`<use href="#${x}" transform="translate(${at(c(e.green.centre.x))},${at(k(e.green.centre.y))}) rotate(${at(e.green.bearingDeg-(e.green.shape.includes("lens")?90:0))}) scale(${at(mt*2/64)}) translate(-32,-32)"/>`);R.push("</g>"),R.push('<g data-band="structure">'),R.push(`<g transform="translate(${at(Da[0])},${at(Da[1])})" opacity="${r.shadowOpacity}" color="${r.shadowColor}">`);for(let O of p){if(!a[O.glyph]?.sil)continue;let Y=O.footprint[0]*t/64;R.push(`<use data-shadow="1" data-kind="${O.kind}" href="#${O.glyph}-sil" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) rotate(${at(O.bearingDeg)}) scale(${at(Y)}) translate(-32,-32)"/>`)}R.push("</g>");for(let O of p){if(!a[O.glyph])continue;let Y=O.footprint[0]*t/64;R.push(`<use data-ink="1" data-kind="${O.kind}" data-id="${O.id}" href="#${O.glyph}" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) rotate(${at(O.bearingDeg)}) scale(${at(Y)}) translate(-32,-32)"/>`)}R.push("</g>"),e.wall&&R.push(`<g data-band="walls" transform="translate(${at(c(0))},${at(k(0))}) scale(${at(t)})">${xa(e.wall,e.site.biome)}</g>`),R.push('<g data-band="canopy">'),R.push(`<g transform="translate(${at(Da[0])},${at(Da[1])})" opacity="${r.shadowOpacity}" color="${r.shadowColor}">`);for(let O of e.vegetation){if(!a[O.glyph]?.sil)continue;let rt=re(O.glyph)[0]*t/64*(O.scale??1);R.push(`<use data-shadow="1" data-kind="tree" href="#${O.glyph}-sil" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) scale(${at(rt)}) translate(-32,-32)"/>`)}R.push("</g>");for(let O of e.vegetation){if(!a[O.glyph])continue;let rt=re(O.glyph)[0]*t/64*(O.scale??1);R.push(`<use data-ink="1" data-kind="tree" data-id="${O.id}" href="#${O.glyph}" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) scale(${at(rt)}) translate(-32,-32)"/>`)}return R.push("</g>"),R.push("</svg>"),Ai(R.join(`
|
|
585
|
+
`),X)}function k2(e,t={}){let r=s2(e,{shift:t.shift??kr,padding:t.padding??20});return h2(r,{skin:t.skin,skinBiome:t.skinBiome,assetSet:t.assetSet,palette:t.palette,theme:t.theme,clipId:t.clipId,symbols:t.symbols})}var N5=new Set(["pier","well","market","mill"]);var vi=4,wi="3.0.1";function er(e,t){return ga(e.x,e.y,t)}function c2(e,t={}){let r=[],o=new Fr,i=wo(e),a=t.shift??kr;for(let n of e.patches)if(n.ward){r.push({type:"Feature",properties:{layer:"ward",wardType:n.ward.type,label:n.ward.getLabel(),withinCity:n.withinCity,withinWalls:n.withinWalls},geometry:mi(n.shape,a)});for(let l of n.ward.geometry){let d=i.get(l);r.push({type:"Feature",properties:{layer:"building",wardType:n.ward.type,building_id:d},geometry:mi(l,a)})}if(n.ward instanceof Rt)for(let l of n.ward.gardens)r.push({type:"Feature",properties:{layer:"green",kind:"garden",wardType:n.ward.type},geometry:mi(l.ring,a)});if(n.ward instanceof Me)for(let l of n.ward.piers)r.push({type:"Feature",properties:{layer:"pier",wardType:n.ward.type},geometry:mi(l,a)})}for(let n of e.arteries)r.push({type:"Feature",properties:{layer:"street",streetType:"artery",street_id:o.alloc("s")},geometry:{type:"LineString",coordinates:n.vertices.map(l=>er(l,a))}});for(let n of e.roads)r.push({type:"Feature",properties:{layer:"street",streetType:"road",street_id:o.alloc("s")},geometry:{type:"LineString",coordinates:n.vertices.map(l=>er(l,a))}});for(let n of e.patches){for(let l of n.ward?.lanes??[])r.push({type:"Feature",properties:{layer:"street",streetType:"alley",width:l.width,street_id:o.alloc("s")},geometry:{type:"LineString",coordinates:[er(l.a,a),er(l.b,a)]}});if(n.ward instanceof Ge&&n.ward.geometry.length)for(let l of n.ward.paths)r.push({type:"Feature",properties:{layer:"street",streetType:"park",width:n.ward.pathWidth,street_id:o.alloc("s")},geometry:{type:"LineString",coordinates:l.map(d=>er(d,a))}})}e.wall!==null&&D5(r,e.wall,"city_wall",a),e.citadel!==null&&e.citadel.ward instanceof Xe&&D5(r,e.citadel.ward.wall,"citadel_wall",a),sk(r,e,a);let s=ra(e,e.params.population,o,i);for(let n of s){if(n.buildingId===null&&!N5.has(n.kind))throw new Error(`POI kind ${n.kind} emitted without a building_id \u2014 selector bug`);let l={layer:"poi",poi_id:o.alloc("p"),kind:n.kind,ward_type:n.wardType,building_id:n.buildingId};r.push({type:"Feature",properties:l,geometry:{type:"Point",coordinates:er(n.point,a)}})}return{type:"FeatureCollection",features:r,metadata:ok(e,e.params,t,a)}}function ok(e,t,r,o){let i=xo(t.population).diameterMeters,a=va(e);return{...t.population>1e3?{building_capacity:e.getBuildingCapacity()}:{},schema_version:vi,settlemaker_version:r.settlemakerVersion??wi,settlement_generation_version:ik(t,o),coordinate_system:"local_origin_y_down",coordinate_units:"settlement_units",generated_at:r.generatedAt??new Date().toISOString(),local_bounds:qr(e,r.padding??20,o),scale:{meters_per_unit:i/a,diameter_meters:i,diameter_local:a,source:"population_heuristic_v1"},stable_ids:{prefixes:{entrance:"g",poi:"p",street:"s",building:"b"}},poi_density:ei(t.population),degraded_flags:[...e.degradedFlags].sort(),local_origin_shift:o}}function ik(e,t){let r={schema:vi,settlemakerVersion:wi,seed:e.seed,population:e.population,nPatches:e.nPatches,urbanDensity:e.urbanDensity??null,walls:e.wallsNeeded,citadel:e.citadelNeeded,plaza:e.plazaNeeded,temple:e.templeNeeded,shanty:e.shantyNeeded,capital:e.capitalNeeded,oceanBearing:e.oceanBearing??null,harbourSize:e.harbourSize??null,roadBearings:e.roadEntryPoints?.map(o=>({b:Math.round(o.bearingDeg*10)/10,r:o.routeId??null,k:o.kind??null}))??null,coastlineGeometry:e.coastlineGeometry?.map(o=>o.map(i=>[Math.round(i.x*100)/100,Math.round(i.y*100)/100]))??null,originShift:{dx:Math.round(t.dx*100)/100,dy:Math.round(t.dy*100)/100,source:t.source}};return ak(JSON.stringify(r)).toString(36)}function ak(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t+e.charCodeAt(r)&2147483647;return t||1}function sk(e,t,r){if(t.border===null)return;let o=t.border,i=va(t);for(let a of t.gates){let s=o.gateMeta.get(a);s&&e.push(nk(a,s,o,t,i,r))}}function nk(e,t,r,o,i,a){let s=t.kind==="sea"||lk(e,o),n=s?"harbour":"land",l=s?"harbour":t.kind==="foot"?"foot":"road",d=`g${t.wallVertexIndex}`,h=dk(e,r),c=Math.hypot(e.x,e.y),k=Math.min(3,.05*i),p=c>0?(c-k)/c:0,f=[Math.round(e.x*p*100)/100,Math.round(e.y*p*100)/100],m=er({x:f[0],y:f[1]},a),v={layer:"entrance",entrance_id:d,kind:n,sub_kind:l,wall_vertex_index:t.wallVertexIndex,bearing_deg:t.bearingDeg,arrival_local:m};t.routeId!=null&&(v.matched_route_id=t.routeId),t.matchDeltaDeg!=null&&(v.bearing_match_delta_deg=t.matchDeltaDeg);let L=t.routes.map(w=>w.routeId).filter(w=>w!=null);return L.length>0&&(v.matched_route_ids=L),t.routes.length>0&&(v.matched_routes=t.routes.map(w=>{let M={requested_bearing_deg:Math.round(w.requestedBearingDeg*10)/10,match_delta_deg:w.matchDeltaDeg};return w.routeId!=null&&(M.route_id=w.routeId),w.kind!=null&&(M.kind=w.kind),M})),h.prev!=null&&(v.prev_entrance_id=h.prev),h.next!=null&&(v.next_entrance_id=h.next),{type:"Feature",properties:v,geometry:{type:"Point",coordinates:er(e,a)}}}function lk(e,t){return t.harbour===null?!1:t.harbour.shape.contains(e)}function dk(e,t){let r=t.shape.vertices,o=r.length,i=r.indexOf(e);if(i===-1)return{};let a=new Set(t.gateMeta.keys()),s=n=>{for(let l=1;l<o;l++){let d=r[((i+n*l)%o+o)%o];if(d!==e&&a.has(d))return`g${t.gateMeta.get(d).wallVertexIndex}`}};return{next:s(1),prev:s(-1)}}function D5(e,t,r,o){e.push({type:"Feature",properties:{layer:"wall",wallType:r},geometry:mi(t.shape,o)});for(let i of t.towers)e.push({type:"Feature",properties:{layer:"tower",wallType:r},geometry:{type:"Point",coordinates:er(i,o)}})}function mi(e,t){let r=e.vertices.map(o=>er(o,t));return r.length>0&&r.push([r[0][0],r[0][1]]),{type:"Polygon",coordinates:[r]}}var Sa=1,ge=class extends Error{constructor(r,o){super(o);this.reason=r;this.name="UrlCodecError"}};async function F5(e,t){let r=new Blob([e]).stream().pipeThrough(t);return new Uint8Array(await new Response(r).arrayBuffer())}function hk(e){let t="";for(let r of e)t+=String.fromCharCode(r);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function kk(e){let t=e.replace(/-/g,"+").replace(/_/g,"/"),r;try{r=atob(t)}catch{throw new ge("base64","parameter is not valid base64url")}let o=new Uint8Array(r.length);for(let i=0;i<r.length;i++)o[i]=r.charCodeAt(i);return o}async function G5(e){let t=new TextEncoder().encode(JSON.stringify(e));return hk(await F5(t,new CompressionStream("deflate-raw")))}async function Ca(e){let t=kk(e),r;try{r=await F5(t,new DecompressionStream("deflate-raw"))}catch{throw new ge("inflate","parameter is not valid deflate-raw data")}try{return JSON.parse(new TextDecoder().decode(r))}catch{throw new ge("json","decompressed payload is not valid JSON")}}async function ck(e,t){return G5({v:Sa,burg:e,...t!==void 0?{seed:t}:{}})}async function p2(e){let t=await Ca(e);if(typeof t!="object"||t===null)throw new ge("shape","payload is not an object");let r=t;if(r.v!==Sa)throw new ge("version",`unsupported payload version ${String(r.v)} (expected ${Sa})`);let o=r.burg;if(typeof o!="object"||o===null||typeof o.name!="string"||typeof o.population!="number")throw new ge("shape","payload has no plausible burg (name + population required)");return Ar(o),{burg:o,...typeof r.seed=="number"?{seed:r.seed}:{}}}var pk=/^#[0-9a-fA-F]{3,8}$/,fk=["paper","fieldFill","fieldFurrow","greenFill","treeFill","roadCasing","roadCore","buildingFill","buildingStroke","landmarkFill","shadowColor","smInk","smStone","smTimber","smVoid","smCanopy1","smCanopy2"],mk=["water","waterEdge"],vk=["shadowOpacity","arteryWidth","roadWidth","casingDelta","seamStroke","shoreWidth"];function W5(e){return typeof e=="string"&&pk.test(e)}function f2(e){return typeof e=="number"&&Number.isFinite(e)}function wk(e){let t={};if(e===null||typeof e!="object")return t;let r=e;for(let i of fk){let a=r[i];W5(a)&&(t[i]=a)}for(let i of mk){let a=r[i];(a===null||W5(a))&&(t[i]=a===null?null:a)}for(let i of vk){let a=r[i];f2(a)&&(t[i]=a)}let o=r.shadowOffset;if(o!==null&&typeof o=="object"){let{dx:i,dy:a}=o;f2(i)&&f2(a)&&(t.shadowOffset={dx:i,dy:a})}return t}var Lk=["name","pop","seed","port","citadel","walls","plaza","temple","shanty","capital","trade","oceanBearing","harbourSize","biome","urbanDensity","coreCapacity","roads"];function yk(e){return e<0||e>=360?(e%360+360)%360:e}function Mk(e){let t=[];for(let r of e.split(",")){let o=r.trim();if(o==="")continue;let[i,a,s]=o.split(":").map(d=>d.trim()),n=Number(i);if(!Number.isFinite(n))throw new ge("roads",`roads="${o}" \u2014 bearing must be a number, e.g. roads=45 or roads=45:main:through`);let l=a===void 0||a===""?"main":a;if(!Ye.includes(l))throw new ge("roads",`roads="${o}" \u2014 unknown class "${l}"; known classes: ${Ye.join(", ")}`);if(s!==void 0&&s!==""&&s!=="through")throw new ge("roads",`roads="${o}" \u2014 third field may only be "through"`);t.push({bearing_deg:yk(n),kind:l,through:s==="through"})}return t}function Zr(e,t){let r=e.get(t);return r==="1"||r==="true"}function Kr(e,t){let r=e.get(t);if(r===null||r==="")return;let o=Number(r);return Number.isFinite(o)?o:void 0}function uk(e){let t=200+Math.abs(e)%4800;return{name:`Burg ${Math.abs(e)%1e4}`,population:t,port:!1,citadel:t>3500,walls:t>1500,plaza:t>800,temple:t>2e3,shanty:!1,capital:!1}}async function gk(e,t={}){let r,o,i=!1,a=e.get("i");if(a!==null){let h=await p2(a);r=h.burg,o=h.seed}else if(Lk.some(h=>e.has(h))){let h=e.get("name")??`Burg ${Kr(e,"seed")??Kr(e,"pop")??0}`,c=e.get("roads"),k=e.get("harbourSize"),p=Kr(e,"urbanDensity"),f=Kr(e,"coreCapacity"),m=Kr(e,"oceanBearing");r={name:h,population:Kr(e,"pop")??300,port:Zr(e,"port"),citadel:Zr(e,"citadel"),walls:Zr(e,"walls"),plaza:Zr(e,"plaza"),temple:Zr(e,"temple"),shanty:Zr(e,"shanty"),capital:Zr(e,"capital"),...Zr(e,"trade")?{trade:!0}:{},...m!==void 0?{oceanBearing:m}:{},...k==="large"||k==="small"?{harbourSize:k}:{},...e.get("biome")!==null?{biome:e.get("biome")}:{},...c!==null?{roadBearings:Mk(c)}:{},...p!==void 0&&p>0?{urbanDensity:p}:{},...f!==void 0&&f>0?{coreCapacity:f}:{}},o=Kr(e,"seed")}else{let h=(t.randomSeed??(()=>Math.floor(Math.random()*2147483648)))();r=uk(h),o=h,i=!0}let s=e.get("style"),n=s!==null?wk(await Ca(s)):void 0,l=e.get("theme")??void 0,d=e.get("villageTheme")??void 0;if(d!==void 0&&!Qr.includes(d))throw new ge("villageTheme",`villageTheme="${d}" \u2014 known village themes: ${Qr.join(", ")}`);return{burg:r,...o!==void 0?{seedOverride:o}:{},...l!==void 0?{paletteName:l}:{},...n!==void 0?{themeOverrides:n}:{},...d!==void 0?{villageThemeName:d}:{},random:i}}var U5=q2(w2(),1);var So=new WeakMap,q5=new WeakMap,bk=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y)<1e-7;function K5(e,t){let r;try{let n=e.map(l=>[l.map(d=>[d.x,d.y])]);r=n.length?U5.default.union(n[0],...n.slice(1)):[]}catch{throw new je("water-context-invalid","Water polygon union could not be constructed.")}let o=r.map(n=>n.map(l=>l.map(([d,h])=>new Z(d,h)))),i=o.flat(),a=[],s=(n,l)=>[n.x,n.y].some((d,h)=>Math.abs(Math.abs(d)-t)<1e-6&&Math.abs(d-(h===0?l.x:l.y))<1e-6);for(let n of i){let l=n.length-1,d=n.slice(0,-1).findIndex((c,k)=>s(c,n[k+1]));if(d<0){a.push(n);continue}let h=[];for(let c=1;c<=l;c++){let k=(d+c)%l,p=n[k],f=n[k+1];s(p,f)?(h.length>1&&a.push(h),h=[]):(h.length||h.push(p),h.push(f))}h.length>1&&a.push(h)}for(let n of e)q5.set(n,t);So.set(e,{radius:t,paths:a,rings:i,polygons:o,segments:a.flatMap(n=>n.slice(1).map((l,d)=>[n[d],l]))})}function Pr(e){return So.get(e)?.paths??e.filter(t=>t.length>1).map(t=>bk(t[0],t.at(-1))?t:[...t,t[0]])}function be(e){return So.get(e)?.segments??Pr(e).flatMap(t=>t.slice(1).map((r,o)=>[t[o],r]))}function Y5(e){return So.get(e)?.rings}function Tt(e,t,r=0){let o=So.get(e);o&&Math.hypot(t.x,t.y)+r>o.radius+1e-7&&Uo(Math.hypot(t.x,t.y)+r)}function X5(e,t,r){let o=q5.get(e);o!==void 0&&Math.hypot(t.x,t.y)+r>o&&Uo(Math.hypot(t.x,t.y)+r)}function J5(e){return So.get(e)?.polygons}function fe(e){return(e%360+360)%360}function Lt(e){let t=e*Math.PI/180;return new Z(Math.sin(t),-Math.cos(t))}function pt(e,t){return fe(Math.atan2(t.x-e.x,-(t.y-e.y))*180/Math.PI)}function Qe(e,t){return Math.abs((fe(e)-fe(t)+540)%360-180)}function Ba(e,t){return(fe(t)-fe(e)+540)%360-180}function We(e,t){let r=Math.hypot(e,t);return r===0?new Z(0,0):new Z(e/r,t/r)}function A(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function Gt(e){let t=0;for(let r=1;r<e.length;r++)t+=A(e[r],e[r-1]);return t}function gt(e){let t=[0];for(let r=1;r<e.length;r++)t.push(t[r-1]+A(e[r],e[r-1]));return t}function ut(e,t,r){let o=t[t.length-1],i=Math.min(Math.max(r,0),o),a=1;for(;a<t.length-1&&t[a]<i;)a++;let s=t[a]-t[a-1]||1,n=(i-t[a-1])/s,l=e[a-1],d=e[a];return{p:new Z(l.x+(d.x-l.x)*n,l.y+(d.y-l.y)*n),dirDeg:pt(l,d)}}function kt(e,t){return Tt(t,e),t.some(r=>bt(e,r))}function st(e,t,r){let o=r.x-t.x,i=r.y-t.y,a=o*o+i*i;if(a===0)return new Z(t.x,t.y);let s=Math.max(0,Math.min(1,((e.x-t.x)*o+(e.y-t.y)*i)/a));return new Z(t.x+o*s,t.y+i*s)}function Yr(e,t){if(t.length===0)return{distance:1/0,point:e};if(t.length===1)return{distance:A(e,t[0]),point:t[0]};let r={distance:1/0,point:t[0]};for(let o=1;o<t.length;o++){let i=st(e,t[o-1],t[o]),a=A(e,i);a<r.distance&&(r={distance:a,point:i})}return r}function Ct(e){return e.diameter/2*Lo+gr}function Wt(e,t,r,o){let i=t.x-e.x,a=t.y-e.y,s=o.x-r.x,n=o.y-r.y,l=i*n-a*s;if(Math.abs(l)<1e-12)return null;let d=((r.x-e.x)*n-(r.y-e.y)*s)/l,h=((r.x-e.x)*a-(r.y-e.y)*i)/l,c=1e-6;return d<=c||d>=1-c||h<=c||h>=1-c?null:new Z(e.x+i*d,e.y+a*d)}function t1(e,t){let r=i=>i.x>=t.minX&&i.x<=t.maxX&&i.y>=t.minY&&i.y<=t.maxY;if(e.length===0||!r(e[0]))return[];let o=[e[0]];for(let i=1;i<e.length;i++){let a=e[i-1],s=e[i];if(r(s)){o.push(s);continue}let n=1,l=(d,h)=>{if(h===0)return;let c=d/h;c>=0&&c<n&&(n=c)};return l(t.minX-a.x,s.x-a.x),l(t.maxX-a.x,s.x-a.x),l(t.minY-a.y,s.y-a.y),l(t.maxY-a.y,s.y-a.y),o.push(new Z(a.x+(s.x-a.x)*n,a.y+(s.y-a.y)*n)),o}return o}function e1(e){let t=(Math.round(e)%360+360)%360;return String(t).padStart(3,"0")}function y2(e){return`arm-${e1(e)}`}function Li(e){return`lane-${e1(e)}`}function yi(e,t){let r=String(Math.round(t*100)).padStart(2,"0");return`${e}/b${r}`}function M2(e,t="outer"){return`${e}/a${t==="inner"?"0":""}`}function Ot(e){return/\/a\d*(~|$)/.test(e)}function Ea(e,t,r){return`${e}:${t===1?"R":"L"}${r}`}var L2="+r";function r1(e,t,r,o){return`${Ea(e,t,r)}${L2}${o}`}var xk=1e3;function Mi(e){let t=e.lastIndexOf(L2);if(t<0){let i=/(\d+)$/.exec(e);return i?parseInt(i[1],10):0}let r=parseInt(e.slice(t+L2.length),10)||0,o=/(\d+)$/.exec(e.slice(0,t));return r*xk+(o?parseInt(o[1],10):0)}function _a(e){return`bld:${e}`}function Co(e,t){return e??String(Math.round(t*100)/100)}function Ra(e,t,r,o){let i=t?t.replace(/\//g,"_"):Co(t,r);return`trunk-${e}-${i}${o?"~far":""}`}var Zk=.12,Pk=6,Sk=70;function u2(e,t,r){return A(t,r)<.05||Qe(pt(e,t),pt(t,r))<=Sk}function Ck(e,t,r){let o=[e],i=(a,s,n,l)=>{let d=new Z((a.x+2*s.x+n.x)/4,(a.y+2*s.y+n.y)/4);if(l>=7||A(d,st(d,a,n))<=Zk){o.push(n);return}let h=new Z((a.x+s.x)/2,(a.y+s.y)/2),c=new Z((s.x+n.x)/2,(s.y+n.y)/2);i(a,h,d,l+1),i(d,c,n,l+1)};return i(e,t,r,0),o}function Xr(e,t=[]){if(e.length<3)return e;let r=[e[0]];for(let o=1;o<e.length-1;o++){let i=e[o-1],a=e[o],s=e[o+1],n=A(i,a),l=A(a,s);if(n<.01||l<.01)continue;let d=Qe(pt(i,a),pt(a,s));if(d>120)return null;let h=t.some(f=>f.points.slice(1).some((m,v)=>A(a,st(a,f.points[v],m))<.05));if(d<4||h){r.push(a);continue}let c=Math.min(Pk,n*.4,l*.4),k=new Z(a.x+(i.x-a.x)*c/n,a.y+(i.y-a.y)*c/n),p=new Z(a.x+(s.x-a.x)*c/l,a.y+(s.y-a.y)*c/l);r.push(...Ck(k,a,p))}return r.push(e[e.length-1]),r.filter((o,i)=>i===0||A(o,r[i-1])>1e-6)}function xe(e,t){for(let a of e)Tt(t,a);if(!t.length)return[];let r=[],o,i=0;for(let a=1;a<e.length;a++){let s=e[a-1],n=e[a],l=A(s,n);if(l<1e-8)continue;let d=[0,1],h=n.x-s.x,c=n.y-s.y;for(let p of t)for(let f=0;f<p.length;f++){let m=p[f],v=p[(f+1)%p.length],L=v.x-m.x,w=v.y-m.y,M=h*w-c*L;if(Math.abs(M)<1e-9)continue;let x=((m.x-s.x)*w-(m.y-s.y)*L)/M,b=((m.x-s.x)*c-(m.y-s.y)*h)/M;x>0&&x<1&&b>=0&&b<=1&&d.push(x)}d.sort((p,f)=>p-f);let k=p=>p===0?s:p===1?n:new Z(s.x+h*p,s.y+c*p);for(let p=1;p<d.length;p++){let f=d[p-1],m=d[p];m-f<1e-9||(kt(k((f+m)/2),t)?(o||(o={points:[k(f)],startM:i+f*l,endM:0},r.push(o)),o.points.push(k(m)),o.endM=i+m*l):o=void 0)}i+=l}return r}function Qa(e,t){let r=xe(e,t);if(!r.some(s=>s.endM-s.startM>10))return e;let o=e[0],i=e.at(-1);if(kt(o,t)||kt(i,t))return e;if(!xe([o,i],t).length)return[o,i];let a;for(let s of r){let n=gt(s.points),l=ut(s.points,n,n.at(-1)/2).p,d=be(t).map(([h,c])=>{let k=st(l,h,c);return{a:h,b:c,p:k,distance:A(l,k)}}).sort((h,c)=>h.distance-c.distance).slice(0,4);for(let{a:h,b:c,p:k}of d){let p=A(h,c);if(p<.1)continue;let f=(c.x-h.x)/p,m=(c.y-h.y)/p;for(let v of[0,-8,8,-16,16,-24,24]){let L=new Z(k.x+f*v,k.y+m*v),w=P=>new Z(L.x-m*P,L.y+f*P),M=xe([w(-20),w(20)],t);if(M.length!==1)continue;let x=M[0];if(x.endM-x.startM>10)continue;let b=w(x.startM-20-8),u=w(x.endM-20+8);for(let[P,C]of[[b,u],[u,b]]){if(xe([o,P],t).length||xe([C,i],t).length)continue;let Q=Xr([o,P,C,i]);if(!Q)continue;let R=xe(Q,t);if(R.length!==1||R[0].endM-R[0].startM>10)continue;let V=gt(Q).at(-1);(!a||V<a.length)&&(a={points:Q,length:V})}}}}return a?.points??e}function Jr(e,t,r=0){for(let s of e)Tt(t,s,r);if(!t.length)return!0;if(e.length<2||kt(e[0],t)||kt(e.at(-1),t))return!1;let o=xe(e,t);if(o.some(s=>s.endM-s.startM>10))return!1;if(!(r>0))return!0;let i=gt(e),a=i.at(-1);for(let s=0;s<=a;s+=2){if(o.some(l=>s>=l.startM-r-5&&s<=l.endM+r+5))continue;let n=ut(e,i,s).p;for(let[l,d]of be(t))if(!(n.x<Math.min(l.x,d.x)-r||n.x>Math.max(l.x,d.x)+r||n.y<Math.min(l.y,d.y)-r||n.y>Math.max(l.y,d.y)+r)&&A(n,st(n,l,d))<r)return!1}return!0}var g2=3;function b2(e,t,r){Tt(t,e,r);let o,i=r+1;for(let[a,s]of be(t)){if(e.x<Math.min(a.x,s.x)-r||e.x>Math.max(a.x,s.x)+r||e.y<Math.min(a.y,s.y)-r||e.y>Math.max(a.y,s.y)+r)continue;let n=st(e,a,s),l=A(e,n);l<i&&(i=l,o=n)}return!o||i>=r||i<1e-8||kt(e,t)?e:new Z(o.x+(e.x-o.x)*(r+.3)/i,o.y+(e.y-o.y)*(r+.3)/i)}function ui(e,t,r){if(e.length<2||!t.length)return e;if(kt(e[0],t)){let p=e.findIndex(f=>!kt(f,t));return p<0?e:[...e.slice(0,p),...ui(e.slice(p),t,r)]}if(kt(e.at(-1),t))return e;let o=e;for(let p of[...xe(o,t)].reverse()){if(p.endM-p.startM<=10)continue;let f=gt(o),m=f.at(-1),v=Math.max(0,p.startM-45),L=Math.min(m,p.endM+45),w=[ut(o,f,v).p,...o.filter((x,b)=>f[b]>v&&f[b]<L),ut(o,f,L).p],M=Qa(w,t);o=[...o.filter((x,b)=>f[b]<v),...M,...o.filter((x,b)=>f[b]>L)]}let i=gt(o),a=i.at(-1),s=xe(o,t),n=r+g2,l=Math.ceil(a/4),d=Array.from({length:l+1},(p,f)=>a*f/l),h=d.map(p=>ut(o,i,p).p),c=d.map((p,f)=>f===0||f===l||s.some(m=>p>=m.startM-n-4&&p<=m.endM+n+4)),k=h;for(let p=0;p<10;p++)k=k.map((f,m)=>{if(c[m])return f;let v=k[m-1],L=k[m+1],w=new Z((v.x+2*f.x+L.x)/4,(v.y+2*f.y+L.y)/4);return b2(kt(w,t)?f:w,t,n)});return k}function Bk(e){return Math.max(e*d5,h5)}function o1(e,t){return Math.atan2(t.x-e.x,-(t.y-e.y))*180/Math.PI}function Ek(e,t){let r=e.points;if(r.length<2||t<=0)return[];let o=r[r.length-1],i=o1(r[r.length-2],o),a=i,s=0;for(let p of e.id)s=Math.imul(s,31)+p.charCodeAt(0)|0;let n=(s>>>0)/4294967296*Math.PI*2,l=0;if(r.length>=3){let p=o1(r[r.length-3],r[r.length-2]),f=Ba(p,i)*k5;l=Math.max(-Ys,Math.min(Ys,f))}let d=[o.clone()],h=o,c=0,k=0;for(;c<t;){let p=Math.min(Ks,t-c);Math.abs(k)<c5&&(i+=l,k+=l);let f=Math.min(1,c/70),m=13*Math.sin(c*Math.PI*2/420+n)*f*f,L=(a+Math.max(-30,Math.min(30,i-a+m)))*Math.PI/180;h=new Z(h.x+Math.sin(L)*p,h.y-Math.cos(L)*p),d.push(h),c+=p}return d}var i1=8;function _k(e){return Math.max(e*p5,f5)}var Ia=1;function n1(e,t,r){for(let o=Ia;o<=uo;o+=Ia)if(!kt(new Z(e.x+t.x*o,e.y+t.y*o),r))return o>=br;return!0}function l1(e,t){let r=A(e,t);return r===0?null:new Z((t.x-e.x)/r,(t.y-e.y)/r)}function Rk(e,t){for(let r=1;r<e.length;r++){let o=e[r-1],i=e[r],a=l1(o,i);if(!a)continue;let s=[];for(let n of Pr(t))for(let l=0;l<n.length-1;l++){let d=Wt(o,i,n[l],n[(l+1)%n.length]);d&&s.push({point:d,ring:n,edge:l,d:A(o,d)})}s.sort((n,l)=>n.d-l.d||n.edge-l.edge);for(let n of s){let l=new Z(n.point.x+a.x*Ia,n.point.y+a.y*Ia);if(kt(l,t)&&n1(n.point,a,t))return{index:r,point:n.point,ring:n.ring,edge:n.edge}}}return null}function a1(e,t){Tt(t,e);let r=null,o=1/0;for(let i of Pr(t))for(let a=0;a<i.length-1;a++){let s=st(e,i[a],i[(a+1)%i.length]),n=A(e,s);n<o&&(o=n,r={index:1,point:s,ring:i,edge:a})}return r}var Qk=4;function Ik(e,t,r,o,i){let a=A(t[0],t.at(-1))<1e-7,s=a?t.length-1:t.length,n=c=>(c%s+s)%s,l=o===1?r+1:r,d=[e],h=0;for(let c=0;c<s&&h<i;c++){let k=l+o*c;if(!a&&(k<0||k>=s))break;let p=t[n(k)],f=A(d[d.length-1],p);f!==0&&(h+=f,d.push(p))}return d}function Ak(e,t){let r=[e[0]],o=0;for(let i=1;i<e.length;i++){let a=e[i-1],s=e[i],n=A(a,s);for(;n>0&&o+n>=t;){let l=(t-o)/n,d=new Z(a.x+(s.x-a.x)*l,a.y+(s.y-a.y)*l);r.push(d),a=d,n=A(a,s),o=0}o+=n}return r}function Tk(e){return e.length<3?e:e.map((t,r)=>{if(r===0||r===e.length-1)return t;let o=e[r-1],i=e[r+1];return new Z((o.x+t.x+i.x)/3,(o.y+t.y+i.y)/3)})}function Ok(e,t){let r=[];for(let o of e){if(r.length>=3){let i=r[r.length-1];for(let a=1;a<r.length-1;a++){let s=Wt(i,o,r[a-1],r[a]);if(s&&!kt(s,t)){r.length=a,r.push(s);break}}}r.push(o)}return r}var d1=4;function s1(e,t,r,o,i,a){let s=Tk(Ak(Ik(e,t,r,o,Xs*Qk),Ks)),n=[],l=0,d=0,h=!1,c=0;for(let k=0;k<s.length&&!h&&l<Xs;k++){let p=s[Math.max(k-1,0)],f=s[Math.min(k+1,s.length-1)],m=A(p,f);if(m===0)continue;let v=-(f.y-p.y)/m,L=(f.x-p.x)/m,w=(b,u)=>new Z(s[k].x+b*v*ma*u,s[k].y+b*L*ma*u),M=null;for(let b=1;b<=d1&&!M;b++){let u=c===0?[1,-1]:[c];for(let P of u){let C=w(P,b);if(!kt(C,i)&&!(n.length&&xe([n[n.length-1],C],i).length)){M=C,c=P;break}}}if(!M)continue;n.length>0&&(l+=A(n[n.length-1],M)),n.push(M);let x=Math.hypot(M.x,M.y);x>d&&(d=x),x>=a&&(h=!0)}return{points:n,runM:l,escaped:h,furthestM:d}}function Hk(e,t){if(e.points.length===0!=(t.points.length===0))return e.points.length>0?e:t;if(e.escaped!==t.escaped)return e.escaped?e:t;if(e.escaped&&e.runM!==t.runM)return e.runM<t.runM?e:t;if(!e.escaped&&e.furthestM!==t.furthestM)return e.furthestM>t.furthestM?e:t;let r=e.points[e.points.length-1],o=t.points[t.points.length-1];return!r||!o?e:r.x!==o.x?r.x<o.x?e:t:r.y<=o.y?e:t}function zk(e,t){for(let r=1;r<e.length;r++){if(!kt(e[r],t))continue;let o=l1(e[r-1],e[r]);if(!(!o||!n1(e[r],o,t)))return r}return null}function Vk(e,t,r,o){let i=kt(t[0],r),a=i?a1(t[0],r):Rk(t,r);if(!a&&!i){let k=zk(t,r);if(k!==null){let p=a1(t[k-1],r);if(a=p?{...p,index:k}:null,!a)return{points:t.slice(0,k),diagnostics:[`coast: ${e} runs into water with no waterline to follow and ends at the last dry ground it had`]}}}if(!a)return{points:t,diagnostics:[]};let s=i?`water: ${e} leaves the village from a contract entry that is itself in the water; its approach road goes ashore before following the coast`:null,n=t.slice(0,a.index),l=s1(a.point,a.ring,a.edge,1,r,o),d=s1(a.point,a.ring,a.edge,-1,r,o),h=Hk(l,d),c=h.points[0];for(;c&&n.length>=2&&A(n[n.length-1],c)>A(n[n.length-2],c);)n.pop();return h.points.length===0?{points:n,diagnostics:[...s?[s]:[],`coast: ${e} meets water with no dry ground within ${ma*d1} m of the shore and ends there`]}:h.escaped?{points:Ok([...n,...h.points],r),diagnostics:s?[s]:[]}:{points:[...n,h.points[0]],diagnostics:[...s?[s]:[],`coast: ${e} follows the shore for ${Math.round(h.runM)} m without leaving the tile and ends at the water`]}}function h1(e,t,r,o=[]){let i=Bk(r),a=_k(r),s=[],n=[],l=[],d=[...e].filter(k=>k.points.length>=2).sort((k,p)=>k.id.localeCompare(p.id)),h=[],c=new Set;for(let k of d){let p=k.points[k.points.length-1],f=t.filter(m=>A(m.point,p)<=i1);if(f.length!==0){for(let m of f)c.add(m);h.push({id:M2(k.id,"outer"),lane:k,from:k})}}for(let k of d){let p=k.points[0];t.some(f=>!c.has(f)&&A(f.point,p)<=i1)&&h.push({id:M2(k.id,"inner"),lane:k,from:{...k,points:[...k.points].reverse()}})}h.sort((k,p)=>k.lane.id.localeCompare(p.lane.id)||k.id.localeCompare(p.id));for(let k of h){let p=k.lane,f=Ek(k.from,i);if(f.length<2)continue;for(let L of f)Tt(o,L,uo);let m=k.id;if(o.length>0){let L=Vk(m,f,o,a);if(f=ui(L.points,o,Qt(p).surfaceM/2),l.push(...L.diagnostics),f.length<2)continue}let v=qs[p.type];for(let L=1;L<f.length;L++){let w=null,M=1/0,x=f[L];for(let b of s){let u=Yr(f[L],b.points);u.distance<=v&&u.distance<M&&(w=b,M=u.distance,x=u.point)}if(w){f=[...f.slice(0,L),x];let b=[m,w.id].sort();n.push({id:`j:${b.join("+")}`,position:x,laneIds:b});break}}s.push({id:m,type:p.type,widthM:p.widthM,points:f,...p.sourceRouteIds?{sourceRouteIds:p.sourceRouteIds}:{},...p.routeRole?{routeRole:"approach"}:{}})}return{lanes:s,junctions:n,diagnostics:l}}function x2(e,t,r){let o=A(e,t),i=Math.max(1,Math.ceil(o)),a=0,s=0;for(let n=0;n<=i;n++){let l=n/i;if(kt(new Z(e.x+(t.x-e.x)*l,e.y+(t.y-e.y)*l),r.water)){if(a+=o/i,s+=o/i,s>12)return 1/0}else s=0}return o+a*8}function jk(e){return ft(e)<=ft("town")?"town":e==="local"?"local":"footpath"}function k1(e,t,r,o,i){let a=Math.min(1,i/600),s=t==="footpath"?1:t==="town"?2.2+a*.6:1.3+a*.7;return{id:e,routeRole:"street",type:t,points:r,widthM:s+.4,surfaceWidthM:s,setbackM:.6,sourceRouteIds:o}}function $k(e,t,r,o){let i=Math.max(18,t/3.5),a=t*1.7+i*2,s=new Tr(o.x-a*3,o.y-a*3,o.x+a*3,o.y+a*3),n=r.float()*Math.PI*2,l=Math.cos(n),d=Math.sin(n);for(let f=-a;f<=a;f+=i)for(let m=-a;m<=a;m+=i){let v=m+(r.float()-.5)*i*.8,L=f+(r.float()-.5)*i*.8;s.addPoint(new Z(o.x+v*l-L*d,o.y+v*d+L*l))}let h=s.triangulation().filter(f=>Number.isFinite(f.c.x)&&Number.isFinite(f.c.y)&&A(f.c,o)<=t*1.65+i),c=h.map(f=>({p:f.c,edges:[]})),k=new Map(s.points.map((f,m)=>[f,m])),p=new Map;return h.forEach((f,m)=>{for(let[v,L]of[[f.p1,f.p2],[f.p2,f.p3],[f.p3,f.p1]]){let w=[k.get(v),k.get(L)].sort((u,P)=>u-P).join(":"),M=p.get(w);if(M===void 0){p.set(w,m);continue}if(kt(c[m].p,e.water)||kt(c[M].p,e.water))continue;let x=x2(c[m].p,c[M].p,e);if(!Number.isFinite(x))continue;let b={a:m,b:M,cost:x,sources:new Set};c[m].edges.push(b),c[M].edges.push(b)}}),c}function Nk(e,t,r){let o=e.map(()=>1/0),i=new Map,a=new Set;for(o[t]=0;;){let n=-1,l=1/0;for(let d=0;d<e.length;d++)!a.has(d)&&o[d]<l&&(l=o[d],n=d);if(n<0)return null;if(n===r)break;a.add(n);for(let d of e[n].edges){let h=d.a===n?d.b:d.a,c=l+d.cost*(d.type?.65:1);c<o[h]&&(o[h]=c,i.set(h,d))}}let s=[];for(let n=r;n!==t;){let l=i.get(n);s.push(l),n=l.a===n?l.b:l.a}return s}function Dk(e){let t=new Map;for(let r of e)for(let o of[r.points[0],r.points[r.points.length-1]]){let i=t.get(o)??[];i.push(r.id),t.set(o,i)}return[...t].filter(([,r])=>r.length>=2).map(([r,o],i)=>({id:`j:routed-${i}`,position:r,laneIds:o.sort()}))}function c1(e,t,r,o,i){let a={trunks:[],junctions:[],pattern:"terminal",aim:i,ring:[],diagnostics:[]};if(!t.length)return a;let s=[...t].sort((b,u)=>ft(b.route.type)-ft(u.route.type)||b.bearingDeg-u.bearingDeg||(b.route.routeId??"").localeCompare(u.route.routeId??"")),n=s[0],l=s.find(b=>b!==n&&b.route.type===n.route.type&&ft(b.route.type)<=ft("market")&&Qe(b.bearingDeg,n.bearingDeg)>=120);if(e.population<=120&&t.length===2&&l&&e.water.length===0){let b=n.route.type,u=p1(n.point,l.point,b,o),P={id:Ra(b,n.route.routeId,n.bearingDeg,!1),type:b,points:u,routeRole:"through",widthM:ve(b),sourceRouteIds:[...new Set(t.map(C=>Co(C.route.routeId,C.bearingDeg)))].sort()};return{...a,trunks:[P],pattern:"main-street"}}let d=$k(e,r,o,i),h=b=>d.map((u,P)=>({node:u,i:P,d:A(b,u.p)})).filter(u=>u.node.edges.length&&!kt(u.node.p,e.water)).sort((u,P)=>u.d-P.d),c=h(i)[0]?.i;if(c===void 0)throw new Error("No dry street junction near the village centre");let k=d[c].p,p=new Map,f=new Set,m=[];for(let b of s){let u=Lt(b.bearingDeg),P=new Z(i.x+u.x*r*1.15,i.y+u.y*r*1.15),C=m.find(X=>Qe(X.entry.bearingDeg,b.bearingDeg)<12),Q=C?.node??-1,R=null;for(let X of C?[{i:C.node}]:h(P))if(R=Nk(d,X.i,c),R){Q=X.i;break}if(Q<0||!R)throw new Error("No connected street for an incoming route");let V=jk(b.route.type),j=Co(b.route.routeId,b.bearingDeg);for(let X of R)(!X.type||ft(V)<ft(X.type))&&(X.type=V),X.sources.add(j),f.add(X);let F=new Z(b.point.x-u.x*12,b.point.y-u.y*12),K=Q,H=new Z(b.point.x*.72+i.x*.28,b.point.y*.72+i.y*.28);for(let X of C?[F,b.point]:[H,F,b.point]){let nt=d.length;d.push({p:X,edges:[]});let mt={a:K,b:nt,cost:A(d[K].p,X),type:V,sources:new Set([j])};d[K].edges.push(mt),d[nt].edges.push(mt),f.add(mt),K=nt,X===H&&m.push({entry:b,node:nt})}p.set(K,b)}let v=d.map(b=>b.edges.filter(u=>f.has(u))),L=new Set,w=[],M=new Set,x=b=>{let u=b;for(let P=2;M.has(u);P++)u=`${b}~${P}`;return M.add(u),u};for(let b=0;b<d.length;b++)if(!(v[b].length===2&&b!==c))for(let u of v[b]){if(L.has(u))continue;let P=[b],C=new Set,Q=b,R=u,V="footpath";for(;;){L.add(R);for(let J of R.sources)C.add(J);if(ft(R.type)<ft(V)&&(V=R.type),Q=R.a===Q?R.b:R.a,P.push(Q),v[Q].length!==2||Q===c)break;let $=v[Q].find(J=>J!==R);if(L.has($))break;R=$}p.has(P[0])&&P.reverse();let j=Qa(P.map($=>d[$].p),e.water);for(let $=1;$+1<j.length;$++){let J=j[$-1],lt=j[$],xt=j[$+1];(A(lt,st(lt,J,xt))<3||Qe(pt(J,lt),pt(lt,xt))>110)&&Number.isFinite(x2(J,xt,e))&&(j.splice($,1),$=Math.max(0,$-2))}let F=Xr(j)??j,K=F.some(($,J)=>J>0&&!Number.isFinite(x2(F[J-1],$,e)))?j:F,H=[K[0]];for(let $=1;$<K.length;$++){let J=K[$-1],lt=K[$],xt=Math.max(1,Math.ceil(A(J,lt)/3));for(let zt=1;zt<=xt;zt++)H.push(zt===xt?lt:new Z(J.x+(lt.x-J.x)*zt/xt,J.y+(lt.y-J.y)*zt/xt))}let X=[...C].sort(),nt=p.get(P[P.length-1]),mt=nt?.route.type??s.filter($=>X.includes(Co($.route.routeId,$.bearingDeg))).map($=>$.route.type).sort(($,J)=>ft($)-ft(J))[0]??V;if(!nt&&H.every($=>A($,k)<r*1.15)){w.push(k1(x(`trunk-street-${w.length}`),V,H,X,e.population));continue}A(H[0],k)>A(H[H.length-1],k)&&H.reverse();let O=r*1.15,Y=H.findIndex(($,J)=>J>0&&A($,k)>=O);Y<1&&(Y=1),Y>=H.length-1&&(Y=H.length-2);let rt=H.every($=>A($,k)>=O),yt=rt?[]:H.slice(0,Y+1),B=rt?H:H.slice(Y);yt.length>=2&&w.push(k1(x(`trunk-street-${w.length}`),V,yt,X,e.population));let U=mt;w.push({id:x(nt?Ra(U,nt.route.routeId,nt.bearingDeg,!1):`trunk-approach-${w.length}`),type:U,points:B,routeRole:"approach",widthM:ve(U),sourceRouteIds:X})}return{...a,trunks:w,junctions:Dk(w),aim:k,pattern:t.length>1?"routed":"terminal"}}var Fk=.12,f1=.55,Gk=6;var Wk=1.5,Uk=45;function L1(e,t,r,o){let i=1-o,a=i*i,s=2*i*o,n=o*o;return new Z(a*e.x+s*t.x+n*r.x,a*e.y+s*t.y+n*r.y)}function qk(e,t,r){let i=0,a=e;for(let s=1;s<=24;s++){let n=L1(e,t,r,s/24);i+=Z.distance(a,n),a=n}return i}function Z2(e,t,r){let o=qk(e,t,r),i=Math.max(1,Math.ceil(o/Gk)),a=[];for(let s=1;s<=i;s++)a.push(L1(e,t,r,s/i));return a}function p1(e,t,r,o){let i=t.x-e.x,a=t.y-e.y,s=Math.hypot(i,a),n=l5[r];if(s===0)return[e.clone(),t.clone()];let l=new Z(-a/s,i/s),d=c=>{let k=o.float()<.5?-1:1,p=f1+o.float()*(1-f1);return k*p*c*s},h=[e.clone()];if(n>=Fk){let c=d(n*.5),k=d(n),p=new Z(e.x*.75+t.x*.25+l.x*c,e.y*.75+t.y*.25+l.y*c),f=new Z(e.x*.25+t.x*.75+l.x*k,e.y*.25+t.y*.75+l.y*k),m=new Z((p.x+f.x)/2,(p.y+f.y)/2);h.push(...Z2(e,p,m)),h.push(...Z2(m,f,t))}else{let c=d(n),k=new Z((e.x+t.x)/2+l.x*c,(e.y+t.y)/2+l.y*c);h.push(...Z2(e,k,t))}return h}function y1(e){return e*n5}function Ce(e){return e.startsWith("trunk-")&&!e.includes("/b")}function Kk(e,t){let r=[];for(let o of e.routes)r.push(Yk(o,o.bearingDeg,t,!1));return r.sort((o,i)=>o.bearingDeg!==i.bearingDeg?o.bearingDeg-i.bearingDeg:o.farSide!==i.farSide?o.farSide?1:-1:(o.route.routeId??"").localeCompare(i.route.routeId??"")),r}function Yk(e,t,r,o){let i=Lt(t);return{point:new Z(i.x*r,i.y*r),bearingDeg:t,route:e,farSide:o}}function P2(e){let t=[...e];for(let r=0;r<6&&t.length>3;r++){let o=Math.atan2(t[1].y-t[0].y,t[1].x-t[0].x),i=Math.atan2(t[2].y-t[1].y,t[2].x-t[1].x),a=Math.abs((i-o)*180/Math.PI);if(a>180&&(a=360-a),a<=Uk)break;t.splice(1,1)}return t}function m1(e){return[...e].sort()}function v1(e){return P2([...e].reverse()).reverse()}function w1(e){return e.replace(/[^a-zA-Z0-9]/g,"_")}function Xk(e,t){for(let r=1;r<e.length;r++)for(let o=1;o<t.length;o++){let i=Wt(e[r-1],e[r],t[o-1],t[o]);if(i)return{aIdx:r-1,bIdx:o-1,point:i}}return null}function Jk(e){for(let t=0;t<e.length;t++)for(let r=t+1;r<e.length;r++){let o=Xk(e[t].points,e[r].points);if(o)return{i:t,j:r,hit:o}}return null}function t4(e,t){let r=e,o=t,i=e.length*e.length+8;for(let a=0;a<i;a++){let s=Jk(r);if(!s)return{trunks:r,junctions:o};let{i:n,j:l,hit:d}=s,h=r[n],c=r[l],k={...h,points:v1([...h.points.slice(0,d.aIdx+1),d.point])},p={...h,id:`${h.id}~x${w1(c.id)}`,points:P2([d.point,...h.points.slice(d.aIdx+1)])},f={...c,points:v1([...c.points.slice(0,d.bIdx+1),d.point])},m={...c,id:`${c.id}~x${w1(h.id)}`,points:P2([d.point,...c.points.slice(d.bIdx+1)])},v=[...r];v[n]=k,v[l]=f,v.push(p,m),r=v,o=[...o,{id:`j:${m1([k.id,p.id,f.id,m.id]).join("+")}`,position:d.point,laneIds:m1([k.id,p.id,f.id,m.id])}]}throw new Error("resolveCrossings exceeded its iteration cap -- the no-proper-crossing invariant loop should always terminate given a finite, fixed set of underlying segments; this means a real bug (e.g. a split that does not shrink the crossing count), not a legitimately busy network.")}function e4(e,t){let r=new Set(e.filter(a=>a.points.length>=2).map(a=>a.id)),o=[],i=new Set;for(let a of t){if(!e.some(d=>d.points.length>=2&&Yr(a.position,d.points).distance<=Wk))continue;let n=a.laneIds.filter(d=>r.has(d));if(n.length===0)continue;let l={...a,laneIds:n};i.has(l.id)||(i.add(l.id),o.push(l))}return o}function M1(e,t,r,o,i=new Z(0,0)){let a=Kk(e,t),s=c1(e,a,r,o,i),n=k=>`${k.x.toFixed(6)},${k.y.toFixed(6)}`,l=new Map;for(let k of s.trunks)for(let p of[k.points[0],k.points.at(-1)]){if(a.some(m=>A(m.point,p)<.001))continue;let f=Qt(k).surfaceM/2+g2;f>(l.get(n(p))?.clearance??0)&&l.set(n(p),{p,clearance:f})}for(let k of l.values())k.p=b2(k.p,e.water,k.clearance);let d=k=>l.get(n(k))?.p??k;s.junctions=s.junctions.map(k=>({...k,position:d(k.position)})),s.aim=d(s.aim),s.trunks=s.trunks.map(k=>({...k,points:k.points.map((p,f)=>f===0||f===k.points.length-1?d(p):p)})),s.trunks=s.trunks.map(k=>({...k,points:ui(k.points,e.water,Qt(k).surfaceM/2)}));let h=h1(s.trunks,a,t,e.water),c=t4([...s.trunks,...h.lanes],[...s.junctions,...h.junctions]);return{...s,trunks:c.trunks,junctions:e4(c.trunks,c.junctions),entries:a,contractRadiusM:t,diagnostics:[...s.diagnostics,...h.diagnostics]}}function Qt(e){return{corridorM:e.widthM,surfaceM:e.surfaceWidthM??e.widthM*(ft(e.type)<ft("local")?1:Il),setbackM:e.setbackM??z3[e.type]??2}}function Be(e){let t=Qt(e);return t.corridorM/2+t.setbackM}function Aa(e,t){if(Ce(e.id)||(e={...e,routeRole:"street",type:ft(e.type)<=ft("town")?"town":e.type==="local"?"local":"footpath"},e.surfaceWidthM!==void 0))return e;let r=Math.min(1,Math.max(0,(t-8)/80)),o=e.type==="footpath"?1:e.type==="trail"?1.4:1.2+1.2*r;return{...e,widthM:o+.4,surfaceWidthM:o,setbackM:.5+.2*r}}var S2=q2(w2(),1);function u1(e,t,r,o,i=[]){if(e.length>=3&&i.length){let s=i.filter(c=>S2.default.intersection([e.map(k=>[k.x,k.y])],[c.map(k=>[k.x,k.y])]).length>0),n=[e,...s].map(c=>[c.map(k=>[k.x,k.y])]),l=S2.default.union(n[0],...n.slice(1)),d=c=>Math.abs(c.reduce((k,p,f)=>{let m=c[(f+1)%c.length];return k+p[0]*m[1]-m[0]*p[1]},0)),h=l.map(c=>c[0]).sort((c,k)=>d(k)-d(c))[0];h&&(e=h.slice(0,-1).map(([c,k])=>new Z(c,k)))}let a={polylines:[],gates:[],towers:[],large:!1,material:o==="desert"?"rubble":"palisade"};for(let s=0;s<e.length;s++){let n=e[s],l=e[(s+1)%e.length],d=l.x-n.x,h=l.y-n.y,c=Math.hypot(d,h);for(let k of dr(n,l,r)){let p=a.polylines.at(-1);p&&Math.hypot(p.at(-1).x-k[0].x,p.at(-1).y-k[0].y)<1e-6?p.push(k[1]):a.polylines.push([...k])}for(let k of t)for(let p=1;p<k.points.length;p++){let f=k.points[p-1],m=k.points[p],v=m.x-f.x,L=m.y-f.y,w=d*L-h*v;if(Math.abs(w)<1e-8)continue;let M=((f.x-n.x)*L-(f.y-n.y)*v)/w,x=((f.x-n.x)*h-(f.y-n.y)*d)/w;if(M<0||M>1||x<0||x>1)continue;let b=n.x+M*d,u=n.y+M*h;if(a.gates.some(Q=>Math.hypot((Q.p1.x+Q.p2.x)/2-b,(Q.p1.y+Q.p2.y)/2-u)<.5))continue;let P=Math.abs(w)/(c*Math.hypot(v,L)),C=(Qt(k).surfaceM+1)/2/Math.max(.12,P);a.gates.push({p1:{x:b-d/c*C,y:u-h/c*C},p2:{x:b+d/c*C,y:u+h/c*C},routeIds:k.sourceRouteIds??[]})}}return a}function g1(e,t,r){let o=[];for(let a of[...e,...t.filter(s=>!["stone-circle","boathouse"].includes(s.kind))]){let s="footprint"in a?a.footprint:re(a.glyph),n=pe(a.glyph,s),l=a.bearingDeg*Math.PI/180,d=Math.cos(l),h=Math.sin(l);for(let c of[-n.width/2,n.width/2])for(let k of[-n.depth/2,n.depth/2])o.push(new Z(a.position.x+c*d-k*h,a.position.y+k*d+c*h))}let i=po(o);return i.length<3?r:i.map((a,s)=>{let n=i[(s+i.length-1)%i.length],l=i[(s+1)%i.length],d=Z.distance(n,a),h=Z.distance(a,l),c={x:(a.y-n.y)/d,y:(n.x-a.x)/d},k={x:(l.y-a.y)/h,y:(a.x-l.x)/h},p=3.5/(1+c.x*k.x+c.y*k.y);return new Z(a.x+(c.x+k.x)*p,a.y+(c.y+k.y)*p)})}function Ze(e,t,r){if(e.length<2)return[];let o=[];for(let a=0;a<e.length-1;a++){let s=We(e[a+1].x-e[a].x,e[a+1].y-e[a].y);o.push(new Z(-s.y*r,s.x*r))}let i=[];for(let a=0;a<e.length;a++){let s=o[Math.max(0,a-1)],n=o[Math.min(a,o.length-1)],l=We(s.x+n.x,s.y+n.y),d=l.x*n.x+l.y*n.y,h=d===0?1:1/d,c=Math.min(Math.abs(h),4)*Math.sign(h||1);i.push(new Z(e[a].x+l.x*t*c,e[a].y+l.y*t*c))}return i}function wt(e){let t=Lt(e.bearingDeg),r=new Z(-t.x,-t.y),o=new Z(-t.y,t.x),i=e.depthM/2;return{center:new Z(e.front.x+r.x*i,e.front.y+r.y*i),tangent:o,normal:r,halfW:e.frontageM/2,halfD:i}}function oe(e,t,r=0){let o=new Z(t.center.x-e.center.x,t.center.y-e.center.y);for(let i of[e.tangent,e.normal,t.tangent,t.normal]){let a=Math.abs(o.x*i.x+o.y*i.y),s=Math.abs(e.tangent.x*i.x+e.tangent.y*i.y)*e.halfW+Math.abs(e.normal.x*i.x+e.normal.y*i.y)*e.halfD,n=Math.abs(t.tangent.x*i.x+t.tangent.y*i.y)*t.halfW+Math.abs(t.normal.x*i.x+t.normal.y*i.y)*t.halfD;if(a>=s+n-r)return!1}return!0}function gi(e,t,r=0){let o=new Z(e.x-t.center.x,e.y-t.center.y),i=Math.abs(o.x*t.tangent.x+o.y*t.tangent.y),a=Math.abs(o.x*t.normal.x+o.y*t.normal.y);return i<=t.halfW+r&&a<=t.halfD+r}function Bo(e){return wt({...e,depthM:Math.min(e.depthM,$3)})}function we(e,t){let r=0,o=e.depthM;for(let i=0;i<8;i++){let a=(r+o)/2,s=wt({...e,depthM:a});oe(s,t)?o=a:r=a}return r}function r4(e,t){let r=new Set,o=new Map,i=new Map;for(let a of e){let s=`${a.laneId} ${a.side}`,n=i.get(s);n?n.push(a):i.set(s,[a])}for(let a of i.values()){if(a.length<2)continue;let s=[...a].sort((h,c)=>Mi(h.id)-Mi(c.id)),l=s.reduce((h,c)=>h+c.frontageM,0)/s.length*V3,d=s[0];for(let h=1;h<s.length;h++){let c=s[h];if(A(d.front,c.front)<l){r.add(c.id),t?.set(c.id,"inner-fold");continue}let k=wt(d);if(!oe(k,wt(c))){d=c;continue}if(!oe(Bo(d),Bo(c))){let v=we(d,Bo(c));o.set(d.id,v);let L=we(c,wt({...d,depthM:v}));o.set(c.id,L),d={...c,depthM:L};continue}let p=we(c,k);if(p>=Bs){o.set(c.id,p),d={...c,depthM:p};continue}let f=Math.min(d.depthM,Re),m=we(c,wt({...d,depthM:f}));if(m>=Re){let v=Math.min(d.depthM,Math.max(f,we(d,wt({...c,depthM:m}))));o.set(d.id,v);let L=we(c,wt({...d,depthM:v}));o.set(c.id,L),d={...c,depthM:L};continue}r.add(c.id),t?.set(c.id,"inner-wander")}}return e.filter(a=>!r.has(a.id)).map(a=>o.has(a.id)?{...a,depthM:o.get(a.id)}:a)}function b1(e,t){if(e==="green")return-1;let r=t.get(e);return r?ft(r):ft("footpath")}function o4(e,t,r,o){let i=new Map(t.map(k=>[k.id,k.type])),a=new Map(t.map(k=>[k.id,k])),s=k=>A(k.front,r.centre),n=k=>Math.hypot(k.frontageM/2,k.depthM),l=[...e].sort((k,p)=>k.id.localeCompare(p.id)),d=new Map,h=new Set,c=k=>{let p=d.get(k.id);return p===void 0?k:{...k,depthM:p}};for(let k=0;k<l.length;k++){let p=l[k];if(!h.has(p.id))for(let f=k+1;f<l.length;f++){let m=l[f];if(h.has(m.id)||p.laneId===m.laneId&&p.side===m.side&&Math.abs(Mi(p.id)-Mi(m.id))===1&&p.laneId!=="green")continue;let w=c(p),M=c(m);if(A(w.front,M.front)>n(w)+n(M)||!oe(wt(w),wt(M)))continue;let x=b1(w.laneId,i),b=b1(M.laneId,i),u=w,P=M;if(x!==b)b<x&&(u=M,P=w);else{let j=s(w),F=s(M);j!==F?F<j&&(u=M,P=w):w.laneId!==M.laneId?M.laneId.localeCompare(w.laneId)<0&&(u=M,P=w):M.id.localeCompare(w.id)<0&&(u=M,P=w)}let C=j=>{o&&o.set(P.id,`${a4(P,u,a)}/${j}`)};if(!oe(Bo(u),Bo(P))){let j=we(u,Bo(P));d.set(u.id,j);let F=we(P,wt({...u,depthM:j}));d.set(P.id,F);continue}let Q=j=>wt({...j,depthM:Math.min(j.depthM,Re)});if(!oe(Q(u),Q(P))){let j=Math.min(u.depthM,Math.max(Re,we(u,Q(P)))),F=we(P,wt({...u,depthM:j}));if(F>=Re){d.set(u.id,j),d.set(P.id,F);continue}}let R=wt(u);if(gi(P.front,R)){h.add(P.id),C("front-inside");continue}let V=we(P,R);V<Bs?(h.add(P.id),C("too-shallow")):d.set(P.id,V)}}return e.filter(k=>!h.has(k.id)).map(k=>c(k))}function x1(e,t,r,o){return o4(r4(e,o),t,r,o)}var i4=20;function a4(e,t,r){if(e.laneId===t.laneId)return"cross-same-lane";if(t.laneId==="green"||e.laneId==="green")return"cross-green-ring";let o=r.get(e.laneId),i=r.get(t.laneId);if(!o||!i)return"cross-other-lane";let a=1/0;for(let s=1;s<o.points.length;s++)for(let n=0;n<i.points.length;n++){let l=st(i.points[n],o.points[s-1],o.points[s]);A(i.points[n],l)<=1.5&&(a=Math.min(a,A(e.front,l)))}return a<=i4?"cross-junction-mouth":"cross-parallel-lanes"}function Z1(e){let t=Math.min(1,Math.max(0,(e-Cs)/(I3-Cs)));return Ss+(Q3-Ss)*t}function bi(e,t,r){let o=t<=0?0:Math.min(da,e/t);return r*(1+la*Math.pow(o,na))}function P1(e,t,r,o,i,a,s=0,n=1/0,l=1/0){let d=typeof l=="function"?l:()=>l,h=[],c=Be(e);for(let k of[1,-1]){let p=Ze(e.points,c,k);if(p.length<2)continue;let f=gt(p),m=f[f.length-1],v=0,L=0;for(;v<m;){let{p:w}=ut(p,f,v),M=A(w,t.centre),x=1+(a.float()-.5)*2*A3,b=Math.max(s,n),u=Math.min(b,Math.max(s,o*ha,bi(M,r,o)*x));if(v+u>m)break;let P=ut(p,f,v+u/2),C=(P.dirDeg+(k===1?-90:90)+360)%360;if(M>d(w)){v+=u,L++;continue}h.push({id:Ea(e.id,k,L),laneId:e.id,side:k,front:P.p,bearingDeg:C,frontageM:u,depthM:i,score:0});let Q=Ba(ut(p,f,v).dirDeg,ut(p,f,Math.min(m,v+u)).dirDeg),V=(k===1?Q>0:Q<0)?i*Math.abs(Q*Math.PI/180):0;v+=u+V+Mo,L++}}return h}function S1(e,t,r,o,i=[]){let a=e.diameter/2*Lo+gr,s=2*Math.PI*a,n=Math.PI*2,l=o.float()*(n/Math.max(4,Math.floor(s/t))),d=[],h=a+t;for(let f of i){let m=(f.widthM/2+t*O3)/a;for(let v=1;v<f.points.length;v++){let L=f.points[v-1],w=f.points[v],M=A(L,w),x=Math.max(1,Math.ceil(M/2));for(let b=0;b<=x;b++){let u=new Z(L.x+(w.x-L.x)*b/x,L.y+(w.y-L.y)*b/x);if(A(u,e.centre)>h)continue;let P=Math.atan2(u.x-e.centre.x,-(u.y-e.centre.y));d.push([P-m,P+m])}}}let c;if(d.length===0)c=[[l,l+n]];else{let f=d.map(([m,v])=>[(m%n+n)%n,v-m]).map(([m,v])=>[m,m+v]).sort((m,v)=>m[0]-v[0]).reduce((m,[v,L])=>{let w=m[m.length-1];return w&&v<=w[1]?w[1]=Math.max(w[1],L):m.push([v,L]),m},[]);c=[];for(let m=0;m<f.length;m++){let v=f[m][1],L=m===f.length-1?f[0][0]+n:f[m+1][0];L>v&&c.push([v,L])}}let k=[],p=0;for(let[f,m]of c){let v=(m-f)*a,L=d.length===0?Math.max(4,Math.floor(v/t)):Math.floor(v/t);if(L<1)continue;let w=(m-f)/L;for(let M=0;M<L;M++){let x=f+(M+.5)*w,b=new Z(e.centre.x+a*Math.sin(x),e.centre.y-a*Math.cos(x)),u=pt(b,e.centre);k.push({id:Ea("green",1,p),laneId:"green",side:1,front:b,bearingDeg:u,frontageM:v/L,depthM:r,score:0}),p++}}return k}function s4(e,t){if(Tt(t,e.front,Math.hypot(e.frontageM/2,e.depthM)),t.length===0)return!1;let r=wt(e),o=r.tangent,i=r.normal,a=(n,l)=>new Z(r.center.x+o.x*n*r.halfW+i.x*l*r.halfD,r.center.y+o.y*n*r.halfW+i.y*l*r.halfD),s=[a(-1,-1),a(1,-1),a(1,1),a(-1,1)];if(kt(r.center,t)||s.some(n=>kt(n,t)))return!0;for(let n=0;n<s.length;n++){let l=s[n],d=s[(n+1)%s.length];for(let h of t)for(let c=0;c<h.length;c++){let k=h[c],p=h[(c+1)%h.length];if(Wt(l,d,k,p))return!0}}return!1}function C2(e,t,r){let o=t.diameter/2;return e.filter(i=>{if(s4(i,r))return!1;let a=A(i.front,t.centre);return!(i.laneId!=="green"&&a<o)})}function C1(e,t,r){return e.map(o=>{let i=A(o.front,t.centre),a=r.get(o.laneId),s=a?(7-ft(a))*el:0,n=o.laneId==="green"?rl:0;return{...o,score:J3-i*tl+s+n}})}function Eo(e){return[...e].sort((t,r)=>r.score-t.score||t.id.localeCompare(r.id))}var n4=1+la*Math.pow(da,na);function l4(e,t,r,o){if(o<=0)return 0;let i=A(e.front,t.centre),a=bi(i,r,o)/o;if(a<=ka)return 0;let s=n4-ka;return(s<=0?1:Math.min(1,(a-ka)/s))*ll}function B2(e){let t=Lt(e.bearingDeg),r=new Z(-t.x,-t.y);return{tangent:new Z(-t.y,t.x),normal:r}}function d4(e,t){if(!t)return e.depthM;let{normal:r}=B2(e),i=(t.position.x-e.front.x)*r.x+(t.position.y-e.front.y)*r.y+pe(t.glyph,t.footprint).depth/2+hl;return Math.min(e.depthM,Math.max(0,i))}function B1(e,t,r){let{tangent:o,normal:i}=B2(e),a=(e.depthM+r-t)/2,s=t+a;return{center:new Z(e.front.x+i.x*s,e.front.y+i.y*s),tangent:o,normal:i,halfW:e.frontageM/2,halfD:a}}function E1(e){let{center:t,tangent:r,normal:o,halfW:i,halfD:a}=e,s=[];for(let n of[-1,1])for(let l of[-1,1])s.push(new Z(t.x+r.x*i*n+o.x*a*l,t.y+r.y*i*n+o.y*a*l));return s.push(new Z(t.x+o.x*a,t.y+o.y*a)),s.push(new Z(t.x-o.x*a,t.y-o.y*a)),s.push(new Z(t.x+r.x*i,t.y+r.y*i)),s.push(new Z(t.x-r.x*i,t.y-r.y*i)),s}function h4(e){return Be(e)}function k4(e,t){if(t.points.length<2)return!1;let r=h4(t);for(let o=1;o<t.points.length;o++){let i=t.points[o-1],a=t.points[o],s=A(i,a),n=Math.max(1,Math.ceil(s/2));for(let l=0;l<=n;l++){let d=new Z(i.x+(a.x-i.x)*l/n,i.y+(a.y-i.y)*l/n);if(gi(d,e,r))return!0}}return!1}function c4(e,t){let r=Ct(t);return E1(e).some(o=>A(o,t.centre)<r)}function p4(e,t){return E1(e).some(r=>kt(r,t))}function f4(e,t,r,o,i,a,s,n){let l=c=>{let k=B1(e,t,c);if(!(k.halfD>0))return!0;if(o.some(p=>k4(k,p))||c4(k,i)||p4(k,a))return!1;for(let p of s)if(p.id!==e.id&&oe(k,wt(p)))return!1;for(let p of n)if(oe(k,p))return!1;return!0};if(l(r))return r;let d=0,h=r;for(let c=0;c<10;c++){let k=(d+h)/2;l(k)?d=k:h=k}return d}function m4(e,t,r){let{tangent:o,normal:i}=B2(e),a=e.frontageM/2,s=new Z(e.front.x+i.x*t,e.front.y+i.y*t),n=e.depthM+r,l=new Z(e.front.x+i.x*n,e.front.y+i.y*n),d=new Z(s.x-o.x*a,s.y-o.y*a),h=new Z(s.x+o.x*a,s.y+o.y*a),c=new Z(l.x-o.x*a,l.y-o.y*a),k=new Z(l.x+o.x*a,l.y+o.y*a);return[d,h,k,c]}function _1(e,t,r,o,i,a,s){let n=new Map(t.map(c=>[c.lotId,c])),l=Eo(e).filter(c=>n.has(c.id)),d=[],h=[];for(let c of l){let k=l4(c,r,a,s);if(k<=0)continue;let p=d4(c,n.get(c.id)),f=f4(c,p,k,o,r,i,e,h);if(f<dl)continue;let m=`croft:${c.id}`,v=m4(c,p,f);d.push({id:m,lotId:c.id,polygon:v,depthM:f}),h.push(B1(c,p,f))}return d}function R1(e,t,r){let i={...As[e]??As.temperate};t<sl&&(i.none=(i.none??0)+nl);let a=ai.reduce((n,l)=>n+(i[l]??0),0);if(a<=0)return"none";let s=r.float()*a;for(let n of ai)if(s-=i[n]??0,s<=0)return n;return ai[ai.length-1]}var ie=Math.round(360/fa);function Q1(e,t,r){let o=i=>{let a=((i/fa-.5)%ie+ie)%ie,s=Math.floor(a),n=a-s;return t[s%ie]+(t[(s+1)%ie]-t[s%ie])*n};return{atBearing:o,at:i=>o(pt(e,i)),maxM:Math.max(r,...t),plus:i=>Q1(e,t.map(a=>a+i),r+i)}}function xi(e,t,r,o=1){let i=Array.from({length:ie},()=>[]);for(let l of t){let d=(Math.floor(pt(e,l)/fa)%ie+ie)%ie;i[d].push(A(e,l))}let a=i.map(l=>{if(l.length===0)return null;let d=l.sort((c,k)=>c-k),h=Math.min(d.length-1,Math.max(0,Math.round(o*(d.length-1))));return d[h]}),s=a.map((l,d)=>{if(l!==null)return l;for(let h=1;h<=ie;h++){let c=a[(d+h)%ie],k=a[(d-h+ie)%ie];if(c!==null&&k!==null)return(c+k)/2;if(c!==null)return c;if(k!==null)return k}return r}),n=s.map((l,d)=>(s[(d-1+ie)%ie]+s[d]+s[(d+1)%ie])/3);return Q1(e,n.map(l=>Math.max(r,l)),r)}function _2(e){let{center:t,tangent:r,normal:o,halfW:i,halfD:a}=e,s=(n,l)=>new Z(t.x+r.x*i*n+o.x*a*l,t.y+r.y*i*n+o.y*a*l);return[s(-1,-1),s(1,-1),s(1,1),s(-1,1)]}function v4(e,t,r,o){let i=[];for(let a of t){if(o&&!o.has(a.id))continue;let s=wt(a),n=0;for(let l of _2(s))n=Math.max(n,A(e.centre,l));i.push(n)}for(let a of r){if(a.polygon.length===0)continue;let s=0;for(let n of a.polygon)s=Math.max(s,A(e.centre,n));i.push(s)}return i}function R2(e,t,r,o){let i=Ct(e);for(let a of v4(e,t,r,o))i=Math.max(i,a);return i}function Ta(e,t,r){let o=[];for(let i of e)r&&!r.has(i.id)||o.push(..._2(wt(i)));for(let i of t)o.push(...i.polygon);return o}function w4(e,t,r,o){let i=Ct(e)+gr+pl;return xi(e.centre,Ta(t,r,o),i,cl)}function L4(e,t,r){let o=ml,i=360/o,a=[];for(let l=0;l<o;l++)a.push(Ts+r.float()*(fl-Ts));let s=a.map((l,d)=>(a[(d-1+o)%o]+a[d]*2+a[(d+1)%o])/4),n=[];for(let l=0;l<o;l++){let d=l*i,h=0;for(let p=-6;p<=6;p++)h=Math.max(h,t.atBearing(d+p*i/12));let c=Lt(d),k=h+s[l];n.push(new Z(e.centre.x+c.x*k,e.centre.y+c.y*k))}return n}function y4(e,t,r,o){let i=vl,a=[],s=[];for(let k=0;k<i;k++)a.push(fe(k*360/i+(o.float()*2-1)*wl)),s.push(1+(o.float()*2-1)*Ll);let n=a.map(k=>{let p=0;for(let f of t)Math.abs((pt(e.centre,f)-k+540)%360-180)<360/i&&(p=Math.max(p,A(e.centre,f)));if(p===0)for(let f of t)p=Math.max(p,A(e.centre,f));return p}),l=$e(t),d=k=>po(a.map((p,f)=>{let m=Lt(p),v=n[f]+k*s[f];return new Z(e.centre.x+m.x*v,e.centre.y+m.y*v)})),h=yl,c=Ml;if($e(d(c))-l<=r)return d(c);if($e(d(h))-l>=r)return d(h);for(let k=0;k<40;k++){let p=(h+c)/2;$e(d(p))-l<r?h=p:c=p}return d((h+c)/2)}function M4(e,t,r){let o=t.filter(s=>Ot(s.id)&&s.points.length>=1),i=s=>{if(s.points.length===0)return!1;let n=s.points[s.points.length-1];return o.some(l=>A(l.points[0],n)<=1e-6)},a=[];for(let s of t){if(s.parentId!==void 0||i(s)||s.points.length<2)continue;let n=s.points[s.points.length-1],l=s.points[s.points.length-2];if(!bt(n,r)){let d=pt(l,n),h=Lt(d);a.push({p:n,dirDeg:d,halfWidthM:Be(s)+Bl,outX:h.x,outY:h.y})}}return a}function u4(e,t,r,o,i=[]){let a=[],s=l=>{if(l.length<3)return;let d=co(l),h=0;for(let c of l)h=Math.max(h,A(d,c));a.push({poly:l,centre:d,radiusM:h})};for(let l of e)s(_2(wt(l)));for(let l of t)s(l.polygon);for(let l of i)s(l);let n=[];for(let l of r){let d=Be(l);for(let h=1;h<l.points.length;h++)n.push({a:l.points[h-1],b:l.points[h],clearanceM:d})}return{claims:a,segs:n,water:o}}function g4(e,t){if(kt(e,t.water))return{kind:"water"};for(let r of t.claims)if(!(A(e,r.centre)>r.radiusM+si)&&(bt(e,r.poly)||H1(e,r.poly)<=si/2))return{kind:"claim",obstacle:r};for(let r of t.segs)if(A(e,st(e,r.a,r.b))<=r.clearanceM)return{kind:"lane",seg:r};return null}function T1(e){let t=[];for(let r=0;r<e.length;r++){let o=e[r],i=e[(r+1)%e.length],a=Math.max(1,Math.ceil(A(o,i)/Ql));for(let s=0;s<a;s++){let n=s/a;t.push(new Z(o.x+(i.x-o.x)*n,o.y+(i.y-o.y)*n))}}return t.push(co(e)),t}function I1(e,t){for(let r of T1(e)){let o=g4(r,t);if(o!==null)return{at:r,blocker:o}}return null}function b4(e,t){let r=e;for(let o=0;o<Vs;o++){let i=I1(r,t);if(i===null)return r;if(i.blocker.kind==="water")return[];let a=[];if(i.blocker.kind==="claim"){let l=i.blocker.obstacle.poly,d=0;for(let c=0;c<l.length;c++){let k=l[c],p=l[(c+1)%l.length];d+=k.x*p.y-p.x*k.y}let h=d>=0?1:-1;for(let c=0;c<l.length;c++){let k=l[c],p=l[(c+1)%l.length],f=Math.hypot(p.x-k.x,p.y-k.y);if(f<1e-9)continue;let m=-h*(p.y-k.y)/f,v=h*(p.x-k.x)/f;a.push({nx:m,ny:v,c:m*k.x+v*k.y-si})}}else{let{a:l,b:d,clearanceM:h}=i.blocker.seg,c=Math.hypot(d.x-l.x,d.y-l.y);if(c<1e-9)return[];let k=(d.x-l.x)/c,p=(d.y-l.y)/c,f=h+si;a.push({nx:p,ny:-k,c:p*l.x-k*l.y-f}),a.push({nx:-p,ny:k,c:-p*l.x+k*l.y-f}),a.push({nx:k,ny:p,c:k*l.x+p*l.y-f}),a.push({nx:-k,ny:-p,c:-(k*d.x+p*d.y)-f})}let s=[],n=0;for(let l of a){if(l.nx*i.at.x+l.ny*i.at.y<=l.c+1e-9)continue;let d=Lr(r,l.nx,l.ny,l.c),h=d.length>=3?$e(d):0;h>n&&(n=h,s=d)}if(s.length<3)return[];r=s}return I1(r,t)===null?r:[]}function O1(e,t){let r=0;for(let a=0;a<t.length;a++){let s=t[a],n=t[(a+1)%t.length];r+=s.x*n.y-n.x*s.y}let o=r>=0?1:-1,i=e;for(let a=0;a<Vs;a++){let s=null;for(let d of T1(i))if(bt(d,t)){s=d;break}if(s===null)return i;let n=[],l=0;for(let d=0;d<t.length;d++){let h=t[d],c=t[(d+1)%t.length],k=c.x-h.x,p=c.y-h.y,f=Math.hypot(k,p);if(f<1e-9)continue;let m=-o*p/f,v=o*k/f,L=m*h.x+v*h.y;if(m*s.x+v*s.y<=L+1e-9)continue;let w=Lr(i,m,v,L),M=w.length>=3?$e(w):0;M>l&&(l=M,n=w)}if(n.length<3)return[];i=n}return i}function x4(e,t){if(t.length===0)return null;let r=co(e),o=null;for(let i of t){if((r.x-i.p.x)*i.outX+(r.y-i.p.y)*i.outY<-i.halfWidthM)continue;let a=(i.dirDeg+90)*Math.PI/180,s=Math.sin(a),n=-Math.cos(a),l=Math.abs(s*(r.x-i.p.x)+n*(r.y-i.p.y));(o===null||l<o.distM)&&(o={road:i,distM:l})}return o}function Z4(e,t){let r=(t.dirDeg+90)*Math.PI/180,o=Math.sin(r),i=-Math.cos(r),a=o*t.p.x+i*t.p.y,s=1/0,n=-1/0;for(let d of e){let h=o*d.x+i*d.y;h<s&&(s=h),h>n&&(n=h)}if(s>=a+t.halfWidthM||n<=a-t.halfWidthM)return!1;let l=co(e);return(l.x-t.p.x)*t.outX+(l.y-t.p.y)*t.outY>-t.halfWidthM*2}function P4(e){return(e%180+180)%180}function A1(e,t){return(P4(e-t)+90)%180-90}function E2(e,t,r,o,i,a){let s=i.float(),n=i.float(),l=i.float(),d=$e(e);if(d<1e-6)return;let h=d<=Os*xl?O1(e,r):e;if(h.length<3)return;let c=$e(h);if(c<1e-6)return;if(t<Hs)for(let w of o){if(!Z4(h,w))continue;let M=t3(h,w.p,w.dirDeg,w.halfWidthM),x=o.filter(b=>b!==w);for(let b of M)E2(b,t+1,r,x,i,a);return}let k=Os*(1+(l*2-1)*gl);if(c<=k*bl||t>=Hs){a.push(h);return}let p=vs(h),f=Xn(h),m=x4(h,o);if(m!==null&&m.distM<=Cl){let w=m.road.dirDeg,M=m.road.dirDeg+90;f=Math.abs(A1(w,p))<=Math.abs(A1(M,p))?w:M}f+=(s*2-1)*Zl;let v=.5+(n-.5)*Pl,L=Jn(h,f,v,Sl);if(L.length<2){a.push(h);return}for(let w of L)E2(w,t+1,r,o,i,a)}function H1(e,t){let r=1/0;for(let o=0;o<t.length;o++){let i=t[o],a=t[(o+1)%t.length],s=a.x-i.x,n=a.y-i.y,l=s*s+n*n,d=l<1e-12?0:Math.max(0,Math.min(1,((e.x-i.x)*s+(e.y-i.y)*n)/l));r=Math.min(r,Math.hypot(e.x-(i.x+s*d),e.y-(i.y+n*d)))}return r}function z1(e,t,r,o,i,a,s,n=[]){let l=R2(t,o,i,s),d=w4(t,o,i,s),h=L4(t,d,a),c=Math.max(0,e.population)*kl,k=y4(t,h,c/ul,a),p=u4(o,i,r,e.water,n),f=M4(t,r,h),m=[];E2(k,0,h,f,a,m);let v=no(e.biome,e.biome==="desert"||e.freshwaterIrrigation===!0);if(!v.length)return{blocks:[],edges:[],outerRadius:l,regionPolygon:k};let L=[],w=l,M=0;for(let x of m){a.float();let b=a.float(),u=a.float(),P=O1(x,h);if(P.length<3)continue;let C=Yn(P,zs);if(C.length<3||$e(C)<js||u<_l&&C.some(nt=>H1(nt,k)<=zs+Rl))continue;let Q=b4(C,p);if(Q.length<3)continue;let R=$e(Q);if(R<js)continue;let V=vs(Q),j=Ji(Q,V),F=Ji(Q,V+90),K=j.hi-j.lo,H=F.hi-F.lo;if(!(K>0)||H<El*K)continue;let X=fe(V+b*$s-$s/2);L.push({id:`field:P${M}`,furlongId:`furlong:${Math.floor(pt(t.centre,co(Q))/30)}`,glyph:v[M%v.length],polygon:Q,furrowBearingDeg:X,areaM2:R}),M+=1;for(let nt of Q)w=Math.max(w,A(t.centre,nt))}return{blocks:L,edges:[],outerRadius:w,regionPolygon:k,...e.flags.walls?{innerBoundary:h}:{}}}function V1(e,t,r,o,i,a,s,n,l=0){let d=new Map,h=24;function c(p,f,m){if(!p.length)return;let v=Math.floor((Math.min(...p.map(x=>x.x))-f-l)/h),L=Math.floor((Math.max(...p.map(x=>x.x))+f+l)/h),w=Math.floor((Math.min(...p.map(x=>x.y))-f-l)/h),M=Math.floor((Math.max(...p.map(x=>x.y))+f+l)/h);for(let x=v;x<=L;x++)for(let b=w;b<=M;b++){let u=`${x},${b}`,P=d.get(u);P?P.push(m):d.set(u,[m])}}function k(p,f){c(p,f,(m,v=0)=>bt(m,p)||p.some((L,w)=>A(m,st(m,L,p[(w+1)%p.length]))<=Math.max(f,v)))}for(let p of t)for(let f=1;f<p.points.length;f++){let m=p.points[f-1],v=p.points[f],L=p.widthM/2+Math.max(3,Ol);c([m,v],L,(w,M=0)=>A(w,st(w,m,v))<=L+M)}for(let p of r){let f=wt(p),m=Math.hypot(f.halfW,f.halfD)+3;c([new Z(f.center.x-m,f.center.y-m),new Z(f.center.x+m,f.center.y+m)],0,(v,L=0)=>gi(v,f,Math.max(1.5,L)))}for(let p of o)k(p.polygon,1.5);for(let p of i)k(p.polygon,1.5);for(let p of n)k(p,3);return(p,f=0)=>{if(Tt(a,p),A(p,e.centre)<Ct(e)+Math.max(1.5,f)||d.get(`${Math.floor(p.x/h)},${Math.floor(p.y/h)}`)?.some(m=>m(p,f)))return!0;for(let m of a)if(bt(p,m))return!0;return!!(f>0&&be(a).some(([m,v])=>A(p,st(p,m,v))<f)||A(p,e.centre)<=s&&be(a).some(([m,v])=>A(p,st(p,m,v))<=Hl))}}function S4(e,t){return e<t?Al:0}function Oa(e,t){let r=_t[e]?.footprint?.[0]??1,o=fr[e]?.bounds??[8,8,56,56];return Math.max(32-o[0],32-o[1],o[2]-32,o[3]-32)*r/64*t}function j1(e,t,r){let o=Math.floor(e),i=Math.floor(t),a=(d,h)=>{let c=Math.imul(d,374761393)^Math.imul(h,668265263)^r;return c=Math.imul(c^c>>>13,1274126177),((c^c>>>16)>>>0)/4294967296},s=d=>d*d*(3-2*d),n=s(e-o),l=s(t-i);return(a(o,i)*(1-n)+a(o+1,i)*n)*(1-l)+(a(o,i+1)*(1-n)+a(o+1,i+1)*n)*l}function $1(e,t,r,o,i,a,s,n,l,d,h=[]){let c=n.plus(Ds),k=c.maxM;if(!(k>0))return[];let p=Math.max(...Rr(e.biome,!0).map(C=>Oa(C,ca))),f=V1(t,r,o,i,a,e.water,l,h,p),m=be(e.water),v=d.getSeed(),L=C=>vo(e.biome,C.x,C.y,v,d.float(),m.some(([Q,R])=>A(C,st(C,Q,R))<15)),w=[],M=Math.max(0,Math.ceil(s.maxM/xr));for(let C=-M;C<=M;C++)for(let Q=-M;Q<=M;Q++){let R=new Z(t.centre.x+C*xr,t.centre.y+Q*xr),V=new Z(R.x+xr/2,R.y+xr/2),j=S4(A(V,t.centre),s.at(V));if(!(d.float()<j))continue;let K=d.float(),H=d.float(),X=new Z(R.x+K*xr,R.y+H*xr),nt=L(X),mt=ni+d.float()*(ca-ni),O=`veg:${C}x${Q}`;if(f(X,Oa(nt,mt)))continue;w.push({id:O,glyph:nt,position:X,scale:mt});let[Y,rt]=Tl,yt=d.int(Y,rt);for(let B=1;B<=yt;B++){let U=d.float()*zl,$=d.float()*2*Math.PI,J=U*Math.sin($),lt=-U*Math.cos($),xt=new Z(X.x+J,X.y+lt);f(xt,Oa(nt,mt))||w.push({id:`${O}:${B}`,glyph:nt,position:xt,scale:mt})}}let x=e.biome==="desert"?6:e.biome==="tundra"?4.8:3.8,b=e.biome==="desert"?.64:e.biome==="coastal"?.56:e.biome==="tundra"?.46:e.biome==="tropical"?.3:.36,u=Math.floor(d.float()*4294967296),P=Math.ceil(k/x);for(let C=-P;C<=P;C++)for(let Q=-P;Q<=P;Q++){let R=new Z(t.centre.x+(C+.15+d.float()*.7)*x,t.centre.y+(Q+.15+d.float()*.7)*x),V=A(R,t.centre);if(V<s.at(R)||V>c.at(R))continue;let j=Math.max(0,(V-n.at(R))/Ds);if(.75*j1(R.x/48,R.y/48,u)+.25*j1(R.x/19,R.y/19,u^1540483477)<b+j*.48||f(R))continue;let K=L(R),H=ni+d.float()*(ca-ni);f(R,Oa(K,H))||w.push({id:`wood:${C}x${Q}:0`,position:R,glyph:K,scale:H})}return w}function C4(e,t,r){let[o,i]=re(e.glyph),a=e.sizeFactor,s=1+(r.float()-.5)*2*N3,n=pe(e.glyph,[o,i]).width,l=t.frontageM/(n*a),d=Math.min(Rs,Math.max(D3,l>1.6?Rs:Math.min(1,l))),h=a*s*d;return[o*h,i*h]}function _o(e,t,r=0,o=!1){let i=a3(e);return i==="invariant"?0:i==="snap-cardinal"?fe(Math.round((t+180)/90)*90):i!=="free"?fe(t+180):fe(t+180+(o?90:0)+r)}function N1(e,t,r,o=!0){let i=C4(e,t,r),a=r.float()*F3,s=Lt(t.bearingDeg),n=new Z(-s.x,-s.y),l=(i[1]-pe(e.glyph,i).depth)/2,d=a+i[1]/2-l,h=(r.float()*2-1)*G3,c=r.bool(W3)&&o;return{id:_a(t.id),lotId:t.id,glyph:e.glyph,position:new Z(t.front.x+n.x*d,t.front.y+n.y*d),bearingDeg:_o(e.glyph,t.bearingDeg,h,c),footprint:i,occupancy:Math.round(e.occupancy*e.sizeFactor)}}function Q2(e){let t=pe(e.glyph,e.footprint),r=Lt(e.bearingDeg);return{tangent:new Z(-r.y,r.x),normal:r,halfW:t.width/2,halfD:t.depth/2}}var I2=.05;function B4(e,t){let r=Q2(e),o=Q2(t),i=new Z(t.position.x-e.position.x,t.position.y-e.position.y);for(let a of[r.tangent,r.normal,o.tangent,o.normal]){let s=Math.abs(i.x*a.x+i.y*a.y),n=Math.abs(r.tangent.x*a.x+r.tangent.y*a.y)*r.halfW+Math.abs(r.normal.x*a.x+r.normal.y*a.y)*r.halfD,l=Math.abs(o.tangent.x*a.x+o.tangent.y*a.y)*o.halfW+Math.abs(o.normal.x*a.x+o.normal.y*a.y)*o.halfD;if(s>=n+l-I2)return!1}return!0}function E4(e,t){if(Tt(t,e.position,Math.hypot(...e.footprint)/2),t.length===0)return!1;let r=pe(e.glyph,e.footprint),o=r.width/2,i=r.depth/2,a=e.bearingDeg*Math.PI/180,s=Math.cos(a),n=Math.sin(a),l=(h,c)=>new Z(e.position.x+h*s-c*n,e.position.y+h*n+c*s),d=[l(-o,-i),l(o,-i),l(o,i),l(-o,i)];if(kt(e.position,t)||d.some(h=>kt(h,t)))return!0;for(let h=0;h<d.length;h++){let c=d[h],k=d[(h+1)%d.length];for(let p of t)for(let f=0;f<p.length;f++)if(Wt(c,k,p[f],p[(f+1)%p.length]))return!0}return!1}function Ie(e,t){let r=Q2(e);for(let o of t){let i=o.widthM/2;for(let a=1;a<o.points.length;a++){let s=st(e.position,o.points[a-1],o.points[a]),n=s.x-e.position.x,l=s.y-e.position.y,d=Math.abs(n*r.tangent.x+l*r.tangent.y),h=Math.abs(n*r.normal.x+l*r.normal.y);if(d<r.halfW+i-I2&&h<r.halfD+i-I2)return!0}}return!1}var _4=[0,.25,-.25,.45,-.45],R4=[0,.15,-.15,.25,-.25,.35,-.35,.45,-.45,.5,-.5];function D1(e,t,r,o,i=[],a,s=!1,n=[]){let l=Eo(e),d=new Set(n.map(m=>m.lotId)),h=new Set,c=[...n],k=n.reduce((m,v)=>m+v.occupancy,0),p=(m,v)=>{let L=Lt(v.bearingDeg),w=new Z(-L.y,L.x),M=0,x=0,b=0;for(let u of s?R4:_4){let P=u*v.frontageM,C=u===0?m:{...m,position:new Z(m.position.x+w.x*P,m.position.y+w.y*P)};if(Ie(C,i)){M++;continue}if(E4(C,r.water)){b++;continue}if(c.some(Q=>B4(C,Q))){x++;continue}return C}return b>=M&&b>=x?"in-water":M>=x?"lane-intrusion":"building-overlap"},f=m=>typeof m!="string";for(let m of t.filter(v=>v.cap==="one"))for(let v of l){if(d.has(v.id)||!r2(m,r,v.frontageM))continue;let L=p(N1(m,v,o),v);if(f(L)){c.push(L),d.add(v.id),h.add(m.glyph),a?.set(v.id,"seated"),k+=L.occupancy;break}}for(let m of l){if(k>=r.population)break;if(d.has(m.id))continue;let v=x5(t,r,m.frontageM,h,o);if(!v){a?.set(m.id,"no-deck-entry");continue}let L=p(N1(v,m,o),m);if(!f(L)){a?.set(m.id,L);continue}c.push(L),d.add(m.id),a?.set(m.id,"seated"),k+=L.occupancy}if(a)for(let m of l)a.has(m.id)||a.set(m.id,"census-satisfied");return{buildings:c,housed:k,unhoused:Math.max(0,r.population-k)}}function A2(e,t){let r=1/0;for(let o=1;o<t.points.length;o++)r=Math.min(r,A(e,st(e,t.points[o-1],t.points[o])));return r}function Q4(e,t){let r=1/0,o=null;for(let i=1;i<t.points.length;i++){let a=t.points[i-1],s=t.points[i],n=A(e,st(e,a,s));n<r&&(r=n,o=[a,s])}return o}function I4(e,t,r){let o=Fe(r,"sm-well");if(!ce(o))return null;let[i,a]=re(o),s=Math.max(i,a),n=w=>w.widthM/2+s/2+jl,l=t.map(w=>({lane:w,distance:A2(e.centre,w),clearance:n(w)})).filter(w=>w.distance<w.clearance).sort((w,M)=>w.distance-M.distance);if(l.length===0)return{id:"poi:well",kind:"well",glyph:o,position:e.centre,bearingDeg:0};let d=Q4(e.centre,l[0].lane);if(!d)return{id:"poi:well",kind:"well",glyph:o,position:e.centre,bearingDeg:0};let[h,c]=d,k=We(c.x-h.x,c.y-h.y),p=new Z(-k.y,k.x),f=Ct(e)*$l,m=w=>t.every(M=>A2(w,M)>=n(M)),v=w=>{for(let M=Fs;M<=f+1e-9;M+=Fs){let x=new Z(e.centre.x+p.x*w*M,e.centre.y+p.y*w*M);if(m(x))return x}return null},L=v(1)??v(-1)??e.centre;return{id:"poi:well",kind:"well",glyph:o,position:L,bearingDeg:0}}function A4(e,t){let r=new Z(e.x-t.center.x,e.y-t.center.y),o=Math.max(-t.halfW,Math.min(t.halfW,r.x*t.tangent.x+r.y*t.tangent.y)),i=Math.max(-t.halfD,Math.min(t.halfD,r.x*t.normal.x+r.y*t.normal.y));return new Z(t.center.x+t.tangent.x*o+t.normal.x*i,t.center.y+t.tangent.y*o+t.normal.y*i)}function Ro(e,t,r){if(X5(r,e,t),r.length<2)return!1;if(bt(e,r))return!0;for(let o=0;o<r.length;o++){let i=r[o],a=r[(o+1)%r.length];if(A(e,st(e,i,a))<t)return!0}return!1}function Zi(e,t,r,o,i,a){for(let s of r)if(A2(e,s)<t+s.widthM/2)return!1;for(let s of o)if(A(e,A4(e,wt(s)))<t)return!1;for(let s of i)if(Ro(e,t,s.polygon))return!1;for(let s of a)if(Ro(e,t,s.polygon))return!1;return!0}function T4(e,t,r,o,i,a,s,n,l,d="temperate"){if(!l.bool(Nl))return null;let h=Kt(d),c=["lintelled-ring","broken-ring","double-ring","horseshoe","oval-ring","ruined-ring"],k=l.float(),p=`sm-henge-${c[Math.floor(k*c.length)]}-${"abc"[Math.floor(k*18)%3]}${h==="temperate"?"":`--${h}`}`;if(!ce(p))return null;let f=t*Dl;for(let m=0;m<Fl;m++){let v=l.int(0,360),L=Lt(v),w=new Z(e.centre.x+L.x*f,e.centre.y+L.y*f);if(!(!Zi(w,go,r,o,i,a)||s.some(x=>Ro(w,go,x))||n.some(x=>A(w,x.position)<go+Gl)))return{id:"poi:stone-circle",kind:"stone-circle",glyph:p,position:w,bearingDeg:0}}return null}function O4(e,t){let r=null;Tt(t,e);for(let o of Pr(t)){if(o.length<2)continue;let i=o,a=gt(i);for(let s=0;s<o.length-1;s++){let n=i[s],l=i[s+1],d=st(e,n,l),h=A(e,d);(!r||h<r.distance)&&(r={ring:o,acc:a,s:a[s]+A(n,d),point:d,distance:h})}}return r}function H4(e,t,r){let o=Lt(t),i=new Z(-o.y,o.x),a=new Z(e.x+i.x*.5,e.y+i.y*.5);return kt(a,r)?new Z(-i.x,-i.y):i}function z4(e,t){let r=[0];for(let o=t;o<=e+1e-9;o+=t)r.push(o,-o);return r}function V4(e,t,r,o,i,a,s){if(!e.flags.port||e.water.length===0)return null;let n=O4(t.centre,e.water);if(!n||n.distance>r)return null;let l="sm-boathouse--coastal";if(!ce(l))return null;let[d,h]=re(l),c=Math.max(d,h)/2,k=h/2-h*ql,p=n.acc[n.acc.length-1],f=n.ring;for(let m of z4(Wl,Ul)){let v=n.s+m;if(v<0||v>p)continue;let L=ut(f,n.acc,v),w=H4(L.p,L.dirDeg,e.water),M=new Z(L.p.x+w.x*k,L.p.y+w.y*k);if(!Zi(M,c,o,i,a,s))continue;let x=pt(M,L.p),b=new Z(-w.x,-w.y),u=M.x+b.x*(h/2),P=M.y+b.y*(h/2),C=h*Kl,Q=C/Gs,R=0;for(let j=pa;j<=Q;j+=pa){let F=new Z(u+b.x*j,P+b.y*j);if(!kt(F,e.water))break;R=j}let V=R>=Q?C:R*Gs;return V<pa?{id:"poi:boathouse",kind:"boathouse",glyph:l,position:M,bearingDeg:_o(l,x)}:{id:"poi:boathouse",kind:"boathouse",glyph:l,position:M,bearingDeg:_o(l,x),jetty:{from:new Z(u,P),to:new Z(u+b.x*V,P+b.y*V),widthM:d*Yl}}}return null}function F1(e,t,r,o,i,a,s,n,l,d,h){let c=[];if(e.population>=Vl){let f=I4(t,r,e.biome);f&&c.push(f)}let k=h??T4(t,n,r,o,i,a,e.water,s,d,e.biome);k&&c.push(k);let p=V4(e,t,l,r,o,i,a);return p&&c.push(p),c}function G1(e,t,r,o,i,a){if(!e.flags.temple||!ce("sm-stone-circle"))return null;let s=go,n,l=Math.max(a+50,Ct(t)+60),d=r.length?r:[{id:"green",type:"footpath",widthM:1,points:[t.centre,new Z(t.centre.x+Ct(t),t.centre.y)]}];for(let h of[...d].sort((c,k)=>c.id.localeCompare(k.id))){let c=gt(h.points);for(let k=0;k<=c.at(-1);k+=6){let p=ut(h.points,c,k).p;if(A(p,t.centre)>l)continue;let f=ut(h.points,c,Math.max(0,k-.5)).p,m=ut(h.points,c,Math.min(c.at(-1),k+.5)).p,v=A(f,m);if(!(v<1e-6))for(let L of[-1,1])for(let w of[0,8,16]){let M=s+h.widthM/2+3+w,x=-(m.y-f.y)/v*L,b=(m.x-f.x)/v*L,u=new Z(p.x+x*M,p.y+b*M);if(A(u,t.centre)<Ct(t)+s+2)continue;let P=A(u,t.centre)+w*.5;if(n&&P>=n.score||!Zi(u,s+2,r,o,i,[])||e.water.some(V=>Ro(u,s+2,V)))continue;let C=new Z(u.x-x*(s+1),u.y-b*(s+1)),Q=!0,R=Math.max(1,Math.ceil(A(p,C)));for(let V=0;V<=R&&Q;V++){let j=new Z(p.x+(C.x-p.x)*V/R,p.y+(C.y-p.y)*V/R);Q=Zi(j,.7,[],o,i,[])&&!e.water.some(F=>Ro(j,.7,F))}Q&&(n={score:P,poi:{id:"poi:stone-circle",kind:"stone-circle",glyph:"sm-stone-circle",position:u,bearingDeg:0},clearing:Array.from({length:24},(V,j)=>new Z(u.x+Math.cos(j*Math.PI/12)*(s+2)/Math.cos(Math.PI/24),u.y+Math.sin(j*Math.PI/12)*(s+2)/Math.cos(Math.PI/24))),access:{id:"poi:stone-circle/access",type:"footpath",routeRole:"street",widthM:1.4,surfaceWidthM:1,setbackM:.3,points:[p,C],...h.id!=="green"?{parentId:h.id}:{}}})}}}if(n){let h=Math.abs(Math.round(n.poi.position.x*127+n.poi.position.y*311)),c=["lintelled-ring","broken-ring","double-ring","horseshoe","oval-ring","ruined-ring"][h%6],k=Kt(e.biome);n.poi.glyph=`sm-henge-${c}-${"abc"[Math.floor(h/6)%3]}${k==="temperate"?"":`--${k}`}`}return n??null}function W1(e){let{site:t,green:r,lanes:o,lots:i,buildings:a,builtRadiusM:s,f0:n,rng:l}=e,d=R1(t.biome,t.population,l),h=new Set(a.map(F=>F.lotId)),c=_1(i,a,r,o,t.water,s,n),k=R2(r,i,c,h),p=G1(t,r,o,i.filter(F=>h.has(F.id)),c,k),f=p?[p.access]:[],m=[...o,...f],v=p?[p.clearing]:[],{blocks:L,edges:w,outerRadius:M,regionPolygon:x,innerBoundary:b}=z1(t,r,m,i,c,l,h,v),u=xi(r.centre,Ta(i,c,h),Ct(r)),P=[];for(let F=0;F<x.length;F++){let K=x[F],H=x[(F+1)%x.length],X=Math.max(1,Math.ceil(Math.hypot(H.x-K.x,H.y-K.y)/5));for(let nt=0;nt<X;nt++)P.push(new Z(K.x+(H.x-K.x)*nt/X,K.y+(H.y-K.y)*nt/X))}let C=xi(r.centre,[...Ta(i,c,h),...L.flatMap(F=>F.polygon),...P],Ct(r)),Q=k*al,R=$1(t,r,m,i.filter(F=>h.has(F.id)),c,L,u,C,Q,l,v),V=Math.max(M,k),j=F1(t,r,m,i,c,L,R,V,Q,l,p?.poi);return{edgeStyle:d,crofts:c,fields:L,fieldEdges:w,vegetation:R,pois:j,accessLanes:f,diagnostics:t.flags.temple&&!p?["temple: no dry, accessible clearing could accommodate the requested henge"]:[],...b?{wall:u1(g1(a,j,b),m,t.water,t.biome,v)}:{}}}function U1(e){let t=[e.greenCentre.x],r=[e.greenCentre.y],o=i=>{t.push(i.x),r.push(i.y)};for(let i of e.buildings)o(i);for(let i of e.dressing)o(i);for(let i of e.lanes)if(!Ot(i.id))for(let a of i.points)o(a);return{minX:Math.min(...t)-di,minY:Math.min(...r)-di,maxX:Math.max(...t)+di,maxY:Math.max(...r)+di}}function q1(e,t){let r=[];for(let o of e){if(!Ot(o.id)){r.push(o);continue}let i=t1(o.points,t);i.length>=2&&r.push({...o,points:i})}return r}function K1(e){e.cut.clear(),e.fates.clear(),e.staleAfterTrim.clear(),e.convergeDetail.clear()}function j4(e,t){if(e.length===0)return t>0?[[0,t]]:[];let r=[...e].sort((s,n)=>s[0]-n[0]),o=[];for(let[s,n]of r){let l=o[o.length-1];l&&s<=l[1]?l[1]=Math.max(l[1],n):o.push([s,n])}let i=[],a=0;for(let[s,n]of o)s>a&&i.push([a,Math.min(s,t)]),a=Math.max(a,n);return a<t&&i.push([a,t]),i.filter(([s,n])=>n>s)}function $4(e,t,r){let o=1/0,i=0;for(let a=1;a<e.length;a++){let s=st(r,e[a-1],e[a]),n=A(r,s);n<o&&(o=n,i=t[a-1]+A(e[a-1],s))}return i}function N4(e){return e.flatMap(t=>t.points.slice(1).flatMap((r,o)=>{let i=t.points[o],a=A(i,r);if(a<=0)return[];let s=new Z((r.x-i.x)/a,(r.y-i.y)/a);return[{laneId:t.id,box:{center:new Z((i.x+r.x)/2,(i.y+r.y)/2),tangent:s,normal:new Z(-s.y,s.x),halfW:a/2,halfD:t.widthM/2}}]}))}function D4(e,t){let r=e.depthM,o=wt(e);for(let{laneId:i,box:a}of t)if(i!==e.laneId){if(r<Re)return r;oe(o,a)&&(r=we({...e,depthM:r},a),o=wt({...e,depthM:r}))}return r}function Y1(e){let{lanes:t,green:r,standing:o,builtRadiusM:i,f0:a,depthM:s,floorM:n,maxFrontageM:l,reachOf:d,pass:h}=e,c=N4(t),k=[],p=new Map,f=o.map(w=>({lot:w,depth:w.depthM})),m=new Set,v=w=>wt({...w.lot,depthM:w.depth}),L=w=>Math.hypot(w.lot.frontageM/2,w.depth);for(let w of t){let M=Be(w),x=d(w);for(let b of[1,-1]){let u=Ze(w.points,M,b);if(u.length<2)continue;let P=gt(u),C=P[P.length-1];if(C<=n)continue;let Q=[];for(let V of o){if(V.laneId!==w.id||V.side!==b)continue;let j=$4(u,P,V.front);Q.push([j-V.frontageM/2-Mo,j+V.frontageM/2+Mo])}let R=0;for(let[V,j]of j4(Q,C)){if(j-V<n)continue;let F=V;for(;F+n<=j;){let K=ut(u,P,F),H=A(K.p,r.centre),X=Math.max(n,l),nt=Math.min(X,Math.max(n,a*ha,bi(H,i,a)),j-F),mt=n/2;if(nt<n)break;let O=ut(u,P,F+nt/2);if(A(O.p,r.centre)>x(O.p)){F+=mt;continue}let Y=(O.dirDeg+(b===1?-90:90)+360)%360,rt={id:r1(w.id,b,R,h),laneId:w.id,side:b,front:O.p,bearingDeg:Y,frontageM:nt,depthM:s,score:0},yt=f.filter(lt=>A(rt.front,lt.lot.front)<=Math.hypot(nt/2,s)+L(lt)),B=D4(rt,c);for(let lt of yt){if(B<Re)break;let xt=v({...lt,depth:Math.min(lt.depth,Re)});oe(wt({...rt,depthM:B}),xt)&&(B=we({...rt,depthM:B},xt))}if(B<Re){F+=mt;continue}let U={...rt,depthM:B},$=wt(U);for(let lt of yt){if(!oe(v(lt),$))continue;let xt=Math.max(Math.min(lt.depth,Re),we({...lt.lot,depthM:lt.depth},$));lt.depth=xt,m.has(lt.lot.id)||p.set(lt.lot.id,xt)}let J={lot:U,depth:U.depthM};k.push(J),m.add(U.id),f.push(J),R++,F+=nt+Mo}}}}return{added:k.map(w=>({...w.lot,depthM:w.depth})),trimmed:p}}function Pi(e){let{lot:t,glyph:r,occupancy:o}=e,i=re(r),a=Lt(t.bearingDeg+180),s=pe(r,i).depth/2+.5;return{id:_a(t.id),lotId:t.id,glyph:r,footprint:i,occupancy:o,position:new Z(t.front.x+a.x*s,t.front.y+a.y*s),bearingDeg:_o(r,t.bearingDeg,0,!1)}}function F4(e){return e.biome==="temperate"&&e.population>=700?{kind:"faith",glyph:"sm-temple",minPop:700,occupancy:0}:{kind:"faith",glyph:Fe(e.biome,"sm-chapel"),minPop:300,occupancy:0}}function X1(e){return[F4(e),{kind:"inn",glyph:Fe(e.biome,"sm-inn"),minPop:180,occupancy:6},{kind:"manor",glyph:Fe(e.biome,"sm-house-large-tiled"),minPop:250,occupancy:6}]}function G4(e){return Be(e)}function W4(e,t){let r=new Z(e.x-t.center.x,e.y-t.center.y),o=Math.max(-t.halfW,Math.min(t.halfW,r.x*t.tangent.x+r.y*t.tangent.y)),i=Math.max(-t.halfD,Math.min(t.halfD,r.x*t.normal.x+r.y*t.normal.y));return new Z(t.center.x+t.tangent.x*o+t.normal.x*i,t.center.y+t.tangent.y*o+t.normal.y*i)}function U4(e,t){let r=W4(t.centre,e);return A(r,t.centre)<Ct(t)}function J1(e){let{center:t,tangent:r,normal:o,halfW:i,halfD:a}=e,s=(n,l)=>new Z(t.x+r.x*i*n+o.x*a*l,t.y+r.y*i*n+o.y*a*l);return[t,s(1,1),s(1,-1),s(-1,1),s(-1,-1)]}function q4(e,t){if(Tt(t,e.center,Math.hypot(e.halfW,e.halfD)),t.length===0)return!1;let[r,o,i,a,s]=J1(e);if([r,o,i,s,a].some(l=>kt(l,t)))return!0;let n=[o,i,s,a];for(let l=0;l<n.length;l++){let d=n[l],h=n[(l+1)%n.length];for(let c of t)for(let k=0;k<c.length;k++)if(Wt(d,h,c[k],c[(k+1)%c.length]))return!0}return!1}function K4(e,t,r){for(let o of t){if(o.id===r)continue;let i=o.widthM/2+w5;for(let a of J1(e))for(let s=1;s<o.points.length;s++)if(A(a,st(a,o.points[s-1],o.points[s]))<i)return!0}return!1}function Y4(e,t,r,o){return`landmark:${e}:${t}:${r===1?"R":"L"}${o}`}function X4(e,t,r,o,i,a){let[s,n]=re(e.glyph),[l,d]=Js[e.kind],h=l*i,c=d*i,k;for(let p of t){let f=G4(p);for(let m of[1,-1]){let v=Ze(p.points,f,m);if(v.length<2)continue;let L=gt(v),w=L[L.length-1],M=0;for(let x=t2;x<=w;x+=t2,M++){let{p:b,dirDeg:u}=ut(v,L,x),P=A(b,r.centre);if(P<h||P>c)continue;let C=(u+(m===1?-90:90)+360)%360,Q={id:Y4(e.kind,p.id,m,M),laneId:p.id,side:m,front:b,bearingDeg:C,frontageM:s,depthM:n,score:0},R=wt(Q);if(U4(R,r)||q4(R,o.water)||a.some(F=>oe(R,F))||K4(R,t,p.id))continue;let V=Ce(p.id),j=e.kind==="faith"?A(R.center,r.centre):e.kind==="inn"?(V?0:i*4)+ft(p.type)*2+Math.min(P*.6,Math.abs(P-i*.75)):Math.abs(P-i*1.05);k&&j>=k.score||Ie(Pi({lot:Q,glyph:e.glyph,kind:e.kind,occupancy:e.occupancy}),t)||(k={lot:Q,score:j})}}}return k?.lot??null}function td(e){return e.startsWith("landmark:")}function ed(e){return X1(e).filter(t=>e.population>=t.minPop&&ce(t.glyph)).length}function Ha(e,t,r,o,i){let a=[],s=[],n=[],l=[...r].sort((d,h)=>d.id<h.id?-1:d.id>h.id?1:0);for(let d of X1(e)){if(e.population<d.minPop)continue;if(!ce(d.glyph)){a.push(`landmark ${d.kind}: glyph "${d.glyph}" not in manifest, skipped`);continue}let h=X4(d,l,t,e,o,n);if(!h){a.push(`landmark ${d.kind}: no site cleared band [${Js[d.kind].join(", ")}] x builtRadiusM, green, water and prior claims across ${r.length} lane(s), skipped`);continue}n.push(wt(h)),s.push({lot:h,glyph:d.glyph,occupancy:d.occupancy,kind:d.kind})}return{landmarks:s,diagnostics:a}}var J4=.15,tc=8,ec=1.35,rd=24;function ad(e,t,r=[],o=[]){let i=new Map([["green",t.centre]]),a=[],s=new Map([["green",[]]]),n=new Map,l=Ct(t),d=p=>{let f=A(p,t.centre)<=l+1e-6?"green":`${Math.round(p.x*1e4)},${Math.round(p.y*1e4)}`;return i.has(f)||(i.set(f,p),s.set(f,[])),f},h=(p,f,m,v)=>{p!==f&&(a.push({from:p,to:f,length:m,laneId:v}),s.get(p).push({node:f,length:m,laneId:v}),s.get(f).push({node:p,length:m,laneId:v}))},c=e.flatMap(p=>p.points.length?[p.points[0],p.points[p.points.length-1]].map(f=>({p:f,laneId:p.id})):[]),k=new Map(o.map(p=>[p.id,p]));for(let p of r)k.get(p.lotId)?.laneId==="green"&&n.set(p.id,"green");for(let p of e){if(p.points.length<2)continue;let f=gt(p.points),m=p.points.map((w,M)=>({s:f[M],p:w})),v=w=>{let M={s:0,p:p.points[0],d:1/0};for(let x=1;x<p.points.length;x++){let b=st(w,p.points[x-1],p.points[x]),u=A(w,b);u<M.d&&(M={p:b,s:f[x-1]+A(p.points[x-1],b),d:u})}return M};for(let w of c){if(w.laneId===p.id)continue;let M=v(w.p);M.d<=J4&&(m.push(M),h(d(M.p),d(w.p),M.d,p.id))}let L=v(t.centre);L.d<=l+Qt(p).surfaceM/2+1e-6&&(m.push(L),h("green",d(L.p),Math.max(0,L.d-l),p.id));for(let w of r){if(k.get(w.lotId)?.laneId!==p.id)continue;let M=v(w.position);m.push(M),n.set(w.id,d(M.p))}m.sort((w,M)=>w.s-M.s);for(let w=1;w<m.length;w++)h(d(m[w-1].p),d(m[w].p),m[w].s-m[w-1].s,p.id)}return{points:i,edges:a,adjacency:s,buildings:n}}function od(e,t=new Set){let r=new Map,o=0;for(let i of e.points.keys()){if(r.has(i))continue;let a=[i];for(r.set(i,o);a.length;)for(let s of e.adjacency.get(a.pop())??[])t.has(s.laneId)||r.has(s.node)||(r.set(s.node,o),a.push(s.node));o++}return r}function id(e,t,r=new Set){let o=new Map([[t,0]]),i=[[t,0]],a=s=>{let n=i.length;for(i.push(s);n>0;){let l=n-1>>1;if(i[l][1]<=s[1])break;i[n]=i[l],n=l}i[n]=s};for(;i.length;){let[s,n]=i[0],l=i.pop();if(i.length){let d=0;for(;d*2+1<i.length;){let h=d*2+1;if(h+1<i.length&&i[h+1][1]<i[h][1]&&h++,i[h][1]>=l[1])break;i[d]=i[h],d=h}i[d]=l}if(n===o.get(s))for(let d of e.adjacency.get(s)??[]){if(r.has(d.laneId))continue;let h=n+d.length;h<(o.get(d.node)??1/0)&&(o.set(d.node,h),a([d.node,h]))}}return o}function T2(e,t,r,o){let i=ad(e,t,r,o),a=od(i),s=new Set(r.map(c=>o.find(k=>k.id===c.lotId)?.laneId)),n=new Set(["green",...i.buildings.values()]);for(let c of i.edges)Ce(c.laneId)&&(n.add(c.from),n.add(c.to));let l=new Set,d=e.filter(c=>!Ce(c.id)&&!s.has(c.id)).sort((c,k)=>Gt(k.points)-Gt(c.points)||c.id.localeCompare(k.id));for(let c of d){l.add(c.id);let k=od(i,l),p=new Map,f=!0;for(let m of n){let v=a.get(m),L=k.get(m);if(v===void 0||L===void 0){f=!1;break}if(p.has(v)&&p.get(v)!==L){f=!1;break}p.set(v,L)}f||l.delete(c.id)}return e.filter(c=>!l.has(c.id)).map(c=>c.parentId&&l.has(c.parentId)?{...c,parentId:void 0}:c)}function sd(e,t,r,o,i){let a=ad([...e,t],r,o,i),s=t.points[0],n=t.points[t.points.length-1],l=L=>[...a.points].reduce((w,[M,x])=>A(L,x)<w.d?{id:M,d:A(L,x)}:w,{id:"green",d:1/0}).id,d=l(s),h=l(n),c=new Set([t.id]),k=id(a,d,c),p=id(a,h,c),f=k.get(h)??1/0,m=Gt(t.points);if(!Number.isFinite(f)||f-m<tc||f<m*ec)return!1;let v=[...a.buildings.values()];return v.some(L=>(k.get(L)??1/0)<=rd)&&v.some(L=>(p.get(L)??1/0)<=rd)}function rc(e){return e.float()*2-1}function oc(e,t,r){if(!(r>0))return 0;let o=Math.min(1,Math.max(0,t/r));return e*h3*o*o}function to(e,t,r,o){let i=Lt(t),a=new Z(-i.y,i.x),s=rc(o),n=[];for(let l=0;l<=r;l+=Wr){let d=oc(s,l,r);n.push(new Z(e.x+i.x*l+a.x*d,e.y+i.y*l+a.y*d))}return n}function O2(e,t,r,o,i){let a=Lt(t),s=0;for(let n=0;n<=ri;n+=Wr){let l=new Z(e.x+a.x*n,e.y+a.y*n);if(!Si(r,o,i,l))break;s=n}return Math.min(ri,Math.max(De,s))}function Si(e,t,r,o){let i=A(o,e.centre);return i<1e-9?!0:i<=t.ringAt(r,pt(e.centre,o))}function ld(e,t){let r=t.points[0],o=A(r,e.centre);for(let i of t.points){let a=A(i,e.centre);a<o&&(o=a,r=i)}return r}var ic=1.5;function ac(e,t){return pt(e.centre,ld(e,t))}function Va(e){let t=Xo(e,"footpath");return ft(t)<ft("local")?"local":t}function sc(e,t){return t.parentId!==void 0?!1:A(ld(e,t),e.centre)<=Ct(e)*ic}function dd(e){let t=Math.PI*Math.max(0,e);return Math.min(M3,Math.max(y3,Math.round(t/L3)))}function nc(e){return 360/dd(e)}function hd(e,t){let r=Math.max(0,t-Ct(e));return Math.min(c3,Math.max(p3,r/3))}function lc(e,t){if(e.length===0)return t.int(0,360);let r=[...e].sort((s,n)=>s-n),o=r[r.length-1],i=r[0]+360-o;for(let s=1;s<r.length;s++){let n=r[s]-r[s-1];n>i&&(i=n,o=r[s-1])}let a=(t.float()-.5)*i*.5;return(o+i/2+a+360)%360}function kd(e){return Math.min(ri,Math.max(De,m3/2*e))}function dc(e,t,r){return r<q3?t:ft(e.type)<=ft("town")?t*w3:t}function z2(e,t,r,o){return i=>dc(e,r.at(pt(t.centre,i)),o)}function cd(e,t){return Math.sqrt(hc(e,t)*E3/Math.PI)*C3}function hc(e,t){return Math.max(1,e)*t/(2*B3)}function pd(e,t,r,o){let i=[];for(let a of e){let s=gt(a.points),n=s[s.length-1];if(n<o*1.25)continue;let l=o;for(;l<=n-o*.5;){let{p:d,dirDeg:h}=ut(a.points,s,l),c=A(d,t.centre);c<=r.at(pt(t.centre,d))&&!e.some(k=>A(k.points[0],d)<o*.45)&&i.push({parent:a,at:l/n,anchor:d,dirDeg:h,distToGreen:c}),l+=o}}return i.sort((a,s)=>a.distToGreen-s.distToGreen||a.parent.id.localeCompare(s.parent.id)||a.at-s.at),i}function V2(e,t,r,o=oi,i){let a=null,s=o;for(let n of e)if(!r.has(n.id))for(let l=1;l<n.points.length;l++){let d=st(t,n.points[l-1],n.points[l]),h=A(t,d);h<s&&(!i||u2(i,t,d))&&(s=h,a=d)}return a}function Bi(e,t){return t.length>0?[...e,...t]:e}function Sr(e,t,r,o){let i=e[0];for(let a=1;a<e.length;a++){let s=null;for(let n of t)for(let l=1;l<n.points.length;l++){let d=Wt(e[a-1],e[a],n.points[l-1],n.points[l]);if(!d||n.id===o&&A(i,d)<=S3)continue;let h=A(e[a-1],d);(!s||h<s.t)&&(s={q:d,t:h})}if(s)return[...e.slice(0,a),s.q]}return e}function za(e,t){for(let r=1;r<e.length;r++)for(let o=1;o<t.length;o++)if(Wt(e[r-1],e[r],t[o-1],t[o]))return!0;return!1}function j2(e,t){if(!t)return!1;let r=0;for(let o=1;o<e.length;o++)for(let i=1;i<t.points.length;i++)if(Wt(e[o-1],e[o],t.points[i-1],t.points[i])&&(r+=1,r>1))return!0;return!1}var kc=1;function fd(e,t){let r=e.points[e.points.length-1];for(let o of t)if(o.id!==e.id)for(let i=1;i<o.points.length;i++){let a=st(r,o.points[i-1],o.points[i]);if(A(r,a)<=kc)return!0}return!1}function $2(e,t){let r=Qe(e,t);return Math.min(r,180-r)}function Ci(e,t,r,o,i=!1){let a=t.filter(d=>d.id!==o);if(a.length===0)return!0;let s=gt(e),n=s[s.length-1],l=[];for(let d=0;d<=n;d+=Wr){let{p:h,dirDeg:c}=ut(e,s,d),k=1/0;for(let p of a)for(let f=1;f<p.points.length;f++)i&&$2(c,pt(p.points[f-1],p.points[f]))>x3||(k=Math.min(k,A(h,st(h,p.points[f-1],p.points[f]))));l.push(k)}return l.length===0?!0:(l.sort((d,h)=>d-h),l[Math.floor(l.length/2)]>=xs*r)}function nd(e,t,r,o,i,a,s,n=[]){let l=Bi(e,n),d=e.filter(h=>!Ce(h.id)&&h.points.length>=2&&Gt(h.points)<a&&Si(t,o,o.radiusM,h.points[h.points.length-1])&&Si(t,o,s,h.points[h.points.length-1])&&!fd(h,e)).sort((h,c)=>Gt(h.points)-Gt(c.points)||h.id.localeCompare(c.id));for(let h of d){let c=h.points.length,k=pt(h.points[c-2],h.points[c-1]),p=Sr(to(h.points[c-1],k,O2(h.points[c-1],k,t,o,s),i),l.filter(v=>v.id!==h.id),t);if(p.length<2)continue;let f=[...p];if(f[0]=new Z(p[0].x+(p[1].x-p[0].x)*.05,p[0].y+(p[1].y-p[0].y)*.05),!l.some(v=>{if(v.id===h.id)return!1;for(let L=1;L<f.length;L++)for(let w=1;w<v.points.length;w++)if(Wt(f[L-1],f[L],v.points[w-1],v.points[w]))return!0;return!1}))return h.points=[...h.points,...p.slice(1)],!0}return!1}function cc(e,t,r,o,i,a,s,n=[]){let l=Bi(e,n);if(e.filter(c=>sc(t,c)&&c.id.startsWith("lane-")).length<dd(o.radiusM)){let c=e.filter(k=>k.parentId===void 0).map(k=>ac(t,k));for(let k=0;k<36;k++){let p=Math.round(lc(c,i))%360;if(c.some(M=>Qe(p,M)<k3)||e.some(M=>M.id===y2(p)||M.id===Li(p)))continue;let m=Lt(p),v=new Z(t.centre.x+m.x*(t.diameter/2)*Ur,t.centre.y+m.y*(t.diameter/2)*Ur),L=.7+i.float()*.6,w=Sr(to(v,p,O2(v,p,t,o,a)*L,i),l,t);if(!(w.length<2||!Ci(w,e,s)))return e.push({id:Li(p),type:"local",points:w,widthM:ve("local")}),!0}}let d=pd(e,t,o,hd(t,o.radiusM)).filter(c=>Si(t,o,a,c.anchor));return(c=>{for(let k of c){if(N2(e,t,o,k.anchor,k.parent,s,n))return!0;let p=null,f=Math.max(1,Math.min(99,Math.round(k.at*100)));for(let P=0;P<99;P++){let C=1+(f-1+P)%99,Q=yi(k.parent.id,C/100);if(!e.some(R=>R.id===Q)){p=Q;break}}if(!p)continue;let m=i.bool(.5)?1:-1,v=(k.dirDeg+m*(70+i.int(0,31))+360)%360,L=Va(k.parent.type),w=to(k.anchor,v,O2(k.anchor,v,t,o,a),i),M=V2(e,w[w.length-1],new Set([k.parent.id]),oi,w[w.length-2]);M&&(w=[...w,M]);let x=w.length;w=Sr(w,l,t,k.parent.id),(M||w.length<x)&&(L=Xo(L,"footpath"));let b=M!==null||w.length<x,u=b?aa:De;if(!(w.length<2||Gt(w)<u)&&!(b?za(w,k.parent.points):j2(w,k.parent))&&Ci(w,e,s,k.parent.id,b))return e.push({id:p,type:L,points:w,widthM:ve(L),parentId:k.parent.id}),!0}return!1})(d)||nd(e,t,r,o,i,a*2,a,n)?!0:nd(e,t,r,o,i,1/0,a,n)}function pc(e,t,r){let o=[];for(let i of t){if(r.has(i.id))continue;let a=null;for(let s=1;s<i.points.length;s++){let n=st(e,i.points[s-1],i.points[s]),l=A(e,n);(!a||l<a.distance)&&(a={point:n,distance:l})}a&&o.push(a)}return o.sort((i,a)=>i.distance-a.distance)}function fc(e,t){for(let r of t)for(let o=1;o<e.length;o++)for(let i=1;i<r.points.length;i++)if(Wt(e[o-1],e[o],r.points[i-1],r.points[i]))return!0;return!1}function md(e,t,r=[],o,i=[]){let a=[...e],s=e.filter(n=>!Ce(n.id)&&n.points.length>=2).slice().sort((n,l)=>n.id.localeCompare(l.id));for(let n of s){if(fd(n,a))continue;let l=n.points[n.points.length-1];for(let d of pc(l,a,new Set([n.id]))){if(d.distance>P3)break;if(d.distance<aa)continue;let h=n.points[n.points.length-2],c=u2(h,l,d.point);if(!c&&Qe(pt(h,l),pt(l,d.point))>100)continue;let k=Lt(pt(h,l)),p=Math.min(6,d.distance/3),f=new Z(l.x+k.x*p,l.y+k.y*p),m=c?Xr([l,f,d.point]):[l,d.point];if(!m||!Jr(m,i)||fc(m,a)||A(d.point,t.centre)<=t.diameter/2)continue;let v={id:`${n.id}/c`,type:"footpath",points:m,widthM:ve("footpath"),parentId:n.id};if(!r.some(L=>Ie(L,[v]))&&!(o&&!sd(a,v,t,r,o))){a.push(v);break}}}return a}function mc(e,t,r,o){let i=Math.round(360/ii),a=new Array(i).fill(!1),s=n=>{let l=A(n,t.centre);l<1||l>r.ringAt(o,pt(t.centre,n))||(a[Math.floor(pt(t.centre,n)/ii)%i]=!0)};for(let n of e)for(let l=0;l<n.points.length;l++){if(s(n.points[l]),l===0)continue;let d=n.points[l-1],h=n.points[l],c=Math.max(1,Math.ceil(A(d,h)/4));for(let k=1;k<c;k++)s(new Z(d.x+(h.x-d.x)*k/c,d.y+(h.y-d.y)*k/c))}return a}function vc(e){let t=e.length;if(e.every(i=>!i))return{bisectorDeg:0,widthDeg:360};let r={start:0,len:0},o=0;for(;o<t*2;){if(e[o%t]){o+=1;continue}let i=o,a=0;for(;a<t&&!e[(i+a)%t];)a+=1;a>r.len&&(r={start:i%t,len:a}),o=i+a}return{bisectorDeg:(r.start+r.len/2)*ii%360,widthDeg:r.len*ii}}function wc(e,t,r,o){let i=null,a=o*li;for(let s=-a;s<=a;s+=Zs)for(let n=-a;n<=a;n+=Zs){let l=new Z(t.centre.x+s,t.centre.y+n);if(!Si(t,r,o,l))continue;let d=null;for(let c of e)for(let k=1;k<c.points.length;k++){let p=st(l,c.points[k-1],c.points[k]),f=A(l,p);(!d||f<d.distance)&&(d={point:p,parent:c,distance:f})}if(!d)continue;(!i||d.distance>i.distance||d.distance===i.distance&&(l.x<i.point.x||l.x===i.point.x&&l.y<i.point.y))&&(i={point:l,junction:d.point,parent:d.parent,distance:d.distance})}return i}function H2(e,t){let r=null;for(let o=1;o<t.points.length;o++){let i=st(e,t.points[o-1],t.points[o]),a=A(e,i);(!r||a<r.distance)&&(r={point:i,distance:a,dirDeg:pt(t.points[o-1],t.points[o])})}return r}function Lc(e,t,r){let o=0,i=0;for(let a of e){let s=H2(t,a);!s||s.distance>b3||A(s.point,r.centre)<Ct(r)||(i+=1,$2(s.dirDeg,pt(r.centre,s.point))<=u3&&(o+=1))}return i>=2&&o*2>=i}function yc(e,t,r,o,i){let a=A(o,t.centre);if(a<Ct(t)+Wr)return null;let s=Wr/a*(180/Math.PI),n=pt(t.centre,o),l=a/Math.max(1e-6,r.at(n)),d=f=>{let m=Lt(f),v=r.at(f)*l;return new Z(t.centre.x+m.x*v,t.centre.y+m.y*v)},h=f=>{let m=[],v=o;for(let L=1;L*s<=g3/2;L++){let w=d(n+f*L*s),M=null,x=1/0;for(let b of e)for(let u=1;u<b.points.length;u++){let P=Wt(v,w,b.points[u-1],b.points[u]);if(!P)continue;let C=A(v,P);C<x&&(x=C,M=P)}if(M)return m.push(M),{pts:m,joined:!0};if(m.push(w),v=w,L*s*Math.PI/180*a>=aa){let b=V2(e,w,i,oi,m.length>1?m[m.length-2]:o);if(b)return m.push(b),{pts:m,joined:!0}}}return{pts:m,joined:!1}},c=h(-1),k=h(1),p=[...c.pts.slice().reverse(),o,...k.pts];return p.length<2?null:{points:p,joinedEnds:(c.joined?1:0)+(k.joined?1:0)}}function N2(e,t,r,o,i,a,s=[]){if(!Lc(e,o,t))return!1;let n=new Set(i?[i.id]:[]),l=yc(e,t,r,o,n);if(!l||l.joinedEnds===0)return!1;let{points:d}=l;if(Gt(d)<De||(d=Sr(d,Bi(e,s),t),d.length<2||Gt(d)<De))return!1;let h=i??(()=>{let M=e.map(x=>({l:x,d:H2(o,x)?.distance??1/0})).sort((x,b)=>x.d-b.d||x.l.id.localeCompare(b.l.id));return M.length>0&&Number.isFinite(M[0].d)?M[0].l:void 0})();if(!h||za(d,h.points)||!Ci(d,e,a,h.id,!0))return!1;{let M=gt(d),x=M[M.length-1],b=0;for(let u=0;u<=x;u+=Wr){let{p:P}=ut(d,M,u),C=1/0;for(let Q of e)for(let R=1;R<Q.points.length;R++)C=Math.min(C,A(P,st(P,Q.points[R-1],Q.points[R])));b=Math.max(b,C)}if(b<xs*a)return!1}let c=gt(h.points),k=c[c.length-1],p=H2(o,h),f=0;if(p&&k>0)for(let M=1;M<h.points.length;M++){let x=st(p.point,h.points[M-1],h.points[M]);if(A(p.point,x)<1e-6){f=c[M-1]+A(h.points[M-1],x);break}}let m=k>0?Math.min(.99,Math.max(.01,f/k)):.5,v=null,L=Math.max(1,Math.min(99,Math.round(m*100)));for(let M=0;M<99;M++){let x=1+(L-1+M)%99,b=yi(h.id,x/100);if(!e.some(u=>u.id===b)){v=b;break}}if(!v)return!1;let w=Xo(Va(h.type),"footpath");return e.push({id:v,type:w,points:d,widthM:ve(w),parentId:h.id}),!0}function Mc(e,t,r,o,i,a,s,n=[]){let l=wc(e,t,o,i);if(!l||l.distance<=Z3)return!1;if(N2(e,t,o,l.point,void 0,s,n))return!0;let d=Math.round(pt(l.junction,l.point))%360,h=Math.min(ri,Math.max(De,l.distance+kd(r)/2)),c=(()=>{let w=gt(l.parent.points),M=w[w.length-1];if(!(M>0))return .5;let x=0;for(let b=1;b<l.parent.points.length;b++){let u=l.parent.points[b-1],P=l.parent.points[b],C=st(l.junction,u,P);if(A(l.junction,C)<1e-6){x=w[b-1]+A(u,C);break}}return Math.min(.99,Math.max(.01,x/M))})(),k=null,p=Math.max(1,Math.min(99,Math.round(c*100)));for(let w=0;w<99;w++){let M=1+(p-1+w)%99,x=yi(l.parent.id,M/100);if(!e.some(b=>b.id===x)){k=x;break}}if(!k)return!1;let f=Va(l.parent.type),m=to(l.junction,d,h,a),v=V2(e,m[m.length-1],new Set([l.parent.id]),oi,m[m.length-2]);v&&(m=[...m,v]);let L=m.length;return m=Sr(m,Bi(e,n),t,l.parent.id),(v||m.length<L)&&(f=Xo(f,"footpath")),m.length<2||Gt(m)<De||j2(m,l.parent)?!1:(e.push({id:k,type:f,points:m,widthM:ve(f),parentId:l.parent.id}),!0)}function uc(e,t){let r=0,o=0;for(let i=1;i<e.points.length;i++){let a=e.points[i-1],s=e.points[i],n=A(a,s);r+=(A(a,t.centre)+A(s,t.centre))/2*n,o+=n}return o===0?A(e.points[0],t.centre):r/o}function gc(e,t){let r=0,o=0;for(let i=1;i<e.points.length;i++){let a=e.points[i-1],s=e.points[i],n=new Z((a.x+s.x)/2,(a.y+s.y)/2),l=A(a,s);r+=$2(pt(a,s),pt(t.centre,n))*l,o+=l}return o===0?0:r/o}function bc(e,t,r,o,i,a,s,n=[]){let l=vc(mc(e,t,o,i));if(l.widthDeg<=nc(i))return!1;let d=o.ringAt(i,l.bisectorDeg),h=e.filter(m=>gc(m,t)>=60).map(m=>uc(m,t)).filter(m=>m>Ct(t)&&m<=i).sort((m,v)=>v-m).map(m=>o.ringAt(m,l.bisectorDeg)),c=Ct(t)+De/2,k=[.9,.75,.6,.45].map(m=>d*m).filter(m=>m>c);for(let m of[...h,...k]){let v=Lt(l.bisectorDeg),L=new Z(t.centre.x+v.x*m,t.centre.y+v.y*m);if(N2(e,t,o,L,void 0,s,n))return!0}let p=Math.max(0,d-Ct(t));if(p<De)return!1;let f=Math.min(p,kd(r)*v3);for(let m of[0,6,-6,12,-12,18,-18]){let v=Math.round(l.bisectorDeg+m+360)%360,L=Li(v);if(e.some(b=>b.id===L||b.id===y2(v)))continue;let w=Lt(v),M=new Z(t.centre.x+w.x*(t.diameter/2)*Ur,t.centre.y+w.y*(t.diameter/2)*Ur),x=Sr(to(M,v,f,a),Bi(e,n),t);if(!(x.length<2||Gt(x)<De))return e.push({id:L,type:"local",points:x,widthM:ve("local")}),!0}return!1}function D2(e,t,r,o,i,a=1,s=1/0){let n=e.filter(f=>Ot(f.id)),l=e.filter(f=>!Ot(f.id)),d=[],h=f=>{let m=[];for(let v of f){let L=l.find(M=>M.id===v.id),w=L?v.points:Xr(v.points,l);if(!w||!L&&f.some(M=>M.id!==v.id&&za(w,M.points)))return;m.push({...v,points:w})}m.some(v=>n.some(L=>za(v.points,L.points)))||d.push([...m,...n])};for(let f=0;f<4;f++){let m=l.map(w=>({...w,points:[...w.points]})),v=o.radiusM;if((f===0?bc(m,t,r,o,v,i,a,n):f===1?Mc(m,t,r,o,v,i,a,n):cc(m,t,r,o,i,v,a,n))&&h(m),d.length>=s)return d}let k=pd(l,t,o,hd(t,o.radiusM)).map(f=>({slot:f,key:i.float()})).sort((f,m)=>f.key-m.key);for(let{slot:f}of k.slice(0,6))for(let m of[-1,1]){let v=yi(f.parent.id,f.at);if(l.some(b=>b.id===v))continue;let L=f.dirDeg+m*85,w=Math.min(48,Math.max(18,o.radiusM*.65)),M=Sr(to(f.anchor,L,w,i),e,t,f.parent.id);if(M.length<2||Gt(M)<12||j2(M,f.parent)||!Ci(M,l,a,f.parent.id))continue;let x=Va(f.parent.type);if(h([...l,{id:v,type:x,points:M,widthM:ve(x),parentId:f.parent.id}]),d.length>=s)return d}let p=i.int(0,30);for(let f=p;f<360;f+=30){let m=Li(f);if(l.some(M=>M.id===m))continue;let v=Lt(f),L=new Z(t.centre.x+v.x*t.diameter*Ur/2,t.centre.y+v.y*t.diameter*Ur/2),w=Sr(to(L,f,o.at(f),i),e,t);if(!(w.length<2||Gt(w)<12||!Ci(w,l,a))&&(h([...l,{id:m,type:"local",points:w,widthM:ve("local")}]),d.length>=s))return d}return d}function vd(e){let{lanes:t,green:r,site:o,activeDeck:i,lotProfile:a,f0:s,lotFloorM:n,lotCapM:l,terrace:d,trace:h}=e,c=a.radiusM,k=new Vt(e.seed),p=new Map(t.map(u=>[u.id,u.type]));p.set("green","main");let f=[...S1(r,s,yo,k,t),...t.filter(u=>!Ot(u.id)).flatMap(u=>P1(u,r,c,s,yo,k,n,l,z2(u,r,a,o.population)))];if(h){K1(h);for(let u of f)h.cut.set(u.id,u.frontageM)}let m=C2(f,r,o.water);if(h){let u=new Set(m.map(P=>P.id));for(let P of h.cut.keys())u.has(P)||h.fates.set(P,"clipped")}let v=m.filter(u=>u.frontageM>=n).length;if(f=x1(m,t,r,h?.convergeDetail),h){let u=new Set(f.map(P=>P.id));for(let P of m)u.has(P.id)||h.fates.set(P.id,"converging-claim")}for(let u=1;u<=j3;u++){let P=Y1({lanes:t.filter(Q=>!Ot(Q.id)),green:r,standing:f,builtRadiusM:c,f0:s,depthM:yo,floorM:n,maxFrontageM:l,reachOf:Q=>z2(Q,r,a,o.population),pass:u});if(P.added.length===0)break;let C=C2(P.added,r,o.water);if(h){for(let R of P.added)h.cut.set(R.id,R.frontageM);let Q=new Set(C.map(R=>R.id));for(let R of P.added)Q.has(R.id)||h.fates.set(R.id,"clipped")}if(C.length===0)break;P.trimmed.size>0&&(f=f.map(Q=>{let R=P.trimmed.get(Q.id);return R===void 0?Q:{...Q,depthM:R}})),v+=C.filter(Q=>Q.frontageM>=n).length,f=[...f,...C]}f=Eo(C1(f,r,p));let L=s,w=f.filter(u=>u.laneId!=="green");w.length>0&&(L=w.reduce((u,P)=>u+P.frontageM,0)/w.length);let M=e.reservedLandmarks?{landmarks:e.reservedLandmarks,diagnostics:[]}:Ha(o,r,t.filter(u=>!Ot(u.id)),c,new Vt(e.seed+19)),x=M.landmarks.map(u=>({lm:u,building:Pi(u)})).filter(({building:u})=>!Ie(u,t));f=f.filter(u=>!x.some(({lm:P})=>oe(wt(u),wt(P.lot)))),f.push(...x.map(({lm:u})=>u.lot));let b=D1(f,i,o,k,t,h?.fates,d,x.map(u=>u.building));return{lots:f,spend:b,deckUsableLotCount:v,measuredMeanFrontage:L,diagnostics:M.diagnostics}}function wd(e){Ar(e);let t=e.waterContext;if(!t)return{input:e};let r={version:1,status:t.status,issues:[]};if(t.status==="unknown-units")return r.issues.push({code:"water-units-unknown"}),{input:{...e,oceanBearing:void 0,port:!1},result:r};t.omittedRivers?.length&&r.issues.push({code:"water-river-local-width-unavailable"});let o=e.coastlineGeometry;if(!Object.hasOwn(e,"coastlineGeometry")){let i=t.bodies.filter(a=>a.distanceM<=t.surveyRadiusM);if(o=[],i.length){let a=i[0];if(i.length!==1||a.kind!=="ocean"||a.coastApproximation!=="simple-local-coast")throw new je("water-geometry-required","This coast or lake needs surveyed water polygons.");let s=Lt(a.bearingDeg),n=new Z(-s.y,s.x),l=t.surveyRadiusM*2;o=[[...Array.from({length:201},(h,c)=>{let k=(c-100)*l/100,p=a.distanceM+80*(1-Math.exp(-k*k/16e4));return new Z(s.x*p+n.x*k,s.y*p+n.y*k)}),new Z(s.x*l+n.x*l,s.y*l+n.y*l),new Z(s.x*l-n.x*l,s.y*l-n.y*l)]],r.status="approximate"}}return{input:{...e,oceanBearing:void 0,coastlineGeometry:o},result:r}}function Ld(e,t,r){let o=e.waterContext;if(!o||o.status!=="measured"||!r)return;K5(t,o.surveyRadiusM);let i=()=>{r.issues.some(l=>l.code==="water-context-conflict")||r.issues.push({code:"water-context-conflict"})},a=new Z(0,0),s=be(t);if(!s.some(([l,d])=>A(a,st(a,l,d))<1e-7)&&t.some(l=>bt(a,l)))throw new je("water-context-conflict","The supplied burg position is in water. Correct its location or shoreline survey.");if(Object.hasOwn(e,"coastlineGeometry"))for(let l of o.bodies){if(!l.polygonIndices?.length){l.distanceM<=o.surveyRadiusM&&i();continue}let d=l.polygonIndices.map(m=>t[m]),h=m=>d.some(v=>v.some((L,w)=>A(m,st(m,L,v[(w+1)%v.length]))<1e-5)),c=1/0,k=Lt(l.bearingDeg),p=new Z(k.x*l.distanceM,k.y*l.distanceM),f=1/0;for(let[m,v]of s)h(new Z((m.x+v.x)/2,(m.y+v.y)/2))&&(c=Math.min(c,A(a,st(a,m,v))),f=Math.min(f,A(p,st(p,m,v))));(l.distanceM<=o.surveyRadiusM&&(Math.abs(c-l.distanceM)>1||f>1)||c<o.surveyRadiusM&&Math.abs(c-l.distanceM)>1)&&i()}}function yd(e,t){return(e.rivers??[]).flatMap((r,o)=>{if(!(r.widthM>0)||!Number.isFinite(r.widthM))return[];let i=r.centreline.filter(v=>Number.isFinite(v.x)&&Number.isFinite(v.y)).map(v=>new Z(v.x,v.y)).filter((v,L,w)=>L===0||A(v,w[L-1])>.001);if(i.length<2)return[];let a=gt(i),s=a.at(-1),n=0,l=1/0;for(let v=1;v<i.length;v++){let L=st(new Z(0,0),i[v-1],i[v]);A(L,new Z(0,0))<l&&(l=A(L,new Z(0,0)),n=a[v-1]+A(i[v-1],L))}let d=new Vt(t*3571+o*7919+1013),h=Math.max(300,30*Math.sqrt(Math.max(1,e.population))),c=Math.min(40,h*.075,s*.05),k=d.float()*Math.PI*2,p=v=>Math.sin(v*Math.PI*2/h+k)+.18*Math.sin(v*Math.PI*2/(h*.57)+k*1.7),f=Math.ceil(s/6),m=[];for(let v=0;v<=f;v++){let L=s*v/f,w=ut(i,a,L).p,M=ut(i,a,Math.max(0,L-3)).p,x=ut(i,a,Math.min(s,L+3)).p,b=A(M,x);if(b<1e-8){m.push(w);continue}let u=Math.sin(Math.min(1,Math.min(L,s-L)/80)*Math.PI/2)**2,P=r.meander===!1?0:c*(p(L)-p(n))*u;m.push(new Z(w.x-(x.y-M.y)/b*P,w.y+(x.x-M.x)/b*P))}return[[...Ze(m,r.widthM/2,1),...Ze(m,r.widthM/2,-1).reverse()]]})}var xc=new Set(Ye),ja=5e3,Zc=24,Pc=4.6,Sc=14,Cc=1.15,Ei=[6,2.4],Bc=[.85,.15],Ec=360,_c=7919,Rc=104729;function Qc(e,t){if((e.coastlineGeometry?.length??0)>0)return[];if(e.oceanBearing==null)return[];let r=Lt(e.oceanBearing),o=new Z(-r.y,r.x),i=Pc*Math.sqrt(Math.max(1,e.population)),a=Math.max(i,Ec/Ei[0]),s=i*Cc,n=new Vt(t*_c+Rc),l=n.float()>=.25,d=Ei.map((L,w)=>w===0?l?-Math.PI/2:Math.PI/2:n.float()*Math.PI*2),h=a*Zc,k=a*Math.min(...Ei)/Sc,p=Math.ceil(2*h/k),f=[];for(let L=0;L<=p;L++){let w=-h+2*h*L/p,M=0;for(let b=0;b<Ei.length;b++)M+=Bc[b]*Math.sin(2*Math.PI*w/(a*Ei[b])+d[b]);let x=i+s+M*s;f.push(new Z(r.x*x+o.x*w,r.y*x+o.y*w))}let m=new Z(r.x*ja-o.x*h,r.y*ja-o.y*h),v=new Z(r.x*ja+o.x*h,r.y*ja+o.y*h);return[[...f,v,m]]}function Md(e,t=0){let r=e,o=wd(e);e=o.input;let i=(e.roadBearings??[]).map(s=>{if(typeof s=="number")return{bearingDeg:s,type:"main",through:!1,routeId:void 0,followsRiver:void 0,relief:void 0};let n=s.kind,l=n&&xc.has(n)?n:Nn(Ui(s.kind??(s.group==="trails"?"foot":"road"))??"foot");return l==="searoutes"?null:{bearingDeg:s.bearing_deg,type:l,through:s.through??!1,routeId:s.route_id,followsRiver:s.followsRiver,relief:s.relief}}).filter(s=>s!==null),a=(e.coastlineGeometry??[]).map(s=>s.map(n=>new Z(n.x,n.y))).concat(Qc(e,t),yd(e,t));return Ld(r,a,o.result),{...o.result?{waterContextResult:o.result}:{},...r.waterContext?.status==="measured"?{surveyRadiusM:r.waterContext.surveyRadiusM}:{},freshwaterIrrigation:(e.rivers?.length??0)>0,population:e.population,biome:Ir(e.biome),routes:i,water:a,flags:{port:e.port,temple:e.temple,trade:e.trade??!1,walls:e.walls,capital:e.capital??!1,citadel:e.citadel??!1,plaza:e.plaza??!1,shanty:e.shanty??!1}}}function ud(e,t){return[...e].sort((r,o)=>r.id.localeCompare(o.id)).flatMap(r=>xe(r.points,t).map((o,i)=>{let a=o.points[0],s=o.points[1],n=o.points.at(-1),l=o.points.at(-2),d=(m,v)=>{let L=A(m,v);return new Z(m.x+(m.x-v.x)/L,m.y+(m.y-v.y)/L)},h=[d(a,s),...o.points,d(n,l)],c=Qt(r).surfaceM/2+.35,k=[...Ze(h,c,1),...Ze(h,c,-1).reverse()],p=gt(o.points),f=o.endM-o.startM;return{id:`bridge:${r.id}:${i}`,laneId:r.id,position:ut(o.points,p,f/2).p,bearingDeg:pt(a,n),spanM:f,narrow:f<=br,centreline:h,deck:k}}))}function gd(e,t){let r=e.centre,o=Ct(e),i=[];for(let a of t)for(let s=1;s<a.points.length;s++){let n=a.points[s-1],l=a.points[s],d=l.x-n.x,h=l.y-n.y,c=n.x-r.x,k=n.y-r.y,p=d*d+h*h,f=2*(c*d+k*h),m=f*f-4*p*(c*c+k*k-o*o);if(!(p<1e-9||m<0))for(let v of[(-f-Math.sqrt(m))/(2*p),(-f+Math.sqrt(m))/(2*p)]){if(v<0||v>1)continue;let L=new Z(n.x+v*d,n.y+v*h);i.some(w=>A(L,w)<2)||i.push(L)}}return i.sort((a,s)=>pt(r,a)-pt(r,s))}function Ic(e){return e.routes}function Zd(e,t,r){let o=Math.max(1,e/t);return Math.sqrt(o*r/Math.PI)}function Ac(e,t,r){let o=e.length?e.reduce((n,l)=>ft(n.type)<=ft(l.type)?n:l):void 0,i=o?ia[o.type]??ia.local:ia.local,a=i*Math.sqrt(t/s3),s=Math.min(n3,r/l3);return Math.min(Math.max(a,i),s)}var bd=2,Tc=200,Oc=1e-6;function Pd(e,t){let r=[];for(let o=0;o<16;o++){let i=o/16*Math.PI*2;r.push(new Z(e.x+t*Math.cos(i),e.y+t*Math.sin(i)))}return r}function xd(e,t,r){return Tt(r,e,t),r.length===0?!1:[e,...Pd(e,t)].some(i=>kt(i,r))}function Hc(e,t,r){let o=Pd(e,t).filter(n=>kt(n,r));if(o.length===0)return new Z(0,1);let i=0,a=0;for(let n of o){let l=We(n.x-e.x,n.y-e.y);i+=l.x,a+=l.y}if(A(new Z(0,0),new Z(i,a))<Oc)return new Z(0,1);let s=We(i,a);return new Z(-s.x,-s.y)}function F2(e,t,r){let o=e;if(!xd(o,t,r))return{centre:o,clipped:!1};for(let i=0;i<Tc;i++){let a=Hc(o,t,r);if(o=new Z(o.x+a.x*bd,o.y+a.y*bd),!xd(o,t,r))break}return{centre:o,clipped:!0}}function zc(e){let t=e.trunks.filter(o=>o.points.length>=2&&!o.id.startsWith("trunk-loop-")&&!Ot(o.id));if(t.length===0)return null;let r=o=>o.points.slice(1).reduce((i,a,s)=>i+A(o.points[s],a),0);return t.reduce((o,i)=>{let a=ft(i.type)-ft(o.type);return a!==0?a<0?i:o:r(i)>r(o)?i:o})}function Vc(e,t){if(t<=0||t+1>=e.length)return 0;let r=e[t-1],o=e[t],i=e[t+1],a=We(o.x-r.x,o.y-r.y),s=We(i.x-o.x,i.y-o.y);return a.x*s.x+a.y*s.y}function jc(e,t,r,o){let i=[];for(let s=1;s+1<e.points.length;s++){let n=e.points[s],l=A(n,t);l>r||i.push({p:n,score:1-l/Math.max(1,r)+Vc(e.points,s)})}if(i.length===0)return Yr(t,e.points).point;i.sort((s,n)=>n.score-s.score);let a=i.slice(0,3);return a[o.int(0,a.length)].p}function Sd(e,t,r,o){let i=Ic(e),a=i.find(M=>M.through),s=Ac(i,e.population,r),l=s/2+d3,d=zc(t),h=t.junctions.filter(M=>M.laneIds.length>=3&&A(M.position,t.aim)<=r).sort((M,x)=>A(M.position,t.aim)-A(x.position,t.aim))[0],c=t.pattern==="main-street",k=c?"astride":"terminal",p=c&&d?jc(d,t.aim,r,o):h?h.position:t.aim;!c&&h&&(k="astride");let f=F2(p,l,e.water);p=f.centre;let v={shape:"sm-green-round",variant:o.bool(.5)?"a":"b",centre:p,diameter:s,bearingDeg:0},L=$c(v,t,r),w=gd(v,[...t.trunks.filter(M=>!Ot(M.id)),...L]);return w.length===3?(v.shape="sm-green-triangle",v.outline=w):w.length===2?(v.shape=a&&ft(a.type)<=ft("main")?"sm-green-lens-long":"sm-green-lens",v.bearingDeg=pt(w[0],w[1]),k="astride"):w.length>=4?v.shape="sm-green-square":k="terminal",f.clipped&&(v.shape="sm-green-d",delete v.outline),{green:v,relation:k,connectors:L}}function $c(e,t,r){let o=Ct(e),i=t.trunks.filter(h=>h.points.length>=2&&!Ot(h.id));if(i.length===0)return[];let a=i.map(h=>({t:h,hit:Yr(e.centre,h.points)})).sort((h,c)=>h.hit.distance-c.hit.distance)[0];if(a.hit.distance<=o)return[];let s=r*m5,n=a.hit.point,l=We(n.x-e.centre.x,n.y-e.centre.y),d=new Z(e.centre.x+l.x*o,e.centre.y+l.y*o);return A(d,n)>s?[]:[{id:"green-c0",type:"local",points:[d,n],widthM:ve("local")}]}var $a=1,Nc=12,Ue=Math.round(360/$a);function G2(e,t){let r=o=>{let i=fe(o)/$a,a=Math.floor(i),s=i-a,n=e[a%Ue],l=e[(a+1)%Ue];return n+(l-n)*s};return{radiusM:t,shapeAt:r,at:o=>t*r(o),scaled:o=>G2(e,t*o),ringAt:(o,i)=>o*r(i)}}function Dc(e){if(e.length===0)return{axisDeg:0,strength:0};let t=0,r=0;for(let a of e){let s=2*a*Math.PI/180;t+=Math.cos(s),r+=Math.sin(s)}let o=Math.hypot(t,r)/e.length;return{axisDeg:fe(Math.atan2(r,t)*180/Math.PI/2),strength:o}}function Fc(e,t){if(Tt(e.water,e.centre,e.radiusM*Us+uo),e.water.length===0)return 1/0;let r=Lt(t),o=e.radiusM*Us,i=a=>new Z(e.centre.x+r.x*a,e.centre.y+r.y*a);for(let a=0;a<=o;a+=bo){if(!kt(i(a),e.water))continue;let s=1/0;for(let n=bo;n<=uo;n+=bo)if(!kt(i(a+n),e.water)){s=n;break}if(s>=br){let n=i(a),l,d=1/0;for(let[c,k]of be(e.water)){let p=st(n,c,k),f=Math.hypot(n.x-p.x,n.y-p.y);f<d&&(d=f,l=[c,k])}let h=0;if(l){let[c,k]=l,p=Math.hypot(k.x-c.x,k.y-c.y),f=-(k.y-c.y)/(p||1),m=(k.x-c.x)/(p||1);for(let v of[-1,1]){let L=1/0;for(let w=bo;w<br;w+=bo)if(!kt(new Z(n.x+v*f*w,n.y+v*m*w),e.water)){L=w;break}h+=L}}else h=1/0;if(h>=br)return a;continue}a+=s}return 1/0}function Cd(e){let{rng:t}=e,r=Xl.map((v,L)=>{let w=t.float()*360,[M,x]=Jl[L];return{k:v,phaseDeg:w,amp:M+t.float()*(x-M)}}),o=Dc(e.trunkBearingsDeg),i=new Array(Ue);for(let v=0;v<Ue;v++){let L=v*$a,w=1;for(let M of r)w+=M.amp*Math.cos(M.k*(L-M.phaseDeg)*Math.PI/180);w*=1+t5*o.strength*Math.cos(2*(L-o.axisDeg)*Math.PI/180),i[v]=w}let a=i.reduce((v,L)=>v+L,0)/i.length,s=Math.sqrt(i.reduce((v,L)=>v+(L-a)**2,0)/i.length)/Math.max(1e-9,a),n=s>=Ws?1:Math.min(e5,Ws/Math.max(1e-6,s));for(let v=0;v<Ue;v++)i[v]=Math.min(li,Math.max(r5,a+(i[v]-a)*n));let l=4,d=0,h=0;for(let v=0;v<Ue;v++)for(let L=0;L<l;L++){let w=L/l,M=i[v]+(i[(v+1)%Ue]-i[v])*w;d+=M*M,h+=1}let c=1/Math.sqrt(d/h),k=i.map(v=>v*c),p=new Array(Ue).fill(1/0),f=!1;for(let v=0;v<Ue;v++){let L=Fc(e,v*$a);Number.isFinite(L)&&(f=!0,p[v]=Math.max(i5,(L-o5)/e.radiusM))}if(!f)return G2(k,e.radiusM);let m=()=>{for(let v=0;v<Ue;v++)k[v]=Math.min(k[v],p[v])};for(let v=0;v<Nc;v++){m();let L=k.reduce((M,x)=>M+x*x,0)/k.length;if(!(L>0))break;let w=1/Math.sqrt(L);if(Math.abs(w-1)<1e-9)break;for(let M=0;M<Ue;M++)k[M]=Math.min(li*1.5,k[M]*w)}return m(),G2(k,e.radiusM)}function Ed(e,t){let r=e.flatMap(o=>[o.points[0],o.points[o.points.length-1]].map(i=>({p:i,laneId:o.id})));return e.map(o=>{if(Ce(o.id))return o;let i=o.points.map(s=>new Z(s.x,s.y)),a=o.points.map(s=>new Z(s.x,s.y));for(let s=0;s<Ps;s++)for(let n=1;n<a.length-1;n++)if(!r.some(({p:l,laneId:d})=>d!==o.id&&(A(l,st(l,i[n-1],i[n]))<.15||A(l,st(l,i[n],i[n+1]))<.15)))for(let l of t){let d=pe(l.glyph,l.footprint),h=o.widthM/2+_3+Math.min(d.width,d.depth)/2,c=a[n].x-l.position.x,k=a[n].y-l.position.y,p=A(a[n],l.position);if(p===0||p>=h)continue;let f=(h-p)/Ps;a[n]=new Z(a[n].x+c/p*f,a[n].y+k/p*f)}for(let s=0;s<a.length;s++){let n=a[s].x-i[s].x,l=a[s].y-i[s].y,d=A(a[s],i[s]);d>sa&&(a[s]=new Z(i[s].x+n/d*sa,i[s].y+l/d*sa))}return{...o,points:a}})}function Gc(e,t,r){let o=`${e.id}:`;return t.filter(i=>r.has(i.lotId)?r.get(i.lotId)===e.id:i.lotId.startsWith(o))}function Wc(e,t,r){let o=1/0,i=0;for(let a=1;a<t.length;a++){let s=st(e,t[a-1],t[a]),n=A(e,s);n<o&&(o=n,i=r[a-1]+A(t[a-1],s))}return i}function Bd(e){return e.endsWith("/c")}var Uc=1.5;function qc(e){let t=new Map,r=new Set,o=new Map;for(let i of e)o.set(i.id,gt(i.points));for(let i of e)if(!(i.points.length<2))for(let[a,s]of[i.points[0],i.points[i.points.length-1]].entries())for(let n of e){if(n.id===i.id)continue;let l=o.get(n.id),d=Uc,h=-1;for(let c=1;c<n.points.length;c++){let k=st(s,n.points[c-1],n.points[c]),p=A(s,k);p<d&&(d=p,h=l[c-1]+A(n.points[c-1],k))}h>=0&&(t.set(n.id,Math.max(t.get(n.id)??0,h)),a===1&&r.add(i.id))}return{floorS:t,joiners:r}}function _d(e,t,r={}){let{weld:o=!0}=r,i=new Map(r.lots?.map(d=>[d.id,d.laneId])??[]),a=[],s=new Set(e.filter(d=>Bd(d.id)&&d.parentId!==void 0).map(d=>d.parentId)),{floorS:n,joiners:l}=o?qc(e):{floorS:new Map,joiners:new Set};for(let d of e){if(Ce(d.id)){a.push(d);continue}if(Bd(d.id)){a.push(d);continue}if(s.has(d.id)){a.push(d);continue}if(l.has(d.id)){a.push(d);continue}let h=Gc(d,t,i),c=n.get(d.id)??0;if(h.length===0&&!n.has(d.id))continue;let k=gt(d.points),p=h.reduce((L,w)=>Math.max(L,Wc(w.position,d.points,k)),0),f=Math.min(k[k.length-1],Math.max(p+R3,c)),m=d.points.filter((L,w)=>k[w]<f),v=ut(d.points,k,f).p;m.length===0&&m.push(d.points[0]),A(m[m.length-1],v)>1e-6&&m.push(v),a.push({...d,points:m.length>=2?m:d.points.slice(0,2)})}return a}var Id=1e3,Kc=96,Rd=4,Qd=3;function Yc(e,t){for(let r=1;r<e.length;r++)for(let o=1;o<t.length;o++)if(Wt(e[r-1],e[r],t[o-1],t[o]))return!0;return!1}function Ad(e,t,r){let o=new Vt(t),i=Md(e,t),a=[],{entries:s,dropped:n}=y5(i.biome,i.population,o);n.length>0&&a.push(`deck dropped (no manifest entry): ${n.join(", ")}`);let l=e2(s),d=Zd(i.population,l,H3),h=M5(s),c=u5(s),k=h*T3,p=h+Z1(i.population),f=h,m=ed(i),v=Math.ceil(i.population/g5(s))+m,L=Math.max(p,c),w=cd(v,L),M=F2(new Z(0,0),v5,i.water).centre,x=M1(i,y1(w),w,o,M);a.push(...x.diagnostics);let b=Sd(i,x,d,o),u=b.green,P=b.relation,C=p,Q=c,R=s,V=[...x.trunks,...b.connectors].map(ot=>Aa(ot,v)),j=Math.max(w,u.diameter/2+2*yo+L),F=new Vt(t*a5+s5),K=Cd({centre:u.centre,radiusM:j,trunkBearingsDeg:i.routes.map(ot=>ot.bearingDeg),water:i.water,rng:F}),H=K,X=H.radiusM,nt=!1,mt=Ha(i,u,V.filter(ot=>!Ot(ot.id)),X,new Vt(t*3571+90)),O=mt.landmarks.map(Pi);a.push(...mt.diagnostics);let Y=(ot,St=!1)=>vd({lanes:ot,green:u,site:i,activeDeck:R,lotProfile:H,f0:C,lotFloorM:Q,lotCapM:k,seed:t*3571+71,terrace:nt,reservedLandmarks:mt.landmarks,trace:St?r:void 0}),rt=Y(V),yt=()=>({evaluated:rt,lanes:V,lotProfile:H,lotRadiusM:X,f0:C,lotFloorM:Q,activeDeck:R,terrace:nt}),B=yt(),U=0,$=0,J=0,lt=1,xt=0,zt=0,ae=!1,Pe=Math.ceil((p-f)/Es);for(let ot=0;ot<Kc&&rt.spend.unhoused>0;ot++){let St=(g=1/0)=>D2(V,u,rt.measuredMeanFrontage,H,new Vt(t*7919+ot*101+37),lt,g),qt=St(Rd),Jt=!1,I;for(let g=0;g===qt.length&&!I&&!Jt&&(qt=St(),Jt=!0),!(g>=qt.length||g>=Rd&&I);g++){let _=qt[g].map(T=>Aa(T,v));if(i.water.length&&_.some(T=>!V.some(W=>W.id===T.id&&W.points===T.points)&&!Jr(T.points,i.water,Qt(T).surfaceM/2+1.5))){J++;continue}if(O.some(T=>Ie(T,_))){J++;continue}let E=Y(_),N=E.spend.housed-rt.spend.housed;if(N<=0){J++;continue}let z=Math.max(1,_.reduce((T,W)=>T+Gt(W.points),0)-V.reduce((T,W)=>T+Gt(W.points),0)),G=T=>T.reduce((W,et)=>W+et.occupancy*A(et.position,u.centre),0),D=Math.max(0,G(E.spend.buildings)-G(rt.spend.buildings))/N,tt=N/(z+8)/(1+D/X);(!I||tt>I.score)&&(I={lanes:_,result:E,score:tt})}if(!I){let g=T2(V,u,rt.spend.buildings,rt.lots);if(g.length<V.length){let S=Y(g);if(S.spend.housed>=rt.spend.housed){V=g,rt=S,B=yt();continue}}}if(!I&&U>=2)for(let g of qt.slice(0,Qd)){let S=D2(g,u,rt.measuredMeanFrontage,H,new Vt(t*31+ot*997),lt,Qd);for(let _ of S){let E=_.map(tt=>Aa(tt,v));if(i.water.length&&E.some(tt=>!V.some(T=>T.id===tt.id&&T.points===tt.points)&&!Jr(tt.points,i.water,Qt(tt).surfaceM/2+1.5))){J++;continue}if(O.some(tt=>Ie(tt,E))){J++;continue}let N=Y(E),z=N.spend.housed-rt.spend.housed;if(z<=0){J++;continue}let G=Math.max(1,E.reduce((tt,T)=>tt+Gt(T.points),0)-V.reduce((tt,T)=>tt+Gt(T.points),0)),D=z/(G+16);(!I||D>I.score)&&(I={lanes:E,result:N,score:D})}}if(I){V=I.lanes,rt=I.result,B=yt(),$++;continue}if(U++>=ol+(i.water.length?2:0))break;if(xt<Pe){let g=++xt*Es;C=Math.max(f,p-g),Q=Math.max(f,c-g),R=b5(s,g)}else ae?lt>bs?lt=Math.max(bs,lt-f3):(X=j*(1+ ++zt*il),H=K.scaled(X/j)):(ae=!0,nt=!0);let y=Y(V);y.spend.housed>=rt.spend.housed?(rt=y,B=yt()):{f0:C,lotFloorM:Q,activeDeck:R,terrace:nt}=B}({evaluated:rt,lanes:V,lotProfile:H,lotRadiusM:X,f0:C,lotFloorM:Q,activeDeck:R,terrace:nt}=B),r&&(rt=Y(V,!0));let{lots:Zt,spend:$t,deckUsableLotCount:Ut}=rt;a.push(`growth: ${$} additions accepted, ${J} trials rejected, ${U} fallback rounds`),$t.unhoused>0&&a.push(`overflow: ${$t.unhoused} of ${i.population} unhoused after bounded frontage growth`);let me=Ed(V.filter(ot=>!Ot(ot.id)),$t.buildings).map(ot=>$t.buildings.some(qt=>Ie(qt,[ot]))||!Jr(ot.points,i.water,Qt(ot).surfaceM/2+1.5)?V.find(qt=>qt.id===ot.id)??ot:ot).concat(V.filter(ot=>Ot(ot.id)));for(let ot=0;ot<4;ot++){let St=me.map((Jt,I)=>I).sort((Jt,I)=>me[Jt].id.localeCompare(me[I].id)),qt=!1;for(let Jt of St){let I=V.find(g=>g.id===me[Jt].id);if(!I||I===me[Jt])continue;me.some((g,S)=>S!==Jt&&Yc(me[Jt].points,g.points))&&(me[Jt]=I,qt=!0)}if(!qt)break}let rr=_d(T2(me,u,$t.buildings,Zt),$t.buildings,{lots:Zt}).map(ot=>Jr(ot.points,i.water,Qt(ot).surfaceM/2+1.5)&&!$t.buildings.some(St=>Ie(St,[ot]))?ot:me.find(St=>St.id===ot.id)??ot),Le=md(rr,u,$t.buildings,Zt,i.water);a.push(...rt.diagnostics);let qe=new Map(Le.map(ot=>[ot.id,ot])),ro=new Set($t.buildings.map(ot=>ot.lotId)),or=Zt.filter(ot=>{if(ro.has(ot.id)||td(ot.id))return!0;if(ot.laneId==="green"){let qt=u.diameter/2*Lo+gr;return Math.abs(A(ot.front,u.centre)-qt)<_s}let St=qe.get(ot.laneId);return St?Xc(ot,St):!1});if(r){let ot=new Set(or.map(St=>St.id));for(let St of r.cut.keys())!ot.has(St)&&r.fates.get(St)!=="clipped"&&r.fates.get(St)!=="converging-claim"&&r.staleAfterTrim.add(St)}Ut>0&&a.push(`seating: ${Math.round($t.buildings.length/Ut*100)}% (${$t.buildings.length} of ${Ut} deck-usable lots)`);let Nt=W1({site:i,green:u,lanes:Le,lots:or,buildings:$t.buildings,builtRadiusM:X,f0:C,rng:o}),Cr=[...Le,...Nt.accessLanes];if(a.push(...Nt.diagnostics),i.water.length>0){let ot=Nt.fields.reduce((qt,Jt)=>{let I=0;for(let y=0;y<Jt.polygon.length;y++){let g=Jt.polygon[y],S=Jt.polygon[(y+1)%Jt.polygon.length];I+=g.x*S.y-S.x*g.y}return qt+Math.abs(I)/2},0),St=Math.PI*X*X;St>0&&ot<St*Is&&a.push(`water: the site is hemmed in \u2014 ${(ot/1e3).toFixed(1)}k m2 of farmland, ${(ot/St).toFixed(2)}x the built area against ${Is.toFixed(1)}x expected of a village with room`)}let se=U1({lanes:Cr,buildings:$t.buildings.map(ot=>ot.position),greenCentre:u.centre,dressing:[...Nt.fields.flatMap(ot=>ot.polygon),...Nt.fieldEdges.map(ot=>ot.position),...Nt.vegetation.map(ot=>ot.position),...Nt.pois.map(ot=>ot.position)]});if(i.surveyRadiusM!==void 0){let ot=Math.max(...[se.minX,se.maxX].flatMap(St=>[se.minY,se.maxY].map(qt=>Math.hypot(St,qt))));ot+1e3>i.surveyRadiusM&&Uo(ot+1e3),i.flags.port&&!Nt.pois.some(St=>St.kind==="boathouse")&&!i.waterContextResult.issues.some(St=>St.code==="water-context-conflict")&&i.waterContextResult.issues.push({code:"water-context-conflict"})}let Xt=q1(Cr,se),oo=Le.filter(ot=>Ot(ot.id)).length-Xt.filter(ot=>Ot(ot.id)).length;return oo>0&&a.push(`apron: ${oo} approach road${oo===1?"":"s"} started outside the drawn tile and was dropped`),{site:i,green:u,lanes:Xt,lots:or,buildings:$t.buildings,edgeStyle:Nt.edgeStyle,crofts:Nt.crofts,fields:Nt.fields,fieldEdges:Nt.fieldEdges,vegetation:Nt.vegetation,pois:Nt.pois,diagnostics:a,...Nt.wall?{wall:Nt.wall}:{},contractRadiusM:x.contractRadiusM,frame:se,trunkJunctions:x.junctions.filter(ot=>ot.position.x>=se.minX&&ot.position.x<=se.maxX&&ot.position.y>=se.minY&&ot.position.y<=se.maxY),greenRelation:P,bridges:ud(Xt,i.water)}}function Xc(e,t){let r=Be(t),o=1/0;for(let i=1;i<t.points.length;i++){let a=st(e.front,t.points[i-1],t.points[i]);o=Math.min(o,A(e.front,a))}return Math.abs(o-r)<_s}function Na(e){let t=new Map;for(let r of e){if(r.points.length<2)continue;let o=Qt(r).surfaceM,i=p=>{let f=e.filter(m=>m.id!==r.id&&m.points.slice(1).some((v,L)=>A(p,st(p,m.points[L],v))<.15));return f.length?Math.min(o,Math.max(...f.map(m=>Qt(m).surfaceM))):o},a=i(r.points[0]),s=i(r.points.at(-1));if(a>=o&&s>=o)continue;let n=gt(r.points),l=n.at(-1),d=Math.min(l/3,Math.max(3,o*2));if(d<=0)continue;let h=p=>(p=Math.min(1,Math.max(0,p)),p*p*(3-2*p)),c=[];for(let p=1;p<r.points.length;p++){let f=r.points[p-1],m=r.points[p],v=A(f,m),L=Math.max(1,Math.ceil(v/1.5));for(let w=0;w<L;w++)c.push(new Z(f.x+(m.x-f.x)*w/L,f.y+(m.y-f.y)*w/L))}c.push(r.points.at(-1));let k=p=>Ze(c,o/2+.02,p).map(f=>{let m=r.points[0],v=0,L=1/0;for(let x=1;x<r.points.length;x++){let b=st(f,r.points[x-1],r.points[x]),u=A(f,b);u<L&&(m=b,L=u,v=n[x-1]+A(b,r.points[x-1]))}let M=(Math.min(a+(o-a)*h(v/d),s+(o-s)*h((l-v)/d))/2+.02)/(o/2+.02);return new Z(m.x+(f.x-m.x)*M,m.y+(f.y-m.y)*M)});t.set(r.id,[...k(1),...k(-1).reverse()])}return t}var Da=[2.6,3.6],Td=.6;function at(e){return(Math.round(e*100)/100).toString()}function Fa(e,t){return`<g id="${e}">${t}</g>`}function Ga(e,t,r){return`${e.map((o,i)=>`${i===0?"M":"L"}${at(t(o.x))},${at(r(o.y))}`).join(" ")} Z`}function Hd(e){return(Math.round(e/Ns)*Ns%360+360)%360}function Od(e,t){return`pat-${e}-r${Hd(t)}`}function zd(e,t=4,r,o={}){let i=o.skin?Vi(o.skin,o.skinBiome??e.site.biome):void 0,a=i?.assets.glyphs??Ke;r=r??i?.village??mr(e.site.biome);let s=[...e.fieldEdges],{minX:n,minY:l}=e.frame,d=(e.frame.maxX-n)*t,h=(e.frame.maxY-l)*t,c=O=>(O-n)*t,k=O=>(O-l)*t,p=[...e.buildings.map(O=>({id:O.id,glyph:O.glyph,position:O.position,bearingDeg:O.bearingDeg,footprint:O.footprint,kind:"building"})),...e.pois.map(O=>({id:O.id,glyph:O.glyph,position:O.position,bearingDeg:O.bearingDeg,footprint:re(O.glyph),kind:"poi"}))],f=Array.from(new Set(p.map(O=>O.glyph))),m=Array.from(new Set(s.map(O=>O.glyph))),v=Array.from(new Set(e.fields.map(O=>O.glyph))),L=Array.from(new Set(e.vegetation.map(O=>O.glyph))),w=Array.from(new Set([...f,...m,...v,...L])),M=Array.from(new Set([...f,...L])),x=`${e.green.shape}-${e.green.variant}`,b=ce(x)&&Object.prototype.hasOwnProperty.call(a,x),u=[];for(let O of w){let Y=a[O];Y&&(u.push(Fa(O,Y.body)),M.includes(O)&&Y.sil&&u.push(Fa(`${O}-sil`,Y.sil)))}if(b)if(i?.overrides.has(x))u.push(Fa(x,a[x].body));else{let O=Ke[x].body.match(/<path[^>]* d="([^"]+)"/)?.[1];O&&u.push(Fa(x,Br(O,e.site.biome,{id:x,seed:"abc".indexOf(e.green.variant)})))}let P=new Set,C=[],Q=16*t;for(let O of e.fields){if(!a[O.glyph])continue;let Y=Od(O.glyph,O.furrowBearingDeg);if(P.has(Y))continue;P.add(Y);let rt=Q/_t[O.glyph].viewBox[2];C.push(`<pattern id="${Y}" patternUnits="userSpaceOnUse" width="${at(Q)}" height="${at(Q)}" patternTransform="rotate(${at(Hd(O.furrowBearingDeg))})"><use href="#${O.glyph}" transform="scale(${at(rt)})"/></pattern>`)}let R=[];R.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${at(d)}" height="${at(h)}" viewBox="0 0 ${at(d)} ${at(h)}" data-contract-radius="${at(e.contractRadiusM)}" data-origin-x="${at(c(0))}" data-origin-y="${at(k(0))}" data-px-per-metre="${at(t)}">`),R.push(`<style>${Ii(r.tokens)}</style>`),R.push(`<defs>${u.join("")}${C.join("")}</defs>`),R.push(`<rect data-bg="paper" width="${at(d)}" height="${at(h)}" fill="${r.ground}"/>`);let V=e.site.water.filter(O=>O.length>=3);if(V.length>0){R.push(`<defs><clipPath id="v-water-clip"><rect width="${at(d)}" height="${at(h)}"/></clipPath></defs>`),R.push('<g data-band="water" clip-path="url(#v-water-clip)">');let O=Y5(e.site.water);if(O){R.push(`<path data-water="union" d="${O.map(rt=>Ga(rt,c,k)).join(" ")}" fill="${r.water}" fill-rule="evenodd" stroke="none"/>`);let Y=Pr(e.site.water).map(rt=>rt.map((yt,B)=>`${B?"L":"M"}${at(c(yt.x))},${at(k(yt.y))}`).join(" ")).join(" ");R.push(`<path data-shore="union" d="${Y}" fill="none" stroke="${r.waterEdge}" stroke-width="${at(Td*t)}" stroke-linejoin="round"/>`)}else V.forEach((Y,rt)=>{R.push(`<path data-water="w${rt}" d="${Ga(Y,c,k)}" fill="${r.water}" stroke="${r.waterEdge}" stroke-width="${at(Td*t)}" stroke-linejoin="round"/>`)});R.push("</g>")}let j=e.pois.flatMap(O=>O.jetty?[O.jetty]:[]);if(j.length>0){R.push('<g data-band="jetty">');for(let O of j){let Y=O.to.x-O.from.x,rt=O.to.y-O.from.y,yt=Math.hypot(Y,rt)||1,B=Y/yt,$=-(rt/yt)*O.widthM/2,J=B*O.widthM/2,lt=[[O.from.x+$,O.from.y+J],[O.to.x+$,O.to.y+J],[O.to.x-$,O.to.y-J],[O.from.x-$,O.from.y-J]].map(([ae,Pe],Zt)=>`${Zt===0?"M":"L"}${at(c(ae))},${at(k(Pe))}`).join(" ");R.push(`<path data-jetty="deck" d="${lt} Z" fill="var(--sm-timber, #d9c39a)" stroke="var(--sm-ink, #33262e)" stroke-width="${at(.25*t)}" stroke-linejoin="round"/>`);let xt=Math.max(2,Math.floor(yt/1.2)),zt=[];for(let ae=1;ae<xt;ae++){let Pe=ae/xt,Zt=O.from.x+Y*Pe,$t=O.from.y+rt*Pe;zt.push(`M${at(c(Zt+$))},${at(k($t+J))} L${at(c(Zt-$))},${at(k($t-J))}`)}zt.length>0&&R.push(`<path data-jetty="planks" d="${zt.join(" ")}" fill="none" stroke="var(--sm-ink, #33262e)" stroke-width="${at(.12*t)}" stroke-linecap="round" opacity="0.55"/>`)}R.push("</g>")}R.push('<g data-band="parcel-fields">');for(let O of e.fields){if(!a[O.glyph])continue;let Y=Od(O.glyph,O.furrowBearingDeg);R.push(`<path data-field="${O.id}" d="${Ga(O.polygon,c,k)}" fill="url(#${Y})" stroke="none"/>`),R.push(Pa(O.polygon.map(rt=>({x:c(rt.x),y:k(rt.y)})),O.glyph,t,O.id))}for(let O of s){if(!a[O.glyph])continue;let rt=re(O.glyph)[0]*t/64;R.push(`<use data-edge="${O.id}" href="#${O.glyph}" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) rotate(${at(O.bearingDeg)}) scale(${at(rt)}) translate(-32,-32)"/>`)}R.push("</g>");let F=V.map(O=>Ga(O,c,k)),H=`road-land-${(F.join("").split("").reduce((O,Y)=>Math.imul(O,31)+Y.charCodeAt(0)|0,0)>>>0).toString(36)}`;F.length&&R.push(`<defs><mask id="${H}" maskUnits="userSpaceOnUse" x="0" y="0" width="${at(d)}" height="${at(h)}"><rect width="${at(d)}" height="${at(h)}" fill="white"/>${F.map(O=>`<path d="${O}" fill="black"/>`).join("")}</mask></defs>`),R.push(`<g data-band="route" ${F.length?`mask="url(#${H})" `:""}fill="none" stroke="#8a6f4a" stroke-linecap="round" stroke-linejoin="round">`);let X=Na(e.lanes),nt=[...e.lanes].sort((O,Y)=>Y.widthM-O.widthM||O.id.localeCompare(Y.id));for(let[O,Y]of nt.entries()){let rt=X.get(Y.id),yt=rt?.map(J=>`${at(c(J.x))},${at(k(J.y))}`).join(" ")??"",B=[...yt].reduce((J,lt)=>Math.imul(J,31)+lt.charCodeAt(0)|0,0)>>>0,U=`road-surface-${O}-${B.toString(36)}`;rt&&R.push(`<defs><clipPath id="${U}"><polygon points="${yt}"/></clipPath></defs>`);let $=Y.points.map((J,lt)=>`${lt===0?"M":"L"}${at(c(J.x))},${at(k(J.y))}`).join(" ");R.push(`<path data-lane="${Y.id}" d="${$}" ${rt?`clip-path="url(#${U})" `:""}stroke-width="${at(Qt(Y).surfaceM*t)}"/>`)}if(R.push("</g>"),e.bridges.some(O=>O.narrow&&O.deck&&O.centreline)){R.push('<g data-band="bridge" fill="#c3aa80" stroke="#594e40" stroke-linejoin="round">');for(let O of e.bridges){if(!O.narrow||!O.deck||!O.centreline)continue;let Y=e.lanes.find(rt=>rt.id===O.laneId);R.push(`<g data-bridge="${O.id}">${Za(O.centreline.map(rt=>({x:c(rt.x),y:k(rt.y)})),(Qt(Y).surfaceM+.7)*t,e.site.biome,Y.type==="main")}</g>`)}R.push("</g>")}R.push('<g data-band="parcel">');let mt=e.green.diameter/2*t;if(e.green.outline&&e.green.shape==="sm-green-triangle"){let O=e.green.outline.map(B=>({x:c(B.x),y:k(B.y)})),Y=O.map(B=>B.x),rt=O.map(B=>B.y),yt=O.map((B,U)=>`${U?"L":"M"}${at(B.x)},${at(B.y)}`).join(" ")+"Z";R.push(`<g data-green="junction">${Br(yt,e.site.biome,{unit:t*.6,id:"junction",bounds:[Math.min(...Y),Math.min(...rt),Math.max(...Y)-Math.min(...Y),Math.max(...rt)-Math.min(...rt)]})}</g>`)}else b&&R.push(`<use href="#${x}" transform="translate(${at(c(e.green.centre.x))},${at(k(e.green.centre.y))}) rotate(${at(e.green.bearingDeg-(e.green.shape.includes("lens")?90:0))}) scale(${at(mt*2/64)}) translate(-32,-32)"/>`);R.push("</g>"),R.push('<g data-band="structure">'),R.push(`<g transform="translate(${at(Da[0])},${at(Da[1])})" opacity="${r.shadowOpacity}" color="${r.shadowColor}">`);for(let O of p){if(!a[O.glyph]?.sil)continue;let Y=O.footprint[0]*t/64;R.push(`<use data-shadow="1" data-kind="${O.kind}" href="#${O.glyph}-sil" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) rotate(${at(O.bearingDeg)}) scale(${at(Y)}) translate(-32,-32)"/>`)}R.push("</g>");for(let O of p){if(!a[O.glyph])continue;let Y=O.footprint[0]*t/64;R.push(`<use data-ink="1" data-kind="${O.kind}" data-id="${O.id}" href="#${O.glyph}" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) rotate(${at(O.bearingDeg)}) scale(${at(Y)}) translate(-32,-32)"/>`)}R.push("</g>"),e.wall&&R.push(`<g data-band="walls" transform="translate(${at(c(0))},${at(k(0))}) scale(${at(t)})">${xa(e.wall,e.site.biome)}</g>`),R.push('<g data-band="canopy">'),R.push(`<g transform="translate(${at(Da[0])},${at(Da[1])})" opacity="${r.shadowOpacity}" color="${r.shadowColor}">`);for(let O of e.vegetation){if(!a[O.glyph]?.sil)continue;let rt=re(O.glyph)[0]*t/64*(O.scale??1);R.push(`<use data-shadow="1" data-kind="tree" href="#${O.glyph}-sil" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) scale(${at(rt)}) translate(-32,-32)"/>`)}R.push("</g>");for(let O of e.vegetation){if(!a[O.glyph])continue;let rt=re(O.glyph)[0]*t/64*(O.scale??1);R.push(`<use data-ink="1" data-kind="tree" data-id="${O.id}" href="#${O.glyph}" transform="translate(${at(c(O.position.x))},${at(k(O.position.y))}) scale(${at(rt)}) translate(-32,-32)"/>`)}return R.push("</g>"),R.push("</svg>"),Ai(R.join(`
|
|
586
586
|
`),{...jo,...sr,...$o(r.tokens)})}var Ae=e=>[e.x,e.y],W2=e=>{let t=e.map(Ae);return t.length>0&&(t[0][0]!==t[t.length-1][0]||t[0][1]!==t[t.length-1][1])&&t.push(t[0]),t};function Jc(e){let t=pe(e.glyph,e.footprint),r=t.width/2,o=t.depth/2,i=e.bearingDeg*Math.PI/180,a=Math.cos(i),s=Math.sin(i),n=(l,d)=>new Z(e.position.x+l*a-d*s,e.position.y+l*s+d*a);return W2([n(-r,-o),n(r,-o),n(r,o),n(-r,o)])}function t9(e){let t=[],r=[],o=a=>{t.push(a.x),r.push(a.y)};for(let a of e.buildings)o(a.position);for(let a of e.lanes)if(!Ot(a.id))for(let s of a.points)o(s);for(let a of e.fields)for(let s of a.polygon)o(s);for(let a of e.vegetation)o(a.position);if(o(e.green.centre),t.length===0)return{min_x:0,min_y:0,max_x:0,max_y:0};let i=20;return{min_x:Math.min(...t)-i,min_y:Math.min(...r)-i,max_x:Math.max(...t)+i,max_y:Math.max(...r)+i}}function Vd(e){let t=t9(e);return Math.max(t.max_x-t.min_x,t.max_y-t.min_y)}function jd(e){let t=[];for(let i of e.buildings)t.push({type:"Feature",properties:{layer:"building",building_id:i.id,lot_id:i.lotId,glyph:i.glyph,occupancy:i.occupancy,bearing_deg:i.bearingDeg},geometry:{type:"Polygon",coordinates:[Jc(i)]}});let r=Na(e.lanes);for(let i of e.lanes){if(i.points.length<2)continue;let a=i.sourceRouteIds??[];t.push({type:"Feature",properties:{layer:"street",street_id:i.id,streetType:i.type,width_m:i.widthM,surface_width_m:Qt(i).surfaceM,...i.routeRole?{route_role:i.routeRole}:{},...r.has(i.id)?{surface_clip_m:r.get(i.id).map(Ae)}:{},setback_m:Qt(i).setbackM,...a.length>0?{route_ids:a}:{},...i.parentId!==void 0?{parent_street_id:i.parentId}:{}},geometry:{type:"LineString",coordinates:i.points.map(Ae)}})}t.push({type:"Feature",properties:{layer:"green",shape:e.green.shape,variant:e.green.variant,diameter_m:e.green.diameter,bearing_deg:e.green.bearingDeg,relation:e.greenRelation,...e.green.outline?{outline_m:e.green.outline.map(Ae)}:{}},geometry:{type:"Point",coordinates:Ae(e.green.centre)}});for(let i of e.fields)t.push({type:"Feature",properties:{layer:"field",field_id:i.id,glyph:i.glyph,furrow_bearing_deg:i.furrowBearingDeg},geometry:{type:"Polygon",coordinates:[W2(i.polygon)]}});(J5(e.site.water)??e.site.water.map(i=>[i])).forEach((i,a)=>{i[0].length<3||t.push({type:"Feature",properties:{layer:"water",water_id:`w${a}`},geometry:{type:"Polygon",coordinates:i.map(W2)}})});for(let i of e.bridges)t.push({type:"Feature",properties:{layer:"crossing",crossing_id:i.id,street_id:i.laneId,span_m:i.spanM,bearing_deg:i.bearingDeg,narrow:i.narrow,...i.deck?{deck_m:i.deck.map(Ae),centreline_m:i.centreline?.map(Ae)}:{}},geometry:{type:"Point",coordinates:Ae(i.position)}});e.wall&&(e.wall.polylines.forEach((i,a)=>t.push({type:"Feature",properties:{layer:"wall",wall_id:`village-wall:${a}`,wallType:"village_wall",material:e.wall.material},geometry:{type:"LineString",coordinates:i.map(Ae)}})),e.wall.gates.forEach((i,a)=>t.push({type:"Feature",properties:{layer:"gate",gate_id:`village-gate:${a}`,route_ids:i.routeIds},geometry:{type:"Point",coordinates:[(i.p1.x+i.p2.x)/2,(i.p1.y+i.p2.y)/2]}})));for(let i of e.trunkJunctions)t.push({type:"Feature",properties:{layer:"junction",junction_id:i.id,street_ids:i.laneIds},geometry:{type:"Point",coordinates:Ae(i.position)}});for(let i of e.pois)t.push({type:"Feature",properties:{layer:"poi",poi_id:i.id,kind:i.kind,glyph:i.glyph,bearing_deg:i.bearingDeg},geometry:{type:"Point",coordinates:Ae(i.position)}});return{type:"FeatureCollection",features:t,metadata:{schema_version:vi,settlemaker_version:wi,settlement_generation_version:"village",coordinate_system:"burg_local_y_down",coordinate_units:"metres",generated_at:new Date().toISOString(),local_bounds:{min_x:e.frame.minX,min_y:e.frame.minY,max_x:e.frame.maxX,max_y:e.frame.maxY},scale:{meters_per_unit:1,diameter_meters:Vd(e),diameter_local:Vd(e),source:"village_metres"},stable_ids:{prefixes:{building:"bld:",poi:"poi:",street:"<lane id>",crossing:"bridge:"}},poi_density:ei(e.site.population),degraded_flags:[],local_origin_shift:{dx:0,dy:0,source:"none"},contract_radius_m:e.contractRadiusM,green_relation:e.greenRelation,...e.green.outline?{outline_m:e.green.outline.map(Ae)}:{},diagnostics:e.diagnostics}}}function e9(e,t){Object.hasOwn(e,"waterContext")&&Ar({...e,population:1001});let r=t?.skin??t?.svg?.skin,o=t?.svg?.skinBiome??e.biome,i=r?{...e,biome:Go(r,o).base}:e,a=qi(i,t?.seed),s={...a,coastlineGeometry:void 0,harbourSize:void 0},n=new Zo(s).probeWallRadius(),l=H5(a.coastlineGeometry,n)??kr,d=l.source==="coast_pull"?{...a,coastlineGeometry:a.coastlineGeometry?.map(f=>f.map(m=>new Z(m.x-l.dx,m.y-l.dy)))}:a,h=new Zo(d).generate(),c=k2(h,{...t?.svg,skin:r,skinBiome:o,shift:l}),k=c2(h,{...t?.geojson,shift:l}),p=[...h.degradedFlags].sort();return{model:h,svg:c,geojson:k,degradedFlags:p,originShift:l}}function Bu(e,t){if(Ar(e),(e.population??0)<=Id){let r=t?.seed??qi(e).seed,o=t?.skin,i=o?{...e,biome:Go(o,e.biome).base}:e,a=Ad(i,r);return{kind:"village",model:a,...a.site.waterContextResult?{waterContextResult:a.site.waterContextResult}:{},svg:zd(a,t?.village?.pxPerMetre,t?.village?.theme,{skin:o,skinBiome:e.biome}),geojson:jd(a),degradedFlags:[],originShift:kr}}return{kind:"settlement",...e9(e,t)}}export{Ke as ARTWORK_GLYPHS,fr as ARTWORK_INK,_t as ARTWORK_MANIFEST,Hr as CurtainWall,vi as GEOJSON_SCHEMA_VERSION,Me as Harbour,Zo as Model,Oi as PALETTES,kn as PALETTE_DEFAULT,Or as Patch,Z as Point,ht as Polygon,l6 as REFINED_SET,Ye as ROUTE_CLASS_ORDER,a2 as SCENE_VERSION,zo as SCHEMATIC_SET,wi as SETTLEMAKER_VERSION,Vo as SETTLEMENT_SET,mn as SKIN_SLOTS,x6 as SKIN_TOKENS,Hi as SKIN_VERSION,Vt as SeededRandom,Ti as TEMPERATE_THEME,Sa as URL_PAYLOAD_VERSION,ge as UrlCodecError,Qr as VILLAGE_BIOMES,Id as VILLAGE_POP_CEILING,At as WardType,je as WaterContextError,h2 as assembleSvg,ts as assetSetFor,s2 as buildScene,va as computeDiameterLocal,qr as computeLocalBounds,xo as computeSettlementScale,gh as computeTileInfo,Z6 as createSkin,bh as cropSvgToTile,uh as declaredMetersPerUnit,p2 as decodeBurgParam,Ca as decodeJsonParam,ck as encodeBurgParam,G5 as encodeJsonParam,xh as enumerateTiles,e9 as generateFromBurg,c2 as generateGeoJson,Bu as generateSettlement,k2 as generateSvg,Ad as generateVillage,jd as generateVillageGeoJson,qi as mapToGenerationParams,Ir as normaliseVillageBiome,os as paletteForBiome,gk as parseSettlementUrl,Mh as parseSvgViewBox,zd as renderVillage,$o as sanitizeVillageTokens,Go as skinBiomeFor,Do as themeFrom,$5 as themeToCss,Zh as totalTileCount,mr as villageThemeFor};
|
|
587
587
|
/*!
|
|
588
588
|
polygon-clipping
|