Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion desktop/src-tauri/src/render_audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ fn audit_graph_scope(window: &tauri::WebviewWindow, output: &Output, deadline: I
// actual OrbitControls and the product projection path, not physical gestures.
fn audit_graph_zoom(window: &tauri::WebviewWindow, output: &Output, deadline: Instant, size: &str) -> Result<(),String> {
let mut states=Vec::new();
for (name,ratio,expected) in [("distant",0.55_f64,0),("context",1.7,2),("detail",2.5,3),("returned",0.55,0)] {
for (name,ratio,expected) in [("distant",0.05_f64,0),("context",1.7,2),("detail",2.5,3),("returned",0.05,0)] {
collect_script(window,"JSON.stringify((()=>{document.querySelector('#knowledge-camera-reset').click();return {reset:true};})())".into(),deadline)?;
let reset = wait_for_audit_state("zoom reset",deadline,||collect_script(window,graph_collect_script(),deadline),
|s|s["motion"]["camera"]==false&&s["motion"]["labelZoomRatio"].as_f64().is_some_and(|r|(r-1.0).abs()<0.02))?;
Expand All @@ -1658,6 +1658,14 @@ fn audit_graph_zoom(window: &tauri::WebviewWindow, output: &Output, deadline: In
collect_script(window,format!(r#"JSON.stringify((()=>{{const c=document.querySelector('#knowledge-graph-canvas'),r=c.getBoundingClientRect();c.dispatchEvent(new WheelEvent('wheel',{{deltaY:{delta},deltaMode:0,clientX:r.x+r.width/2,clientY:r.y+r.height/2,bubbles:true,cancelable:true}}));return {{syntheticWheel:true}};}})())"#),deadline)?;
let navigation=wait_for_audit_state("zoom labels paint",deadline,||collect_script(window,graph_collect_script(),deadline),
|s|s["motion"]["camera"]==false && s["motion"]["labelZoom"]==expected)?;
if expected == 0 {
let motion = &navigation["motion"];
let actual = motion["requestedCameraDistance"].as_f64().ok_or("camera distance missing")?;
let maximum = motion["cameraMaxDistance"].as_f64().ok_or("camera maximum missing")?;
if !actual.is_finite() || !maximum.is_finite() || (actual-maximum).abs() > 0.001 {
return Err("distant zoom did not reach the actual camera maximum".into());
}
}
let labels=collect_script(window,LABEL_GEOMETRY_COLLECT.into(),deadline)?;
if labels["overlapPairs"]!=0 || labels["clippedLabels"]!=0 || labels["visibleUnpositionedLabels"]!=0 || labels["truncated"]!=false || labels["hudOverlapPairs"]!=0 || labels["hudSampled"]!=1 {
return Err(format!("zoom label geometry failed: {labels}"));
Expand Down
19 changes: 19 additions & 0 deletions desktop/src/__tests__/projected-relaxation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,22 @@ describe('settled projected display collision correction', () => {
expect([...relaxProjectedCircles(points,{...viewport,width:0}).offsets]).toEqual([0,0,0,0]);
});
});

describe('dense viewports keep core separation ahead of optional whitespace',()=>{
it.each([2.7,3])('does not turn a separated %s-pixel grid into overlapping cores',spacing=>{
const area={left:0,top:0,width:439,height:332};
const points=Array.from({length:1024},(_,i)=>({x:80+i%32*spacing,y:50+Math.floor(i/32)*spacing,radius:1.3}));
const original=JSON.stringify(points),before=projectedLayoutMetrics(points,area);
if(!before.available)throw Error('fixture projection unavailable');
expect(before.overlapPairs).toBe(0);
const {offsets,diagnostics}=relaxProjectedCircles(points,area);
const corrected=points.map((p,i)=>({...p,x:p.x+offsets[i*2],y:p.y+offsets[i*2+1]}));
const after=projectedLayoutMetrics(corrected,area);
if(!after.available)throw Error('corrected projection unavailable');
expect(after.visiblePoints).toBe(points.length);
expect(after.overlapPairs).toBe(0);
expect(JSON.stringify(points)).toBe(original);
expect(diagnostics.maxShift).toBeLessThanOrEqual(PROJECTED_RELAXATION_LIMITS.shiftCssPx+1e-9);
expect(diagnostics.pairTests).toBeLessThanOrEqual(PROJECTED_RELAXATION_LIMITS.pairTests);
});
});
88 changes: 52 additions & 36 deletions desktop/src/knowledge/projected-relaxation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ProjectedCircle, ProjectionViewport } from './projected-layout-metrics';

export const PROJECTED_RELAXATION_LIMITS = Object.freeze({ nodes: 2048, passes: 8, pairTests: 131072, shiftCssPx: 10, gapCssPx: 4.5 });
export const PROJECTED_RELAXATION_LIMITS = Object.freeze({ nodes: 2048, passes: 16, pairTests: 131072, shiftCssPx: 10, gapCssPx: 4.5 });
export interface RelaxationResult {
offsets: Float64Array;
diagnostics: { nodes: number; passes: number; pairTests: number; moved: number; maxShift: number; budgetExhausted: boolean; inputTruncated: boolean };
diagnostics: { nodes: number; passes: number; effectiveGapCssPx:number; pairTests: number; corePairTests:number; gapPairTests:number; coreContacts:number; moved: number; maxShift: number; budgetExhausted: boolean; inputTruncated: boolean };
}

/** Bounded display-only offsets. No identities, edges, source coordinates or
Expand All @@ -13,11 +13,11 @@ export function relaxProjectedCircles(input: readonly ProjectedCircle[], viewpor
const limits = PROJECTED_RELAXATION_LIMITS, count = Math.min(input.length, limits.nodes);
const offsets = new Float64Array(count * 2), x = new Float64Array(count), y = new Float64Array(count);
const active = new Uint8Array(count), dx = new Float64Array(count), dy = new Float64Array(count);
const diagnostics = { nodes: count, passes: 0, pairTests: 0, moved: 0, maxShift: 0,
const diagnostics = { nodes: count, passes: 0, effectiveGapCssPx:0, pairTests: 0, corePairTests:0, gapPairTests:0, coreContacts:0, moved: 0, maxShift: 0,
budgetExhausted: false, inputTruncated: input.length > count };
const { left, top, width, height } = viewport;
if (![left,top,width,height].every(Number.isFinite) || width <= 0 || height <= 0) return { offsets, diagnostics };
let maxRadius = 0;
let maxRadius = 0, retainedCorrection = false;
for (let i = 0; i < count; i++) {
const p = input[i]; x[i] = p.x; y[i] = p.y;
if (![p.x,p.y,p.radius].every(Number.isFinite) || p.radius <= 0 || p.inClipVolume === false
Expand All @@ -27,47 +27,63 @@ export function relaxProjectedCircles(input: readonly ProjectedCircle[], viewpor
if (initialOffsets?.length === count * 2) {
const ox = initialOffsets[i*2], oy = initialOffsets[i*2+1], size = Math.hypot(ox,oy);
if (Number.isFinite(size)) {
if (size > 0) retainedCorrection = true;
const gain = size > limits.shiftCssPx ? limits.shiftCssPx / size : 1;
x[i] = pinned.has(i) ? p.x + ox * gain : Math.max(left + p.radius,Math.min(left + width - p.radius,p.x + ox * gain));
y[i] = pinned.has(i) ? p.y + oy * gain : Math.max(top + p.radius,Math.min(top + height - p.radius,p.y + oy * gain));
}
}
}
const cellSize = Math.max(1, maxRadius * 2 + limits.gapCssPx);
const columns = Math.ceil(width / cellSize) + 3;
if (!Number.isSafeInteger(columns * (Math.ceil(height / cellSize) + 3))) return { offsets, diagnostics };
const visibleCount = active.reduce((sum,value)=>sum+value,0);
// Optional whitespace follows the visible average pitch; it is not a
// source/semantic distance or a guarantee that every packing is feasible.
const gap = Math.min(limits.gapCssPx,Math.sqrt(width*height/Math.max(1,visibleCount))*.1);
diagnostics.effectiveGapCssPx = gap;
for (let pass = 0; pass < limits.passes; pass++) {
const grid = new Map<number, number[]>();
for (let i = 0; i < count; i++) if (active[i]) {
const key = Math.floor((y[i] - top) / cellSize) * columns + Math.floor((x[i] - left) / cellSize);
const cell = grid.get(key); if (cell) cell.push(i); else grid.set(key, [i]);
}
dx.fill(0); dy.fill(0);
const budget = Math.floor((limits.pairTests - diagnostics.pairTests) / (limits.passes - pass));
let tested = 0, contacts = 0;
outer: for (let slot = 0; slot < count; slot++) {
const a = (slot + pass * 257) % count;
if (!active[a]) continue;
const cx = Math.floor((x[a] - left) / cellSize), cy = Math.floor((y[a] - top) / cellSize);
for (let gx = cx - 1; gx <= cx + 1; gx++) for (let gy = cy - 1; gy <= cy + 1; gy++)
for (const b of grid.get(gy * columns + gx) ?? []) {
if (b <= a || pinned.has(a) && pinned.has(b)) continue;
if (tested >= budget) { diagnostics.budgetExhausted = true; break outer; }
tested++; diagnostics.pairTests++;
let vx = x[a] - x[b], vy = y[a] - y[b], distance = Math.hypot(vx, vy);
const separation = input[a].radius + input[b].radius + limits.gapCssPx;
if (distance >= separation) continue;
contacts++;
if (distance < 1e-9) {
const angle = ((Math.imul(a + 1, 2654435761) ^ Math.imul(b + 1, 1597334677)) >>> 0) / 4294967296 * Math.PI * 2;
vx = Math.cos(angle); vy = Math.sin(angle); distance = 1;
} else { vx /= distance; vy /= distance; }
const amount = Math.max(.1, separation - Math.hypot(x[a]-x[b],y[a]-y[b])) * .55;
const share = pinned.has(a) || pinned.has(b) ? 1 : .5;
if (!pinned.has(a)) { dx[a] += vx * amount * share; dy[a] += vy * amount * share; }
if (!pinned.has(b)) { dx[b] -= vx * amount * share; dy[b] -= vy * amount * share; }
}
}
let tested = 0, contacts = 0, coreContacts = 0;
const accumulate = (gap:number, core:boolean) => {
const cellSize = Math.max(1, maxRadius * 2 + gap);
const columns = Math.ceil(width / cellSize) + 3;
if (!Number.isSafeInteger(columns * (Math.ceil(height / cellSize) + 3))) return;
const grid = new Map<number, number[]>();
for (let i = 0; i < count; i++) if (active[i]) {
const key = Math.floor((y[i] - top) / cellSize) * columns + Math.floor((x[i] - left) / cellSize);
const cell = grid.get(key); if (cell) cell.push(i); else grid.set(key, [i]);
}
outer: for (let slot = 0; slot < count; slot++) {
const a = (slot + pass * 257) % count;
if (!active[a]) continue;
const cx = Math.floor((x[a] - left) / cellSize), cy = Math.floor((y[a] - top) / cellSize);
for (let gx = cx - 1; gx <= cx + 1; gx++) for (let gy = cy - 1; gy <= cy + 1; gy++)
for (const b of grid.get(gy * columns + gx) ?? []) {
if (b <= a || pinned.has(a) && pinned.has(b)) continue;
if (tested >= budget) { diagnostics.budgetExhausted = true; break outer; }
tested++; diagnostics.pairTests++;
if(core)diagnostics.corePairTests++;else diagnostics.gapPairTests++;
let vx = x[a] - x[b], vy = y[a] - y[b], distance = Math.hypot(vx, vy);
const radii = input[a].radius + input[b].radius;
const separation = radii + (core ? .5 : gap);
if (distance >= (core ? radii : separation)) continue;
contacts++;if(core){coreContacts++;diagnostics.coreContacts++;}
if (distance < 1e-9) {
const angle = ((Math.imul(a + 1, 2654435761) ^ Math.imul(b + 1, 1597334677)) >>> 0) / 4294967296 * Math.PI * 2;
vx = Math.cos(angle); vy = Math.sin(angle); distance = 1;
} else { vx /= distance; vy /= distance; }
const amount = Math.max(.1, separation - Math.hypot(x[a]-x[b],y[a]-y[b])) * .55;
const share = pinned.has(a) || pinned.has(b) ? 1 : .5;
if (!pinned.has(a)) { dx[a] += vx * amount * share; dy[a] += vy * amount * share; }
if (!pinned.has(b)) { dx[b] -= vx * amount * share; dy[b] -= vy * amount * share; }
}
}
};
// Spend each pass on actual overlapping cores before optional whitespace.
accumulate(0,true);
// A retained correction is already a settled display choice. Reprojection
// repairs new core contacts without repeatedly spending optional whitespace.
// Extra convergence rounds are for cores only, not repeated whitespace.
if (!retainedCorrection && !coreContacts && tested < budget && pass < Math.floor(limits.passes/2)) accumulate(gap,false);
diagnostics.passes++;
if (!contacts) break;
for (let i = 0; i < count; i++) if (active[i] && !pinned.has(i)) {
Expand Down
61 changes: 61 additions & 0 deletions docs/evaluation/projection-priority-20261025.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Preserve core separation before optional screen whitespace

Baseline:244c98ffe3333aa34480e5b670c2ae137426e19e, with the semantic-coordinate
repair already installed. Its actual1984-point compact native capture retained371
reference-core overlap pairs and exhausted131072 pair checks. Default-size capture
had0. These are anonymous projected circle cores, not source identity, glow,
font ink or semantic-quality measurements.

The display solver treated optional4.5px whitespace like an actual overlapping
core. On two explicitly separated1024-point grids (radius1.3px, spacing2.7/3px),
it created589/364 overlapping pairs. New behavioral regressions reject both.
A changed title, graph membership or embedding is unnecessary to reproduce this.

Each bounded pass now checks actual cores first with the smaller spatial grid.
Optional whitespace is considered only when that pass found no core contacts;
it is at most the existing4.5px cap and scales with10% of the visible average
cell pitch. This is a display heuristic, not a geometric packing theorem.
The final pass repairs cores. A retained nonzero correction keeps its optional
spacing choice while still allowing actual new core contacts to be repaired;
this preserves stable re-projection. No source coordinate, edge, membership,
semantic force, label policy, model, index or persistent data is changed.

The node2048/pair131072/shift10px caps stay unchanged. The pass cap is16
(previously8), allowing sparse core-only rounds to converge within the same
arithmetic pair budget. Optional whitespace uses at most the first8 rounds;
extra rounds are exclusively for actual cores, avoiding an accidental doubling
of optional whitespace work. The first actual8-pass candidate improved compact371→33
but left3 default-size contacts, so that candidate was not installed. The new core and gap
check/contact counters make admission observable. WithN admitted points andP
passes, storage remainsO(N); up to two grids are built per pass. Adversarial dense
cell traversal is stillO(P*N²), including candidates skipped before the arithmetic
pair counter. The arithmetic pair cap alone is not a full wall-time proof.
Average spatial pruning does not establish universal linear complexity. Bounded
repeated corrections do not prove all feasible packings converge or preserve
all semantic distances; the authority is still the unchanged3D source solver.

Separate8-pass prototypes compared fixed-gap core priority and density-only spacing,
then combined them. On saved *already corrected* compact screen points used as
fresh input, baseline336 residual overlaps, priority7, density0 and combined7
were observed. This is a controlled replay, not the unrecorded original input
of the installed correction and not a production speedup. Both separated grid
regressions have0 with the combined candidate (also verified in the final16-pass
full frontend run). A densely overlapping2.5px grid
remains difficult: baseline1043 versus combined1344 residual pairs for1024nodes.
That tradeoff is retained; there is no all-input non-regression or zero-overlap
claim. The displacement envelope and iterations can make dense packing infeasible.

The first full frontend run detected drift on re-projection in both motion modes.
That failure is retained and fixed by retaining settled optional spacing; the
existing frame/GPU-buffer/bridge/picking/pin checks remain the acceptance oracle.
No test tolerance was relaxed. Final checks and native/install evidence live in
the task's projection-priority-20261025 output directory, not inferred here.

The owned transparent native audit also drives distant/returned wheel input to
the actual camera maximum (rather than merely0.55 of fitted zoom), validates the
native distance and preserves the two zoom-in stages. It retains zero fitted/
zoomed-out labels, label/HUD rectangle checks, inactive/nonkey capture and final
minimized readback. It does not manipulate the user's primary window or prove
physical gestures, Retina, whole-app FPS/GPU/battery, voice or a normal release.
Current-source Pro/Gemini/reverse validation remainsNOT_RUN under the preserved
source-upload rejection. No alternate model/account/upload route is used.