Repository: excalidraw/excalidraw
File: src/components/App.tsx (TypeScript)

Code before:
          ))
      ) {
        setCursor(this.canvas, CURSOR_TYPE.MOVE);
      } else {
        setCursor(this.canvas, CURSOR_TYPE.AUTO);
      }
    }
  };

  private handleEraser = (
    event: PointerEvent,
    pointerDownState: PointerDownState,
    scenePointer: { x: number; y: number },
  ) => {
    const idsToUpdate: Array<string> = [];

    const distance = distance2d(
      pointerDownState.lastCoords.x,
      pointerDownState.lastCoords.y,
      scenePointer.x,
      scenePointer.y,
    );
    const threshold = 10 / this.state.zoom.value;
    const point = pointerDownState.lastCoords;
    let samplingInterval = 0;
    while (samplingInterval < distance) {
      const hitElement = this.getElementAtPosition(point.x, point.y);
      if (hitElement) {
        idsToUpdate.push(hitElement.id);
        if (event.altKey) {
          if (pointerDownState.elementIdsToErase[hitElement.id]) {
            pointerDownState.elementIdsToErase[hitElement.id] = false;
          }
        } else {
          pointerDownState.elementIdsToErase[hitElement.id] = true;
        }
      }

      // Calculate next point in the line at a distance of sampling interval
      samplingInterval += threshold;

      const distanceRatio = samplingInterval / distance;
      const nextX =
        (1 - distanceRatio) * point.x + distanceRatio * scenePointer.x;
      const nextY =
        (1 - distanceRatio) * point.y + distanceRatio * scenePointer.y;
      point.x = nextX;
      point.y = nextY;
    }

    const hitElement = this.getElementAtPosition(

Review comment (suggestion):
- you're hitbox-testing the original position twice (once in previous invocation, once at the start of the loop)
- I'd also check if the loop if the interpolation is needed at all. First, I'd go from end to start: drop the `samplingInterval` variable and just use the `distance`, starting from the end and subtracting `threshold` from it on each loop iteration, and making the loop condition to be `distance >= threshold`. This way you don't loop unnecessarily and reduce the variables.

Code after:
        // if using cmd/ctrl, we're not dragging
        !event[KEYS.CTRL_OR_CMD] &&
        (hitElement ||
          this.isHittingCommonBoundingBoxOfSelectedElements(
            scenePointer,
            selectedElements,
          ))
      ) {
        setCursor(this.canvas, CURSOR_TYPE.MOVE);
      } else {
        setCursor(this.canvas, CURSOR_TYPE.AUTO);
      }
    }
  };

  private handleEraser = (
    event: PointerEvent,
    pointerDownState: PointerDownState,
    scenePointer: { x: number; y: number },
  ) => {
    const updateElementIds = (elements: ExcalidrawElement[]) => {
      elements.forEach((element) => {
        idsToUpdate.push(element.id);
        if (event.altKey) {
          if (pointerDownState.elementIdsToErase[element.id]) {
            pointerDownState.elementIdsToErase[element.id] = false;
          }
        } else {
          pointerDownState.elementIdsToErase[element.id] = true;
        }
      });
    };

    const idsToUpdate: Array<string> = [];

    const distance = distance2d(
      pointerDownState.lastCoords.x,
      pointerDownState.lastCoords.y,
      scenePointer.x,
      scenePointer.y,
    );
    const threshold = 10 / this.state.zoom.value;
    const point = { ...pointerDownState.lastCoords };
    let samplingInterval = 0;
    while (samplingInterval <= distance) {
      const hitElements = this.getElementsAtPosition(point.x, point.y);
      updateElementIds(hitElements);

      // Exit since we reached current point
      if (samplingInterval === distance) {
        break;