In this section
- Convergence 2km transform · gridatlas / tools/satnav/guidance/convergence-2km.mjs lines 1–72
- Convergence 2km Test test · gridatlas / tools/satnav/guidance/convergence-2km.test.mjs lines 1–153
- Convergence Preview storage · gridatlas / tools/satnav/guidance/convergence-preview.mjs lines 1–83
- Convergence Unlimited transform · gridatlas / tools/satnav/guidance/convergence-unlimited.mjs lines 1–69
- Ordered Convergence 2km render · gridatlas / tools/satnav/guidance/ordered-convergence-2km.mjs lines 1–125
- Ordered Convergence Unlimited render · gridatlas / tools/satnav/guidance/ordered-convergence-unlimited.mjs lines 1–115
Convergence 2km
A JavaScript module in the guidance folder of GridAtlas that classifies direct leg (`classifyDirectLeg`), reconciles navigation layers (`reconcileNavigationLayers`) and prepares asset destination (`prepareAssetDestination`) (units: kV).
transformgridatlas / tools/satnav/guidance/convergence-2km.mjs · lines 1–72 of 72 · pattern reconcileNavigationLayers (shared by 2 files)
- What it does
- It calculates its inputs. Defines 7 functions or classes, including classifyDirectLeg, directLegGeometry, reconcileNavigationLayers, prepareAssetDestination, valid.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Downstream impact
- Used directly by 3 files: Convergence 2km Test (gridatlas); Ordered Convergence 2km (gridatlas); Direct Convergence 2km (gridatlas). Reached from 3 other entry points, including GridAtlas PR File Size Guard Workflow (gridatlas); CI PR Gate (gridatlas); Map Promotion Rehearsal (gridatlas).
- What it achieves
- It classifies direct leg (`classifyDirectLeg`), prepares asset destination (`prepareAssetDestination`) and ranks higher voltage (`rankHigherVoltage`). Direct navigation is not a pedestrian route or evidence of access.
- Why it matters
- Imported by Ordered Convergence 2km and Direct Convergence 2km. Checked by Convergence 2km Test.
- Application
- gridatlas · tools/satnav/guidance · JavaScript module
- Uses
- none found
- Used by
- imported by Convergence 2km Test (import), imported by Ordered Convergence 2km (import), imported by Direct Convergence 2km (import), mentioned in Standalone (comment link)
- Produces
- MAX_DIRECT_LEG_M, DIRECT_LEG_EPSILON_M, classifyDirectLeg, directLegGeometry, reconcileNavigationLayers, prepareAssetDestination, rankHigherVoltage
- Defines here
- classifyDirectLeg, directLegGeometry, reconcileNavigationLayers, prepareAssetDestination, valid, rankHigherVoltage, valid
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/guidance/convergence-2km.mjs:1-72 · blob 440a3838829b41ab702e83078d5c2ae74cc88866 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: production_core
// SPDX-License-Identifier: Apache-2.0
// Direct navigation is not a pedestrian route or evidence of access.
export const MAX_DIRECT_LEG_M = 2000;
export const DIRECT_LEG_EPSILON_M = 0.000001;
export function classifyDirectLeg(maths, from, to) {
const metres = maths.distanceKm(...from, ...to) * 1000;
if (!Number.isFinite(metres) || metres < 0) throw new RangeError('Invalid direct leg');
if (metres > MAX_DIRECT_LEG_M + DIRECT_LEG_EPSILON_M) return {metres, status:'over-limit'};
if (Math.abs(from[0] - to[0]) > 180) return {metres, status:'antimeridian'};
return {metres, status:metres === 0 ? 'coincident' : 'ok'};
}
// The existing route follower accepts at most 1000 m per segment. Use at
// most four geodesic subdivisions, not additional user-visible waypoints.
export function directLegGeometry(maths, from, to) {
const leg = classifyDirectLeg(maths, from, to);
if (leg.status !== 'ok') return null;
const count = Math.ceil(leg.metres / 750);
const bearing = maths.initialBearingDeg(...from, ...to);
const coordinates = [[...from]];
for (let i = 1; i < count; i++) {
coordinates.push(maths.destinationPoint(...from, leg.metres / 1000 * i / count, bearing));
}
coordinates.push([...to]);
for (let i = 1; i < coordinates.length; i++) {
const a = coordinates[i-1], b = coordinates[i];
if (Math.abs(a[0]-b[0]) > 180 || maths.distanceKm(...a,...b) > 1) return null;
}
return {type:'LineString', coordinates};
}
// Only navigation-owned layers are moved. Do not mutate infrastructure
// visibility, source data, GPS, route state or map identity.
export function reconcileNavigationLayers(map, ids) {
if (!ids.every(id => map.getLayer(id))) return false;
for (const id of ids) {
if (map.getLayoutProperty(id,'visibility') === 'none') map.setLayoutProperty(id,'visibility','visible');
}
const order = map.getStyle()?.layers?.map(layer => layer.id) ?? [];
const tail = order.slice(-ids.length);
if (ids.every((id,i) => tail[i] === id)) return false;
for (const id of ids) map.moveLayer(id);
return true;
}
// Asset transfers are deliberate, atomic and based on a fresh measured origin.
// Do not change the existing plan when a proposed destination is unsupported.
export function prepareAssetDestination(maths, fix, at, tracking, quality) {
const valid = p => Array.isArray(p) && p.length === 2 && p.every(Number.isFinite)
&& Math.abs(p[0]) <= 180 && Math.abs(p[1]) <= 90;
if (!valid(at)) return {ok:false, reason:'Invalid destination coordinates'};
if (!tracking || quality !== 'usable' || !fix || !valid([fix.longitude,fix.latitude]))
return {ok:false,reason:'Start GPS and wait for a fresh, accurate fix'};
const from = [fix.longitude,fix.latitude];
const leg = classifyDirectLeg(maths,from,at);
if (leg.status !== 'ok') return {ok:false,reason:leg.status === 'over-limit'
? 'Direct leg exceeds 2 km; choose a nearer waypoint' : 'No supported direct leg',metres:leg.metres};
return {ok:true,coordinates:[from,[...at]],metres:leg.metres};
}
// Read the existing Grid Engine payload and calculator; do not infer topology.
export function rankHigherVoltage(nodes, origin, distanceKm, minimumKv = 33, limit = 5) {
if (!Array.isArray(nodes) || typeof distanceKm !== 'function') return [];
const valid = p => Array.isArray(p) && p.length === 2 && p.every(Number.isFinite)
&& Math.abs(p[0]) <= 180 && Math.abs(p[1]) <= 90;
if (!valid(origin)) return [];
return nodes.flatMap(node => {
if (!node || !valid(node.at)) return [];
const kv = Array.isArray(node.kv) ? node.kv.filter(Number.isFinite) : [];
if (!kv.some(v => v >= minimumKv)) return [];
const km = distanceKm(...origin,...node.at);
if (!Number.isFinite(km) || km <= 0) return [];
return [{name:String(node.name || 'Unnamed mapped substation'),at:[...node.at],kv:Math.max(...kv),km}];
}).sort((a,b)=>a.km-b.km || a.name.localeCompare(b.name)).slice(0,limit);
}Convergence 2km Test
A test in the guidance folder of GridAtlas that checks Convergence 2km and Ordered Convergence 2km.
testgridatlas / tools/satnav/guidance/convergence-2km.test.mjs · lines 1–153 of 153 · Entry point
- What it does
- It tests 11kV. Defines to, fix. Uses libraries node:test, node:assert/strict, node:vm. Side effects: reads or writes files.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work. Domain terms in the code: 11kV.
- Inputs & outputs
- Voltage levels named: 11kV.
- Downstream impact
- Used directly by 2 files: CI PR Gate (gridatlas); GridAtlas PR File Size Guard Workflow (gridatlas). Reached from 1 other entry point, including Map Promotion Rehearsal (gridatlas).
- What it achieves
- Defines `fix`.
- Why it matters
- Run by CI PR Gate and GridAtlas PR File Size Guard Workflow.
- Application
- gridatlas · tools/satnav/guidance · test
- Uses
- Convergence 2km (import), Ordered Convergence 2km (import), Direct Convergence 2km (import), Secondary Vicinity (import), node:test, node:assert/strict, ../vendor/9698781539e549deaa6ecaa4a2b34610c1f9fd29/vendor/grid-distance-maths/src/geodesy.mjs, node:vm
- Used by
- run by CI PR Gate (script call), run by GridAtlas PR File Size Guard Workflow (workflow run)
- Produces
- to, fix
- Defines here
- to, fix
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/guidance/convergence-2km.test.mjs:1-153 · blob ae8e4ae22b56441e313a85de859705f74fbbc859 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: ingest · effects: filesystem · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: production_core
import {test} from 'node:test';
import assert from 'node:assert/strict';
import * as maths from '../vendor/9698781539e549deaa6ecaa4a2b34610c1f9fd29/vendor/grid-distance-maths/src/geodesy.mjs';
import {classifyDirectLeg,directLegGeometry,reconcileNavigationLayers,prepareAssetDestination,rankHigherVoltage} from './convergence-2km.mjs';
import {createWaypointGuidance} from './ordered-convergence-2km.mjs';
import {createDirectWalk} from '../walk/direct-convergence-2km.mjs';
const from = [-0.4,51.55];
const to = metres => maths.destinationPoint(...from,metres/1000,90);
for (const m of [999,1000,1001,1999,2000,2001]) {
test('direct-leg boundary '+m+' m',()=>{
const end=to(m), leg=classifyDirectLeg(maths,from,end);
assert.ok(Math.abs(leg.metres-m)<0.000001);
assert.equal(leg.status,m<=2000?'ok':'over-limit');
const g=directLegGeometry(maths,from,end);
if(m>2000){assert.equal(g,null);return;}
assert.deepEqual(g.coordinates[0],from);
assert.deepEqual(g.coordinates.at(-1),end);
assert.ok(g.coordinates.length<=4);
for(let i=1;i<g.coordinates.length;i++) assert.ok(maths.distanceKm(...g.coordinates[i-1],...g.coordinates[i])<=1);
});
}
test('coincident and antimeridian legs are not drawn incorrectly',()=>{
assert.equal(classifyDirectLeg(maths,from,from).status,'coincident');
assert.equal(directLegGeometry(maths,from,from),null);
assert.equal(classifyDirectLeg(maths,[179.999,0],[-179.999,0]).status,'antimeridian');
assert.equal(directLegGeometry(maths,[179.999,0],[-179.999,0]),null);
});
const compass={fixQuality:()=> 'usable',guide:(fix,target)=>({distanceM:maths.distanceKm(fix.longitude,fix.latitude,...target.coordinates)*1000,accuracyM:fix.accuracyM,bearingDeg:0})};
const fix=(at,timestampMs)=>({longitude:at[0],latitude:at[1],accuracyM:3,timestampMs});
test('2 km ordered leg retains deviation capability and does not falsely arrive',()=>{
const walk=createWaypointGuidance(maths,compass);
walk.setRoute([{id:'a',coordinate:from},{id:'b',coordinate:to(2000)}]);
assert.equal(walk.locate(fix(from,1000),1000).status,'guiding');
const mid=walk.locate(fix(to(1000),2000),2000);
assert.equal(mid.status,'guiding');
assert.equal(mid.deviationAvailable,true);
assert.ok(Math.abs(mid.distanceM-1000)<0.001);
assert.equal(walk.locate(fix(to(2000),3000),3000).status,'complete');
});
test('direct single destination rejects 2001 m and permits 2000 m',()=>{
const walk=createDirectWalk(maths,compass);
walk.setTargets([{id:'b',coordinate:to(2001)}]);
assert.equal(walk.locate(fix(from,1000),1000).status,'over-limit');
walk.setTargets([{id:'b',coordinate:to(2000)}]);
assert.equal(walk.locate(fix(from,2000),2000).status,'guiding');
});
test('reconcile restores navigation visibility and ordering, then is idempotent',()=>{
let order=['accuracy','line','gps','secondary','vicinity'],moves=0;
const visibility={line:'none'};
const map={getLayer:id=>order.includes(id),getStyle:()=>({layers:order.map(id=>({id}))}),
getLayoutProperty:id=>visibility[id],setLayoutProperty:(id,k,v)=>visibility[id]=v,
moveLayer:id=>{moves++;order=order.filter(x=>x!==id).concat(id);}};
assert.equal(reconcileNavigationLayers(map,['accuracy','line','gps']),true);
assert.deepEqual(order,['secondary','vicinity','accuracy','line','gps']);
assert.equal(visibility.line,'visible');
assert.equal(reconcileNavigationLayers(map,['accuracy','line','gps']),false);
assert.equal(moves,3);
order.push('late-11kv');
assert.equal(reconcileNavigationLayers(map,['accuracy','line','gps']),true);
assert.deepEqual(order,['secondary','vicinity','late-11kv','accuracy','line','gps']);
});
test('unsupported planned intermediate leg cannot arrive even after a GPS jump',()=>{
const walk=createDirectWalk(maths,compass);
walk.setTargets([{id:'a',coordinate:from},{id:'b',coordinate:to(2001)},{id:'c',coordinate:to(2500)}]);
const first=walk.locate(fix(from,1000),1000);
assert.equal(first.status,'over-limit');
assert.equal(first.targetId,'b');
for(const time of [2000,2000,3000]){
const receipt=walk.locate(fix(to(2001),time),time);
assert.equal(receipt.status,'over-limit');
assert.equal(receipt.targetId,'b');
}
});
test('multiple valid legs may exceed 2 km in total without false arrival',()=>{
const walk=createDirectWalk(maths,compass);
walk.setTargets([{id:'a',coordinate:from},{id:'b',coordinate:to(1500)},{id:'c',coordinate:to(3000)}]);
assert.equal(walk.locate(fix(from,1000),1000).targetId,'b');
assert.equal(walk.locate(fix(to(1500),2000),2000).targetId,'c');
assert.equal(walk.locate(fix(to(3000),3000),3000).status,'complete');
});
test('over-limit GPS sample rejects an older apparent arrival',()=>{
const walk=createDirectWalk(maths,compass);
walk.setTargets([{id:'b',coordinate:to(2001)}]);
assert.equal(walk.locate(fix(from,2000),2000).status,'over-limit');
assert.equal(walk.locate(fix(to(2001),1000),2000).status,'waiting');
assert.equal(walk.locate(fix(to(2001),3000),3000).status,'complete');
});
test('asset destination requires fresh active GPS and preserves input',()=>{
const sample=fix(from,1000), at=to(2000);
const before=JSON.stringify({sample,at});
for(const quality of ['stale','poor','missing']) assert.equal(prepareAssetDestination(maths,sample,at,true,quality).ok,false);
assert.equal(prepareAssetDestination(maths,sample,at,false,'usable').ok,false);
assert.equal(prepareAssetDestination(maths,sample,[181,0],true,'usable').ok,false);
assert.equal(prepareAssetDestination(maths,sample,from,true,'usable').ok,false);
assert.equal(prepareAssetDestination(maths,sample,to(2001),true,'usable').ok,false);
const selected=prepareAssetDestination(maths,sample,at,true,'usable');
assert.equal(selected.ok,true);
assert.deepEqual(selected.coordinates,[from,at]);
assert.notEqual(selected.coordinates[1],at);
assert.equal(JSON.stringify({sample,at}),before);
});
test('higher voltage ranking uses supplied calculator and filters invalid or low voltage nodes',()=>{
const nodes=[{name:'far',at:to(1800),kv:[132]},{name:'near',at:to(300),kv:[11,33]},
{name:'secondary',at:to(100),kv:[11]},{name:'bad',at:[Infinity,0],kv:[400]},
{name:'same',at:from,kv:[33]},{name:'other',at:to(800),kv:[66]}];
let calls=0;
const ranked=rankHigherVoltage(nodes,from,(...p)=>{calls++;return maths.distanceKm(...p)},33,2);
assert.deepEqual(ranked.map(x=>x.name),['near','other']);
assert.equal(ranked[0].kv,33);
assert.equal(calls,4);
assert.deepEqual(rankHigherVoltage(null,from,maths.distanceKm),[]);
assert.deepEqual(rankHigherVoltage(nodes,[181,0],maths.distanceKm),[]);
});
import vm from 'node:vm';
import {buildSecondaryVicinity} from './secondary-vicinity.mjs';
test('secondary Vicinity derives from immutable source pins and preserves the existing project entry',()=>{
const {engine,focus}=buildSecondaryVicinity();
assert.match(engine,/openProjectVicinity,openSecondaryVicinity/);
assert.match(focus,/UKPN secondary \(origin\)/);
assert.match(engine,/UKPN transformer register/);
assert.match(engine,/CC BY 4\.0/);
assert.doesNotThrow(()=>new vm.Script(engine));
assert.doesNotThrow(()=>new vm.Script(focus));
});
test('secondary Vicinity accepts only the actual selected UKPN source feature and preserves map camera',()=>{
const {engine}=buildSecondaryVicinity();
const start=engine.indexOf('function openSecondaryVicinity(');
const end=engine.indexOf('function initProjectSwipe(',start);
assert.ok(start>=0&&end>start);
const calls=[], at=[-0.4,51.55];
const map={getSource:id=>id==='src-ukpn_secondary'?{serialize:()=>({data:{features:[{id:'UKPN-A',geometry:{type:'Point',coordinates:at}}]}})}:null,
getCenter:()=>({lng:-0.5,lat:51.6}),getZoom:()=>16};
const context={mh:()=>map,NS:{gridScope:{scope:()=>[]}},W:{__GRIDATLAS_NEON_LINKS__:{enableSubstationLayer:()=>{}}},
dcc:(...args)=>calls.push(args)};
vm.createContext(context);
vm.runInContext(engine.slice(start,end),context);
const open=context.openSecondaryVicinity;
for(const input of [null,{}, {site:'',at},{site:'made-up',at},{site:'UKPN-A',at:[-0.3,51.55]},{site:'UKPN-A',at:[Infinity,51.55]}]) assert.equal(open(input),false);
assert.equal(calls.length,0);
assert.equal(open({site:'UKPN-A',at}),true);
assert.equal(calls.length,1);
const [usedMap,record,,options]=calls[0];
assert.equal(usedMap,map);
assert.equal(record.p.id,'ukpn:UKPN-A');
assert.equal(record.p.site_id,'UKPN-A');
assert.equal(record.p.origin_kind,'ukpn-secondary');
assert.equal('repd_ref' in record.p,false);
assert.deepEqual(JSON.parse(JSON.stringify(options.cam)),{center:[-0.5,51.6],zoom:16});
assert.notEqual(record.a,at);
});Convergence Preview
A JavaScript module in the guidance folder of GridAtlas that reads manifest (`readManifest`), using SHA-256.
storagegridatlas / tools/satnav/guidance/convergence-preview.mjs · lines 1–83 of 83 · Entry point · pattern verify (shared by 34 files)
- What it does
- It loads data. Defines sha, readManifest, pin, verify. Uses libraries node:fs, node:path, node:assert/strict, node:crypto. Side effects: reads or writes files.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Inputs & outputs
- In: JSON file current.json. Out: JSON file current.json.
- Downstream impact
- Used directly by 2 files: CI PR Gate (gridatlas); GridAtlas PR File Size Guard Workflow (gridatlas). Reached from 1 other entry point, including Map Promotion Rehearsal (gridatlas).
- What it achieves
- It reads manifest (`readManifest`) and is built from the sha step (`sha`) and the pin step (`pin`). Run `regional-preview.mjs` first in a checkout containing both PRs. It reads `atlas/current.json` and writes `/current.json`.
- Why it matters
- Run by CI PR Gate and GridAtlas PR File Size Guard Workflow.
- Application
- gridatlas · tools/satnav/guidance · JavaScript module
- Uses
- Secondary Vicinity (import), node:fs, node:path, node:assert/strict, node:crypto
- Used by
- run by CI PR Gate (script call), run by GridAtlas PR File Size Guard Workflow (workflow run)
- Produces
- sha, readManifest, pin, verify
- Defines here
- sha, readManifest, pin, verify
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/guidance/convergence-preview.mjs:1-83 · blob b4acaef316e89ccaa4c0e5b450efe6cdc7afc283 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: filesystem · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: production_core
// SPDX-License-Identifier: Apache-2.0
// Disposable combined candidate. Run regional-preview.mjs first in a checkout
// containing both PRs. Does not publish or mutate the immutable releases.
import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import {createHash} from 'node:crypto';
import {buildSecondaryVicinity} from './secondary-vicinity.mjs';
const regional='atlas/v/regional-interface-ci';
const route='atlas/v/satnav-convergence-ci';
const historical='atlas/v/satnav-road-to-field-202611281725';
const live=fs.readFileSync('atlas/current.json');
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
const readManifest=dir=>JSON.parse(fs.readFileSync(dir+'/current.json','utf8'));
const candidate=readManifest(regional), walking=readManifest(historical);
assert.equal(candidate.composition_version,'regional-interface-ci','corrected regional candidate required');
assert.equal(walking.generation,'202611281725','unexpected SatNav predecessor');
assert.ok(candidate.cartridge_order.includes('ukpn-secondary-card'));
assert.ok(!fs.existsSync(route),'refusing to overwrite an existing preview');
const generation=new Date().toISOString().replace(/[-:T]/g,'').slice(0,12);
const built=buildSecondaryVicinity();
fs.mkdirSync(route);
try {
fs.copyFileSync(regional+'/index.html',route+'/index.html',fs.constants.COPYFILE_EXCL);
function pin(entry,filename,bytes) {
fs.writeFileSync(route+'/'+filename,bytes,{flag:'wx'});
const next={...entry,path:'./'+filename,generation,sha256:sha(bytes),bytes:bytes.length};
for(const k of ['assembled_from','contract','proof','byte_budget'])delete next[k];
return next;
}
function verify(dir,entry) {
const bytes=fs.readFileSync(path.resolve(dir,entry.path));
assert.equal(sha(bytes),entry.sha256,entry.id+' predecessor hash mismatch');
return bytes;
}
const expectedReplacements=new Set(['uk-offtakers-overlay','vicinity-focus']);
candidate.cartridges=candidate.cartridges.map(entry=>{
const bytes=verify(regional,entry);
if(entry.id==='uk-offtakers-overlay') {
expectedReplacements.delete(entry.id);
return pin(entry,'secondary-vicinity-engine.js',Buffer.from(built.engine));
}
if(entry.id==='vicinity-focus') {
expectedReplacements.delete(entry.id);
return pin(entry,'secondary-vicinity-focus.js',Buffer.from(built.focus));
}
if(entry.path.startsWith('./'))return pin(entry,path.basename(entry.path),bytes);
return entry;
});
assert.equal(expectedReplacements.size,0);
const ids=walking.cartridge_order.filter(id=>id.startsWith('satnav-'));
assert.equal(ids.length,7);
let after='ukpn-secondary-card';
for(const id of ids) {
const original=walking.cartridges.find(c=>c.id===id);
assert.ok(original && !candidate.cartridge_order.includes(id));
verify(historical,original);
let entry={...original,after};
if(id==='satnav-waypoint-map'||id==='satnav-start-walk'){
const name=id==='satnav-waypoint-map'?'waypoint-map':'gate-walk';
entry=pin(entry,'satnav-'+name+'.js',fs.readFileSync('atlas/modules/satnav-convergence-2km-'+name+'.js'));
}
candidate.cartridges.push(entry);
candidate.cartridge_order.push(id);
after=id;
}
candidate.previous_generation=candidate.generation;
candidate.generation=generation;
candidate.composition_id=generation+'-satnav-convergence-ci';
candidate.composition_version='satnav-convergence-ci';
delete candidate.composition_manifest;
assert.equal(new Set(candidate.cartridge_order).size,candidate.cartridge_order.length);
assert.equal(candidate.cartridges.length,candidate.cartridge_order.length);
for(const entry of candidate.cartridges)verify(route,entry);
fs.writeFileSync(route+'/current.json',JSON.stringify(candidate,null,1)+'\n',{flag:'wx'});
assert.deepEqual(fs.readFileSync('atlas/current.json'),live);
console.log('SATNAV CONVERGENCE CI '+JSON.stringify({route,generation,productionUnchanged:true,
cartridges:candidate.cartridges.map(({id,sha256,after})=>({id,sha256,after}))}));
} catch(error) {
fs.rmSync(route,{recursive:true,force:true});
throw error;
}Convergence Unlimited
A JavaScript module in the guidance folder of GridAtlas that classifies direct leg (`classifyDirectLeg`), reconciles navigation layers (`reconcileNavigationLayers`) and prepares asset destination (`prepareAssetDestination`) (units: kV).
transformgridatlas / tools/satnav/guidance/convergence-unlimited.mjs · lines 1–69 of 69 · Not reached from any entry point (candidate for review) · pattern reconcileNavigationLayers (shared by 2 files)
- What it does
- It calculates its inputs. Defines 7 functions or classes, including classifyDirectLeg, directLegGeometry, reconcileNavigationLayers, prepareAssetDestination, valid.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Downstream impact
- Used directly by 5 files: Distance Dock Proof (gridatlas); Ordered Convergence Unlimited (gridatlas); Orient17a Continuity Ordered (gridatlas); Orient17a Ordered (gridatlas); and 1 more.
- What it achieves
- It classifies direct leg (`classifyDirectLeg`), prepares asset destination (`prepareAssetDestination`) and ranks higher voltage (`rankHigherVoltage`). Direct navigation is not a pedestrian route or evidence of access.
- Why it matters
- Imported by 5 files, including Distance Dock Proof, Ordered Convergence Unlimited and Orient17a Continuity Ordered.
- Application
- gridatlas · tools/satnav/guidance · JavaScript module
- Uses
- none found
- Used by
- imported by Distance Dock Proof (import), imported by Ordered Convergence Unlimited (import), imported by Orient17a Continuity Ordered (import), imported by Orient17a Ordered (import), imported by Orient17a V9212 Ordered (import)
- Produces
- MAX_DEVIATION_LEG_M, classifyDirectLeg, directLegGeometry, reconcileNavigationLayers, prepareAssetDestination, rankHigherVoltage
- Defines here
- classifyDirectLeg, directLegGeometry, reconcileNavigationLayers, prepareAssetDestination, valid, rankHigherVoltage, valid
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/guidance/convergence-unlimited.mjs:1-69 · blob 11c5a7b4be1a00854e7652dcc512a91fcfafb6b2 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: duplicate_candidate
// SPDX-License-Identifier: Apache-2.0
// Direct navigation is not a pedestrian route or evidence of access.
// Deviation projection stays bounded; this is NOT a navigation distance limit.
export const MAX_DEVIATION_LEG_M = 2000;
export function classifyDirectLeg(maths, from, to) {
const metres = maths.distanceKm(...from, ...to) * 1000;
if (!Number.isFinite(metres) || metres < 0) throw new RangeError('Invalid direct leg');
if (Math.abs(from[0] - to[0]) > 180) return {metres, status:'antimeridian'};
return {metres, status:metres === 0 ? 'coincident' : 'ok'};
}
// Bounded drawing geometry at all distances; short legs retain <=750 m segments for deviation projection.
export function directLegGeometry(maths, from, to) {
const leg = classifyDirectLeg(maths, from, to);
if (leg.status !== 'ok') return null;
const count = Math.min(64,Math.ceil(leg.metres / 750));
const bearing = maths.initialBearingDeg(...from, ...to);
const coordinates = [[...from]];
for (let i = 1; i < count; i++) {
coordinates.push(maths.destinationPoint(...from, leg.metres / 1000 * i / count, bearing));
}
coordinates.push([...to]);
for (let i = 1; i < coordinates.length; i++) {
const a = coordinates[i-1], b = coordinates[i];
if (Math.abs(a[0]-b[0]) > 180 || !b.every(Number.isFinite)) return null;
}
return {type:'LineString', coordinates};
}
// Only navigation-owned layers are moved. Do not mutate infrastructure
// visibility, source data, GPS, route state or map identity.
export function reconcileNavigationLayers(map, ids) {
if (!ids.every(id => map.getLayer(id))) return false;
for (const id of ids) {
if (map.getLayoutProperty(id,'visibility') === 'none') map.setLayoutProperty(id,'visibility','visible');
}
const order = map.getStyle()?.layers?.map(layer => layer.id) ?? [];
const tail = order.slice(-ids.length);
if (ids.every((id,i) => tail[i] === id)) return false;
for (const id of ids) map.moveLayer(id);
return true;
}
// Asset transfers are deliberate, atomic and based on a fresh measured origin.
// Do not change the existing plan when a proposed destination is unsupported.
export function prepareAssetDestination(maths, fix, at, tracking, quality) {
const valid = p => Array.isArray(p) && p.length === 2 && p.every(Number.isFinite)
&& Math.abs(p[0]) <= 180 && Math.abs(p[1]) <= 90;
if (!valid(at)) return {ok:false, reason:'Invalid destination coordinates'};
if (!tracking || quality !== 'usable' || !fix || !valid([fix.longitude,fix.latitude]))
return {ok:false,reason:'Start GPS and wait for a fresh, accurate fix'};
const from = [fix.longitude,fix.latitude];
const leg = classifyDirectLeg(maths,from,at);
if (leg.status === 'coincident') return {ok:false,reason:'Destination coincides with origin',metres:leg.metres};
return {ok:true,coordinates:[from,[...at]],metres:leg.metres};
}
// Read the existing Grid Engine payload and calculator; do not infer topology.
export function rankHigherVoltage(nodes, origin, distanceKm, minimumKv = 33, limit = 5) {
if (!Array.isArray(nodes) || typeof distanceKm !== 'function') return [];
const valid = p => Array.isArray(p) && p.length === 2 && p.every(Number.isFinite)
&& Math.abs(p[0]) <= 180 && Math.abs(p[1]) <= 90;
if (!valid(origin)) return [];
return nodes.flatMap(node => {
if (!node || !valid(node.at)) return [];
const kv = Array.isArray(node.kv) ? node.kv.filter(Number.isFinite) : [];
if (!kv.some(v => v >= minimumKv)) return [];
const km = distanceKm(...origin,...node.at);
if (!Number.isFinite(km) || km <= 0) return [];
return [{name:String(node.name || 'Unnamed mapped substation'),at:[...node.at],kv:Math.max(...kv),km}];
}).sort((a,b)=>a.km-b.km || a.name.localeCompare(b.name)).slice(0,limit);
}Ordered Convergence 2km
A JavaScript module in the guidance folder of GridAtlas that creates waypoint guidance (`createWaypointGuidance`), selects leg (`selectLeg`) and sets route (`setRoute`).
rendergridatlas / tools/satnav/guidance/ordered-convergence-2km.mjs · lines 1–125 of 125 · pattern createWaypointGuidance (shared by 6 files)
- What it does
- Defines 9 functions or classes, including copyPin, createWaypointGuidance, selectLeg, setRoute, snapshot.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Inputs & outputs
- Coordinate systems named: WGS84 / EPSG:4326.
- Downstream impact
- Used directly by 2 files: Convergence 2km Test (gridatlas); Direct Convergence 2km (gridatlas). Reached from 3 other entry points, including GridAtlas PR File Size Guard Workflow (gridatlas); CI PR Gate (gridatlas); Map Promotion Rehearsal (gridatlas).
- What it achieves
- It copies pin (`copyPin`), creates waypoint guidance (`createWaypointGuidance`) and selects leg (`selectLeg`). Its `createWaypointGuidance` function gives guidance state with next target, distance, bearing, remaining distance and bounded deviation information from Geographical maths and compass modules, uniquely identified WGS84 pins, timestamped GPS fixes (VEDIC: follow waypoints).
- Why it matters
- Imported by Direct Convergence 2km. Checked by Convergence 2km Test.
- Application
- gridatlas · tools/satnav/guidance · JavaScript module
- VEDIC
- FOLLOW WAYPOINTS (GG2050-VEDIC-000097): SatNav · Location and navigation data. Geographical maths and compass modules, uniquely identified WGS84 pins, timestamped GPS fixes → Guidance state with next target, distance, bearing, remaining distance and bounded deviation information.
- Uses
- Route Follower (import), Convergence 2km (import)
- Used by
- imported by Convergence 2km Test (import), imported by Direct Convergence 2km (import), mentioned in Standalone (comment link)
- Produces
- createWaypointGuidance
- Defines here
- copyPin, createWaypointGuidance, selectLeg, setRoute, snapshot, locate, bearingToNext, unsupported, limitReceipt
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/guidance/ordered-convergence-2km.mjs:1-125 · blob 68dc244cd3f2199ca2c00ee0e0d7b6cc3d94afb6 · GitHub at these lines
- State
- achieves: code · context: readme_derived · stage: output · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: production_core
// SPDX-License-Identifier: Apache-2.0
import {createRouteFollower} from '../line/route-follower.mjs';
const MAX_PINS = 20_000;
const ARRIVAL_RADIUS_M = 15;
import {classifyDirectLeg, directLegGeometry, MAX_DIRECT_LEG_M, DIRECT_LEG_EPSILON_M} from './convergence-2km.mjs';
function copyPin(pin, ids) {
const at = pin?.coordinate;
if (typeof pin?.id !== 'string' || !pin.id || ids.has(pin.id)) {
throw new RangeError('Waypoints need unique IDs');
}
if (!Array.isArray(at) || at.length !== 2 || !at.every(Number.isFinite)
|| Math.abs(at[0]) > 180 || Math.abs(at[1]) > 90) {
throw new RangeError('Expected WGS84 [longitude, latitude]');
}
ids.add(pin.id);
return {id: pin.id, coordinate: [...at]};
}
/** Takes the same maths and compass modules used by the SatNav GPS watch. */
export function createWaypointGuidance(maths, compass) {
let route = [];
let remainingFromPin = [];
let next = 0;
let lastSample = -Infinity;
let followActiveLeg = null;
let deviationLimit = null;
function selectLeg() {
followActiveLeg = null;
deviationLimit = null;
if (next === 0 || next >= route.length) return;
const from = route[next - 1].coordinate;
const to = route[next].coordinate;
const leg = classifyDirectLeg(maths, from, to);
if (leg.status === 'over-limit') deviationLimit = 'over-2-km';
else if (leg.status === 'antimeridian') deviationLimit = 'antimeridian';
else if (leg.status === 'ok') {
const geometry = directLegGeometry(maths, from, to);
if (geometry) followActiveLeg = createRouteFollower(geometry, maths);
else deviationLimit = 'geometry-unavailable';
}
}
function setRoute(pins) {
if (!Array.isArray(pins) || pins.length > MAX_PINS) throw new RangeError('Too many waypoints');
const ids = new Set();
const updated = Array.from(pins, pin => copyPin(pin, ids));
const remaining = Array(updated.length).fill(0);
for (let i = updated.length - 2; i >= 0; i--) {
const metres = maths.distanceKm(...updated[i].coordinate, ...updated[i + 1].coordinate) * 1000;
if (!Number.isFinite(metres)) throw new RangeError('Cannot measure this section');
remaining[i] = remaining[i + 1] + metres;
}
// Preserve the visited prefix when editing points further along the route.
let visited = 0;
while (visited < next && visited < updated.length) {
const old = route[visited], pin = updated[visited];
if (old.id !== pin.id || !old.coordinate.every((value, i) => value === pin.coordinate[i])) break;
visited++;
}
route = updated;
remainingFromPin = remaining;
next = visited;
selectLeg();
}
function snapshot(status, quality) {
const target = route.length >= 2 ? route[next] : null;
return {
status, quality, targetIndex: target ? next : null, targetId: target?.id ?? null,
distanceM: null, bearingDeg: null, remainingM: status === 'complete' ? 0 : null,
plannedM: remainingFromPin[0] ?? 0,
offRoute: null, deviationAvailable: false, deviationLimit: null
};
}
function locate(fix, now = Date.now()) {
const quality = compass.fixQuality(fix, now);
if (route.length < 2) return snapshot('draft', quality);
if (next >= route.length) return snapshot('complete', quality);
if (quality !== 'usable') return snapshot('waiting', quality);
if (fix.timestampMs < lastSample) return snapshot('waiting', 'out-of-order');
const bearingToNext = () => compass.guide(fix, {coordinates: route[next].coordinate}, now);
let guidance = bearingToNext();
// A single measured fix may visit one pin. A repaint can never visit another.
const fresh = fix.timestampMs > lastSample;
lastSample = fix.timestampMs;
const unsupported = () => deviationLimit === 'over-2-km' ||
guidance?.distanceM > MAX_DIRECT_LEG_M + DIRECT_LEG_EPSILON_M;
const limitReceipt = () => ({
...snapshot('over-limit', quality), distanceM: guidance?.distanceM ?? null,
deviationLimit: 'over-2-km'
});
// An unsupported planned leg cannot be completed by a GPS jump or a
// repaint. Check before advancement and again for the newly active leg.
if (unsupported()) return limitReceipt();
if (fresh && guidance && guidance.distanceM + guidance.accuracyM <= ARRIVAL_RADIUS_M) {
next++;
selectLeg();
if (next >= route.length) return snapshot('complete', quality);
guidance = bearingToNext();
if (unsupported()) return limitReceipt();
}
if (!Number.isFinite(guidance?.distanceM)) return snapshot('waiting', 'unavailable');
// Direct guidance remains available on long legs. The follower's bounded
// active-leg projection supplies deviation only where supported.
const projectionSafe = followActiveLeg
&& Math.abs(fix.longitude - route[next - 1].coordinate[0]) <= 180
&& Math.abs(fix.longitude - route[next].coordinate[0]) <= 180;
const leg = projectionSafe ? followActiveLeg(fix, now) : null;
return {
...snapshot('guiding', quality),
distanceM: guidance.distanceM, bearingDeg: guidance.bearingDeg,
remainingM: guidance.distanceM + remainingFromPin[next],
offRoute: leg?.offRoute ?? null, deviationAvailable: leg?.status === 'ok',
deviationLimit: followActiveLeg && !projectionSafe ? 'antimeridian' : deviationLimit
};
}
return {setRoute, locate};
}Ordered Convergence Unlimited
A JavaScript module in the guidance folder of GridAtlas that creates waypoint guidance (`createWaypointGuidance`), selects leg (`selectLeg`) and sets route (`setRoute`).
rendergridatlas / tools/satnav/guidance/ordered-convergence-unlimited.mjs · lines 1–115 of 115 · Not reached from any entry point (candidate for review) · pattern createWaypointGuidance (shared by 6 files)
- What it does
- Defines 7 functions or classes, including copyPin, createWaypointGuidance, selectLeg, setRoute, snapshot.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Inputs & outputs
- Coordinate systems named: WGS84 / EPSG:4326.
- Downstream impact
- Used directly by 2 files: Distance Dock Proof (gridatlas); Direct Convergence Unlimited (gridatlas).
- What it achieves
- It copies pin (`copyPin`), creates waypoint guidance (`createWaypointGuidance`) and selects leg (`selectLeg`). Its `createWaypointGuidance` function gives guidance state with next target, distance, bearing, remaining distance and bounded deviation information from Geographical maths and compass modules, uniquely identified WGS84 pins, timestamped GPS fixes (VEDIC: follow waypoints).
- Why it matters
- Imported by Distance Dock Proof and Direct Convergence Unlimited.
- Application
- gridatlas · tools/satnav/guidance · JavaScript module
- VEDIC
- FOLLOW WAYPOINTS (GG2050-VEDIC-000097): SatNav · Location and navigation data. Geographical maths and compass modules, uniquely identified WGS84 pins, timestamped GPS fixes → Guidance state with next target, distance, bearing, remaining distance and bounded deviation information.
- Uses
- Route Follower (import), Convergence Unlimited (import)
- Used by
- imported by Distance Dock Proof (import), imported by Direct Convergence Unlimited (import)
- Produces
- createWaypointGuidance
- Defines here
- copyPin, createWaypointGuidance, selectLeg, setRoute, snapshot, locate, bearingToNext
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/guidance/ordered-convergence-unlimited.mjs:1-115 · blob 043ecf9bd7ee7cad78e07daa5efd1842334bd0c4 · GitHub at these lines
- State
- achieves: code · context: readme_derived · stage: output · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: duplicate_candidate
// SPDX-License-Identifier: Apache-2.0
import {createRouteFollower} from '../line/route-follower.mjs';
const MAX_PINS = 20_000;
const ARRIVAL_RADIUS_M = 15;
import {classifyDirectLeg, directLegGeometry, MAX_DEVIATION_LEG_M} from './convergence-unlimited.mjs';
function copyPin(pin, ids) {
const at = pin?.coordinate;
if (typeof pin?.id !== 'string' || !pin.id || ids.has(pin.id)) {
throw new RangeError('Waypoints need unique IDs');
}
if (!Array.isArray(at) || at.length !== 2 || !at.every(Number.isFinite)
|| Math.abs(at[0]) > 180 || Math.abs(at[1]) > 90) {
throw new RangeError('Expected WGS84 [longitude, latitude]');
}
ids.add(pin.id);
return {id: pin.id, coordinate: [...at]};
}
/** Takes the same maths and compass modules used by the SatNav GPS watch. */
export function createWaypointGuidance(maths, compass) {
let route = [];
let remainingFromPin = [];
let next = 0;
let lastSample = -Infinity;
let followActiveLeg = null;
let deviationLimit = null;
function selectLeg() {
followActiveLeg = null;
deviationLimit = null;
if (next === 0 || next >= route.length) return;
const from = route[next - 1].coordinate;
const to = route[next].coordinate;
const leg = classifyDirectLeg(maths, from, to);
if (leg.status === 'antimeridian') deviationLimit = 'antimeridian';
else if (leg.metres > MAX_DEVIATION_LEG_M) deviationLimit = 'projection-unavailable';
else if (leg.status === 'ok') {
const geometry = directLegGeometry(maths, from, to);
if (geometry) followActiveLeg = createRouteFollower(geometry, maths);
else deviationLimit = 'geometry-unavailable';
}
}
function setRoute(pins) {
if (!Array.isArray(pins) || pins.length > MAX_PINS) throw new RangeError('Too many waypoints');
const ids = new Set();
const updated = Array.from(pins, pin => copyPin(pin, ids));
const remaining = Array(updated.length).fill(0);
for (let i = updated.length - 2; i >= 0; i--) {
const metres = maths.distanceKm(...updated[i].coordinate, ...updated[i + 1].coordinate) * 1000;
if (!Number.isFinite(metres)) throw new RangeError('Cannot measure this section');
remaining[i] = remaining[i + 1] + metres;
}
// Preserve the visited prefix when editing points further along the route.
let visited = 0;
while (visited < next && visited < updated.length) {
const old = route[visited], pin = updated[visited];
if (old.id !== pin.id || !old.coordinate.every((value, i) => value === pin.coordinate[i])) break;
visited++;
}
route = updated;
remainingFromPin = remaining;
next = visited;
selectLeg();
}
function snapshot(status, quality) {
const target = route.length >= 2 ? route[next] : null;
return {
status, quality, targetIndex: target ? next : null, targetId: target?.id ?? null,
distanceM: null, bearingDeg: null, remainingM: status === 'complete' ? 0 : null,
plannedM: remainingFromPin[0] ?? 0,
offRoute: null, deviationAvailable: false, deviationLimit: null
};
}
function locate(fix, now = Date.now()) {
const quality = compass.fixQuality(fix, now);
if (route.length < 2) return snapshot('draft', quality);
if (next >= route.length) return snapshot('complete', quality);
if (quality !== 'usable') return snapshot('waiting', quality);
if (fix.timestampMs < lastSample) return snapshot('waiting', 'out-of-order');
const bearingToNext = () => compass.guide(fix, {coordinates: route[next].coordinate}, now);
let guidance = bearingToNext();
// A single measured fix may visit one pin. A repaint can never visit another.
const fresh = fix.timestampMs > lastSample;
lastSample = fix.timestampMs;
if (fresh && guidance && guidance.distanceM + guidance.accuracyM <= ARRIVAL_RADIUS_M) {
next++;
selectLeg();
if (next >= route.length) return snapshot('complete', quality);
guidance = bearingToNext();
}
if (!Number.isFinite(guidance?.distanceM)) return snapshot('waiting', 'unavailable');
// Direct guidance remains available on long legs. The follower's bounded
// active-leg projection supplies deviation only where supported.
const projectionSafe = followActiveLeg
&& Math.abs(fix.longitude - route[next - 1].coordinate[0]) <= 180
&& Math.abs(fix.longitude - route[next].coordinate[0]) <= 180;
const leg = projectionSafe ? followActiveLeg(fix, now) : null;
return {
...snapshot('guiding', quality),
distanceM: guidance.distanceM, bearingDeg: guidance.bearingDeg,
remainingM: guidance.distanceM + remainingFromPin[next],
offRoute: leg?.offRoute ?? null, deviationAvailable: leg?.status === 'ok',
deviationLimit: followActiveLeg && !projectionSafe ? 'antimeridian' : deviationLimit
};
}
return {setRoute, locate};
}