In this section
- Ordered render · gridatlas / tools/satnav/guidance/ordered.mjs lines 1–116
- Ordered Test test · gridatlas / tools/satnav/guidance/ordered.test.mjs lines 1–185
- Orient17a Continuity Ordered render · gridatlas / tools/satnav/guidance/orient17a-continuity-ordered.mjs lines 1–129
- Orient17a Ordered render · gridatlas / tools/satnav/guidance/orient17a-ordered.mjs lines 1–122
- Orient17a V9212 Ordered render · gridatlas / tools/satnav/guidance/orient17a-v9212-ordered.mjs lines 1–129
Ordered
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.mjs · lines 1–116 of 116 · 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: Ordered Test (gridatlas); Direct (gridatlas). Reached from 2 other entry points, including GridAtlas PR File Size Guard Workflow (gridatlas); Direct Test (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. Checked by Ordered 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)
- Used by
- imported by Ordered Test (import), imported by Direct (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.mjs:1-116 · blob d6d0d0c5a8ac48ffa97a5d2a1d3fa2c50e3616f9 · 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;
const MAX_FOLLOWER_LEG_M = 1_000;
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 length = maths.distanceKm(...from, ...to) * 1000;
// The existing local projection takes unwrapped longitude differences.
if (Math.abs(from[0] - to[0]) > 180) {
deviationLimit = 'antimeridian';
} else if (length > MAX_FOLLOWER_LEG_M) {
deviationLimit = 'over-1-km';
} else if (length > 0) {
followActiveLeg = createRouteFollower({type: 'LineString', coordinates: [from, to]}, maths);
}
}
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};
}Ordered Test
A test in the guidance folder of GridAtlas that checks Ordered. It is built from the close step (`close`).
testgridatlas / tools/satnav/guidance/ordered.test.mjs · lines 1–185 of 185 · Entry point · pattern route (shared by 12 files)
- What it does
- It tests its inputs. Defines fix, pin, route, close. Uses libraries node:test, node:assert/strict, node:path, node:url.
- 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 1 file: GridAtlas PR File Size Guard Workflow (gridatlas).
- What it achieves
- Defines `fix`, `pin`, `route` and 1 more.
- Why it matters
- Run by GridAtlas PR File Size Guard Workflow.
- Application
- gridatlas · tools/satnav/guidance · test
- Uses
- Ordered (import), node:test, node:assert/strict, node:path, node:url
- Used by
- run by GridAtlas PR File Size Guard Workflow (workflow run)
- Produces
- fix, pin, route, close
- Defines here
- fix, pin, route, close
- 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.test.mjs:1-185 · blob ddc8bed462045c1fd3be2536113639b5e135bbb0 · GitHub at these lines
- State
- achieves: name · 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 test from 'node:test';
import assert from 'node:assert/strict';
import {resolve} from 'node:path';
import {pathToFileURL} from 'node:url';
import {createWaypointGuidance} from './ordered.mjs';
const stored = '../vendor/9698781539e549deaa6ecaa4a2b34610c1f9fd29/';
const root = process.env.SATNAV_COMPASS_ROOT
? pathToFileURL(resolve(process.env.SATNAV_COMPASS_ROOT) + '/')
: new URL(stored, import.meta.url);
const maths = await import(new URL('vendor/grid-distance-maths/src/geodesy.mjs', root));
const compass = await import(new URL('nav/compass.mjs', root));
const now = 10_000;
const start = [-0.1, 51.5];
const east = maths.destinationPoint(...start, 0.1, 90);
const north = maths.destinationPoint(...east, 0.1, 0);
const fix = (at, timestampMs = now, accuracyM = 3) => ({
longitude: at[0], latitude: at[1], accuracyM, timestampMs
});
const pin = (id, coordinate) => ({id, coordinate});
const pins = [pin('from', start), pin('middle', east), pin('to', north)];
function route(points = pins) {
const guidance = createWaypointGuidance(maths, compass);
guidance.setRoute(points);
return guidance;
}
function close(actual, expected, tolerance = 0.01) {
assert.ok(Math.abs(actual - expected) < tolerance, `${actual} differs from ${expected}`);
}
test('the first unvisited pin remains the only target, even at a later pin', () => {
const g = route();
const atEnd = g.locate(fix(north), now);
assert.equal(atEnd.targetId, 'from');
assert.equal(atEnd.status, 'guiding');
close(atEnd.plannedM, 200);
close(atEnd.remainingM, atEnd.distanceM + 200);
assert.equal(atEnd.offRoute, null);
});
test('an ordered walk uses canonical bearings and distance to the remaining pins', () => {
const g = route();
const leg = g.locate(fix(start), now);
assert.equal(leg.targetIndex, 1);
close(leg.bearingDeg, 90);
close(leg.remainingM, 200);
assert.equal(leg.offRoute, false);
const turn = g.locate(fix(east, now + 1), now + 1);
assert.equal(turn.targetId, 'to');
close(turn.bearingDeg, 0);
close(turn.remainingM, 100);
const end = g.locate(fix(north, now + 2), now + 2);
assert.equal(end.status, 'complete');
assert.equal(end.remainingM, 0);
assert.equal(end.bearingDeg, null);
assert.equal(end.targetId, null);
assert.equal(g.locate(null, now + 3).status, 'complete');
});
test('stale, invalid, missing, poor and out-of-order fixes cannot advance', () => {
const g = route();
const rejected = [
[null, 'missing'], [fix(start, -1), 'stale'], [fix(start, now + 1), 'stale'],
[fix([181, 0]), 'invalid'], [fix(start, now, 31), 'poor']
];
for (const [sample, quality] of rejected) {
const row = g.locate(sample, now);
assert.equal(row.status, 'waiting');
assert.equal(row.quality, quality);
assert.equal(row.targetIndex, 0);
assert.equal(row.bearingDeg, null);
}
g.locate(fix(start), now);
const late = g.locate(fix(east, now - 1), now);
assert.equal(late.quality, 'out-of-order');
assert.equal(late.targetId, 'middle');
});
test('the accuracy circle must fit the arrival radius, no false bearing in it', () => {
const g = route();
const uncertain = g.locate(fix(start, now, 20), now);
assert.equal(uncertain.targetIndex, 0);
assert.equal(uncertain.bearingDeg, null);
const closeBy = maths.destinationPoint(...start, 0.012, 45);
const near = g.locate(fix(closeBy, now + 1, 10), now + 1);
assert.equal(near.targetIndex, 0);
const ok = g.locate(fix(start, now + 2, 15), now + 2);
assert.equal(ok.targetIndex, 1);
});
test('an accuracy or clock repaint cannot advance two overlapping pins', () => {
const g = route([pin('a', start), pin('b', start), pin('c', north)]);
assert.equal(g.locate(fix(start), now).targetId, 'b');
assert.equal(g.locate(fix(start), now + 1).targetId, 'b');
assert.equal(g.locate(fix(start, now + 1), now + 1).targetId, 'c');
});
test('a closed loop cannot finish while its middle waypoint is unvisited', () => {
const g = route([pin('A', start), pin('B', east), pin('A-return', start)]);
g.locate(fix(start), now);
assert.equal(g.locate(fix(start, now + 1), now + 1).targetId, 'B');
assert.equal(g.locate(fix(east, now + 2), now + 2).targetId, 'A-return');
assert.equal(g.locate(fix(start, now + 3), now + 3).status, 'complete');
});
test('deviation is relative to the current leg and respects fix uncertainty', () => {
const g = route();
g.locate(fix(start), now);
const middle = maths.destinationPoint(...start, 0.05, 90);
const offset = maths.destinationPoint(...middle, 0.04, 0);
assert.equal(g.locate(fix(offset, now + 1), now + 1).offRoute, true);
const lessCertain = g.locate(fix(offset, now + 2, 25), now + 2);
assert.equal(lessCertain.offRoute, false);
});
test('long and dateline-crossing legs retain compass guidance without a deviation claim', () => {
const long = route([pin('a', start), pin('b', maths.destinationPoint(...start, 2, 90))]);
const row = long.locate(fix(start), now);
close(row.remainingM, 2000);
close(row.bearingDeg, 90);
assert.equal(row.deviationAvailable, false);
assert.equal(row.offRoute, null);
assert.equal(row.deviationLimit, 'over-1-km');
const dateline = route([pin('a', [179.999, 0]), pin('b', [-179.999, 0])]);
const short = dateline.locate(fix([179.999, 0]), now);
close(short.remainingM, 222.64, 0.1);
assert.equal(short.deviationAvailable, false);
assert.equal(short.deviationLimit, 'antimeridian');
assert.equal(short.bearingDeg, 90);
});
test('a fix across the dateline cannot be projected onto a near-dateline leg', () => {
const g = route([pin('A', [179.996, 0]), pin('B', [179.999, 0])]);
assert.equal(g.locate(fix([179.996, 0]), now).deviationAvailable, true);
const row = g.locate(fix([-179.999, 0], now + 1), now + 1);
close(row.remainingM, 222.64, 0.1);
close(row.bearingDeg, 270);
assert.equal(row.offRoute, null);
assert.equal(row.deviationLimit, 'antimeridian');
});
test('edits to future pins keep progress and edits to visited pins revisit the first change', () => {
const g = route();
g.locate(fix(start), now);
g.locate(fix(east, now + 1), now + 1);
g.setRoute([...pins, pin('last', start)]);
assert.equal(g.locate(null, now).targetId, 'to');
g.setRoute([pin('from', start), pin('middle', north), pin('to', start)]);
assert.equal(g.locate(null, now).targetId, 'middle');
g.setRoute([pin('middle', north), pin('from', start)]);
assert.equal(g.locate(null, now).targetId, 'middle');
});
test('handles draft routes and rejects invalid or excessive edits atomically', () => {
const g = route();
for (const invalid of [
[pin('repeat', start), pin('repeat', north)], [pin('a', [181, 0])],
[pin('a', [0, Infinity])], Array(20_001).fill(pins[0]), null
]) assert.throws(() => g.setRoute(invalid), RangeError);
assert.equal(g.locate(null, now).targetId, 'from');
g.setRoute([]);
assert.equal(g.locate(null, now).status, 'draft');
g.setRoute([pins[0]]);
assert.equal(g.locate(fix(start), now).status, 'draft');
});
test('route inputs and caller-owned fixes are never mutated', () => {
const copied = pins.map(p => pin(p.id, [...p.coordinate]));
const current = Object.freeze(fix(start));
const g = route(copied);
copied[0].coordinate[0] = 180;
copied[1].id = 'renamed';
const row = g.locate(current, now);
assert.equal(row.targetId, 'middle');
close(row.remainingM, 200);
});
test('20,000 ordered pins can be loaded and located', () => {
const many = Array.from({length: 20_000}, (_, i) => pin(String(i), [i * 0.0001, 0]));
const g = route(many);
const row = g.locate(fix([0, 0]), now);
assert.equal(row.targetId, '1');
close(row.remainingM, maths.distanceKm(0, 0, 1.9999, 0) * 1000);
});Orient17a Continuity Ordered
A JavaScript module in the guidance folder of GridAtlas that creates waypoint guidance (`createWaypointGuidance`), selects leg (`selectLeg`) and resets evidence (`resetEvidence`).
rendergridatlas / tools/satnav/guidance/orient17a-continuity-ordered.mjs · lines 1–129 of 129 · Not reached from any entry point (candidate for review) · pattern resetEvidence (shared by 2 files)
- What it does
- Defines 9 functions or classes, including copyPin, createWaypointGuidance, selectLeg, resetEvidence, suspend.
- 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 1 file: Orient17a Continuity Direct (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 Orient17a Continuity Direct.
- 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), Orient17a Navigation (import), Convergence Unlimited (import)
- Used by
- imported by Orient17a Continuity Direct (import)
- Produces
- createWaypointGuidance
- Defines here
- copyPin, createWaypointGuidance, selectLeg, resetEvidence, suspend, 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/orient17a-continuity-ordered.mjs:1-129 · blob 937c0d874352120d102cc3e7fd54b490bd6e09ca · 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: unreached_review
// SPDX-License-Identifier: Apache-2.0
import {createRouteFollower} from '../line/route-follower.mjs';
import {geometry,createArrival} from '../orientation/orient17a-navigation.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;
const proximity = createArrival();
let routeKey = '';
let notBefore = -Infinity;
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 resetEvidence() { proximity.reset(); }
function suspend(now = Date.now()) {
resetEvidence();
notBefore = Math.max(notBefore, now);
}
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++;
}
const nextKey = JSON.stringify(updated);
if (routeKey !== nextKey) {proximity.reset();notBefore=Date.now();routeKey=nextKey;}
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 (quality !== 'usable' || !fix || fix.accuracyM<=0 || fix.timestampMs<notBefore) {proximity.reset();return snapshot('waiting', quality);}
if (next >= route.length) return snapshot('complete', quality);
if (fix.timestampMs < lastSample) { proximity.reset(); return snapshot('waiting', 'out-of-order'); }
const bearingToNext = () => geometry(fix, 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 && proximity.observe({fix,metrics:guidance,key:route[next].id,now})) {
next++;
proximity.reset();
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, suspend, resetEvidence};
}Orient17a Ordered
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/orient17a-ordered.mjs · lines 1–122 of 122 · 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 1 file: Orient17a Direct (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 Orient17a Direct.
- 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), Orient17a Navigation (import), Convergence Unlimited (import)
- Used by
- imported by Orient17a Direct (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/orient17a-ordered.mjs:1-122 · blob ba69cfa1f2cd516d5cc8de1fb529d86d0cc6454d · 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';
import {geometry,createArrival} from '../orientation/orient17a-navigation.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;
const proximity = createArrival();
let routeKey = '';
let notBefore = -Infinity;
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++;
}
const nextKey = JSON.stringify(updated);
if (routeKey !== nextKey) {proximity.reset();notBefore=Date.now();routeKey=nextKey;}
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 (quality !== 'usable' || !fix || fix.accuracyM<=0 || fix.timestampMs<notBefore) {proximity.reset();return snapshot('waiting', quality);}
if (next >= route.length) return snapshot('complete', quality);
if (fix.timestampMs < lastSample) return snapshot('waiting', 'out-of-order');
const bearingToNext = () => geometry(fix, 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 && proximity.observe({fix,metrics:guidance,key:route[next].id,now})) {
next++;
proximity.reset();
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};
}Orient17a V9212 Ordered
A JavaScript module in the guidance folder of GridAtlas that creates waypoint guidance (`createWaypointGuidance`), selects leg (`selectLeg`) and resets evidence (`resetEvidence`).
Set aside from the main view: 92% of its lines are the same as tools/satnav/guidance/orient17a-continuity-ordered.mjs (gridatlas), which stays. (near-copy-of, proposed by families.py). 92% of lines shared with Orient17a Continuity Ordered; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9223 to gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/guidance/orient17a-continuity-ordered.mjs:1-129 937c0d874352120d102cc3e7fd54b490bd6e09ca
- sha256 7f19aab493160778524e2186e099f89960d49d5e11890ed32816cc4d6f6fbf34
- target sha256 07e33c2564a6ff6e94739e18268ee3b49b05f1830949d523de9b7df8cd84847c
- group of 2 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
rendergridatlas / tools/satnav/guidance/orient17a-v9212-ordered.mjs · lines 1–129 of 129 · Not reached from any entry point (candidate for review) · pattern resetEvidence (shared by 2 files)
- What it does
- Defines 9 functions or classes, including copyPin, createWaypointGuidance, selectLeg, resetEvidence, suspend.
- 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 1 file: Orient17a V9212 Direct (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 Orient17a V9212 Direct.
- 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), Orient17a V9212 Navigation (import), Convergence Unlimited (import)
- Used by
- imported by Orient17a V9212 Direct (import)
- Produces
- createWaypointGuidance
- Defines here
- copyPin, createWaypointGuidance, selectLeg, resetEvidence, suspend, 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/orient17a-v9212-ordered.mjs:1-129 · blob 9566c24affb045129996e4500614e3e0660e1348 · 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';
import {geometry,createArrival} from '../orientation/orient17a-v9212-navigation.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;
const proximity = createArrival();
let routeKey = '';
let notBefore = -Infinity;
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 resetEvidence() { proximity.reset(); }
function suspend(now = Date.now()) {
resetEvidence();
notBefore = Math.max(notBefore, now);
}
function setRoute(pins,now=Date.now()) {
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++;
}
const nextKey = JSON.stringify(updated);
if (routeKey !== nextKey) {proximity.reset();notBefore=now;routeKey=nextKey;}
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 (quality !== 'usable' || !fix || fix.accuracyM<=0 || fix.timestampMs<notBefore) {proximity.reset();return snapshot('waiting', quality);}
if (next >= route.length) return snapshot('complete', quality);
if (fix.timestampMs < lastSample) { proximity.reset(); return snapshot('waiting', 'out-of-order'); }
const bearingToNext = () => geometry(fix, 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 && proximity.observe({fix,metrics:guidance,key:JSON.stringify([route[next].id,route[next].coordinate]),now})) {
next++;
proximity.reset();
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, suspend, resetEvidence};
}