adds saving and loading history to and from disk

This commit is contained in:
2025-01-01 10:08:50 -05:00
parent dfd524ba19
commit 9136c5fd71
15 changed files with 602 additions and 146 deletions

View File

@@ -34,8 +34,36 @@ export class PointLine {
return left + (this.data[left].x < x ? 1 : 0);
}
insert(point: Point) {
insert(point: Point, maximum_separation?: number) {
const index = this.find_index(point.x);
this.data.splice(index, 0, point);
if (maximum_separation !== undefined) {
this.reduce_to_maximum_separation(maximum_separation, [index - 1, index + 1]);
}
}
reduce_to_maximum_separation(maximum_separation: number, range?: [number, number]) {
if (maximum_separation <= 0) {
return;
}
// Add a default range if it does not exist
range = range || [1, this.data.length - 2];
// clamp it to the bounds
range = [Math.max(1, range[0]), Math.min(this.data.length - 2, range[1])];
// Loop over the indices in the range (backwards so removals don't break anything)
for (let i = range[1]; i >= range[0]; i--) {
const x_previous = this.data[i - 1].x;
const x_current = this.data[i].x;
const x_next = this.data[i + 1].x;
const separation_before = x_current - x_previous;
const separation_after = x_next - x_current;
// If the data points are too close on both sides then delete this point
if (separation_before < maximum_separation && separation_after < maximum_separation) {
this.data.splice(i, 1);
}
}
}
}