mitja/rbush
Mitja Bezenšek 2024-04-02 19:27:35 +02:00
rodzic d6049546b0
commit 60d4aa3f8b
2 zmienionych plików z 9 dodań i 8 usunięć

Wyświetl plik

@ -1376,7 +1376,7 @@ export interface MatModel {
export const MAX_PAGES = 40;
// @internal (undocumented)
export const MAX_SHAPES_PER_PAGE = 20000;
export const MAX_SHAPES_PER_PAGE = 2000;
// @internal (undocumented)
export const MAX_ZOOM = 8;

Wyświetl plik

@ -18,6 +18,7 @@ export class SpatialIndex {
shapesInTree = new Map<TLShapeId, Element>()
rBush = new TldrawRBush()
lastPageId: TLPageId | null
calculationNumber = 0
constructor(private editor: Editor) {
this.lastPageId = editor.getCurrentPageId()
@ -57,22 +58,22 @@ export class SpatialIndex {
const { store } = this.editor
const shapeHistory = store.query.filterHistory('shape')
return computed<{ epoch: number }>('getShapesInView', (prevValue, lastComputedEpoch) => {
return computed<number>('getShapesInView', (prevValue, lastComputedEpoch) => {
let isDirty = false
const currentPageId = this.editor.getCurrentPageId()
const shapes = this.editor.getCurrentPageShapes()
if (isUninitialized(prevValue)) {
return this.fromScratch(shapes, lastComputedEpoch)
return this.fromScratch(shapes)
}
const diff = shapeHistory.getDiffSince(lastComputedEpoch)
if (diff === RESET_VALUE) {
return this.fromScratch(shapes, lastComputedEpoch)
return this.fromScratch(shapes)
}
if (this.lastPageId !== currentPageId) {
return this.fromScratch(shapes, lastComputedEpoch)
return this.fromScratch(shapes)
}
const elementsToAdd: Element[] = []
@ -123,11 +124,11 @@ export class SpatialIndex {
}
}
}
return isDirty ? { epoch: lastComputedEpoch } : prevValue
return isDirty ? this.calculationNumber++ : prevValue
})
}
private fromScratch(shapes: TLShape[], epoch: number) {
private fromScratch(shapes: TLShape[]) {
this.lastPageId = this.editor.getCurrentPageId()
this.rBush.clear()
this.shapesInTree = new Map<TLShapeId, Element>()
@ -142,6 +143,6 @@ export class SpatialIndex {
}
this.rBush.load(elementsToAdd)
return { epoch }
return this.calculationNumber++
}
}