fix: hide points outside linear element editor when close enough

This commit is contained in:
Aakansha Doshi 2022-08-24 15:49:04 +05:30
parent 33300d19f6
commit bcb45f7cf6
2 changed files with 53 additions and 16 deletions

View file

@ -409,6 +409,38 @@ export class LinearElementEditor {
return centerPoint(points[0], points.at(-1)!);
}
static getVisiblePointIndexes(
linearElementEditor: LinearElementEditor,
appState: AppState,
) {
const { elementId } = linearElementEditor;
const element = LinearElementEditor.getElement(elementId);
if (!element) {
return [];
}
const visiblePointIndexes: number[] = [];
let previousPoint: Point | null = null;
element.points.forEach((point, index) => {
let distance = Infinity;
if (previousPoint) {
distance = distance2d(
point[0],
point[1],
previousPoint[0],
previousPoint[1],
);
}
if (
(!appState.editingLinearElement &&
distance >= 2 * LinearElementEditor.POINT_HANDLE_SIZE) ||
appState.editingLinearElement
) {
visiblePointIndexes.push(index);
previousPoint = point;
}
});
return visiblePointIndexes;
}
static handlePointerDown(
event: React.PointerEvent<HTMLCanvasElement>,
appState: AppState,