adds frontend history

This commit is contained in:
2024-12-30 21:36:46 -05:00
parent aa1763cbe7
commit ff0a578940
8 changed files with 184 additions and 63 deletions

View File

@@ -2,3 +2,40 @@ export interface Point {
x: number;
y: number;
}
export class PointLine {
data: Point[];
constructor() {
this.data = [];
}
find_index(x: number) {
if (this.data.length == 0) {
return 0;
}
// left should be too early to insert
// right should be too late to insert
let left = 0;
let size = this.data.length;
while (size > 1) {
const half = Math.floor(size / 2);
const mid = left + half;
const is_less = this.data[mid].x < x;
if (is_less) {
left = mid;
}
size -= half;
}
return left + (this.data[left].x < x ? 1 : 0);
}
insert(point: Point) {
const index = this.find_index(point.x);
this.data.splice(index, 0, point);
}
}