docs(tests): explain projection cache invalidation and frame notifications

This commit is contained in:
2026-11-12 17:30:41 +08:00
parent c43af2ccb9
commit 19bfbc772d
7 changed files with 13 additions and 0 deletions
+2
View File
@@ -12,6 +12,7 @@ const registry=createRegistry(builtinComponents()),node=(id,x)=>({id,incarnation
/** 每次新建等价文档/投影,检验缓存不能只靠输入引用相同判断可复用。 */
const draw=(edges=[edge()])=>projectCanvas(createDocument('p',[{id:'p',parent:null}],[node('a',0),node('b',500),...edges]),'p',registry,new Set(),()=>undefined);
// 控制点到y=-500,10描边使保守范围扩5;查询端点之间屏幕外弯曲区域仍能找到edge,节点y保持500。
// bounds 是控制多边形加半线宽的保守范围,并非曲线实际极值矩形;命中此索引只表明需要保留绘制候选。
test('bowed cubic paint is indexed outside endpoint rectangles including stroke while document bounds remain unchanged',()=>{const projection=draw(),result=projectedConnectionPaintOverflow(projection,registry,{edgeGeometry:()=>[[{x:100,y:550},{x:100,y:-500},{x:500,y:-500},{x:500,y:550}]],strokeWidth:()=>10});assert.deepEqual(result.unknown,[]);assert.deepEqual(result.regions[0].bounds,{x:95,y:-505,width:410,height:1060});const index=createPaintIndex();index.sync(result.regions);assert.ok(index.query({x:250,y:0,width:10,height:10}).has('edge'));assert.equal(projection.document.elements.get('a').geometry.y,500);});
// 直线全被端点范围覆盖时无额外区域;缺/NaN锚点、非法段和无限线宽不能被当成无需绘制。
test('straight contained paint needs no overflow; missing anchors and invalid geometry stay unknown',()=>{const projection=draw();assert.equal(projectedConnectionPaintOverflow(projection,registry,{edgeGeometry:()=>[[{x:100,y:550},{x:200,y:550},{x:400,y:550},{x:500,y:550}]],strokeWidth:()=>2}).regions.length,0);for(const services of [{anchor:()=>undefined},{anchor:()=>({point:{x:NaN,y:0},normal:{x:1,y:0}})},{edgeGeometry:()=>[[{x:NaN,y:0}]],strokeWidth:()=>1},{strokeWidth:()=>Infinity}])assert.deepEqual(projectedConnectionPaintOverflow(projection,registry,services).unknown,['edge']);});
@@ -33,6 +34,7 @@ test('an empty connection projection does not enumerate unrelated nodes',()=>{
// 重复ID按后者解析锚点,原地替换投影行也读新位置;缺b则两边unknown,较小边预算仍正确报告。
test('endpoint filtering preserves duplicate IDs, mutable replacement, missing targets and edge budgets',()=>{
const projection=draw([edge('one'),edge('two')]),last={...projection.nodes[0],position:{x:900,y:500}},positions=[];
// 同 ID 的投影行故意重复,检查端点查找采用最后一行;这不是构造允许重复身份的持久文档。
projection.nodes.push(last);const services={anchor:(node,_handle,end)=>{positions.push(node.position.x);return{point:{x:node.position.x,y:550},normal:{x:end==='source'?1:-1,y:0}};}};
assert.deepEqual(projectedConnectionPaintOverflow(projection,registry,services,1).unknown,['paint_budget']);assert.deepEqual(positions,[900,500]);
projection.nodes[projection.nodes.length-1]={...last,position:{x:1200,y:500}};positions.length=0;projectedConnectionPaintOverflow(projection,registry,services,1);assert.deepEqual(positions,[1200,500]);