Repository: excalidraw/excalidraw
File: src/element/bounds.ts (TypeScript)

Code before:
    const gen = rough.generator();
    const curve =
      element.strokeSharpness === "sharp"
        ? gen.linearPath(
            points as [number, number][],
            generateRoughOptions(element),
          )
        : gen.curve(
            points as [number, number][],
            generateRoughOptions(element),
          );
    const ops = getCurvePathOps(curve);
    bounds = getMinMaxXYFromCurvePathOps(ops);
  }

  const [minX, minY, maxX, maxY] = bounds;
  return [
    minX + element.x,
    minY + element.y,
    maxX + element.x,
    maxY + element.y,
  ];
};

export const getElementPointsCoords = (
  element: ExcalidrawLinearElement,
  points: readonly (readonly [number, number])[],
  sharpness: ExcalidrawElement["strokeSharpness"],
): [number, number, number, number] => {
  // This might be computationally heavey
  const gen = rough.generator();
  const curve =
    sharpness === "sharp"
      ? gen.linearPath(
          points as [number, number][],
          generateRoughOptions(element),
        )
      : gen.curve(points as [number, number][], generateRoughOptions(element));
  const ops = getCurvePathOps(curve);
  const [minX, minY, maxX, maxY] = getMinMaxXYFromCurvePathOps(ops);
  return [
    minX + element.x,
    minY + element.y,
    maxX + element.x,
    maxY + element.y,
  ];
};

export const getClosestElementBounds = (
  elements: readonly ExcalidrawElement[],
  from: { x: number; y: number },

Review comment (bug):
I just spotted a bug with resizing a single rotated line. Rolling back this change fixed it, but I don't really understand why. There's not much difference between this code and [`generateLinearElementShape`](https://github.com/excalidraw/excalidraw/pull/5586/files#diff-b5487856e823a67aae9b278f6ab4d7a588125d44bc539a0bcb1a8045b11bb549R383)

Code after:

  const points = rescalePoints(
    0,
    nextWidth,
    rescalePoints(1, nextHeight, element.points, normalizePoints),
    normalizePoints,
  );

  let bounds: [number, number, number, number];

  if (isFreeDrawElement(element)) {
    // Free Draw
    bounds = getBoundsFromPoints(points);
  } else {
    // Line
    const gen = rough.generator();
    const curve =
      element.strokeSharpness === "sharp"
        ? gen.linearPath(
            points as [number, number][],
            generateRoughOptions(element),
          )
        : gen.curve(
            points as [number, number][],
            generateRoughOptions(element),
          );

    const ops = getCurvePathOps(curve);
    bounds = getMinMaxXYFromCurvePathOps(ops);
  }

  const [minX, minY, maxX, maxY] = bounds;
  return [
    minX + element.x,
    minY + element.y,
    maxX + element.x,
    maxY + element.y,
  ];
};

export const getElementPointsCoords = (
  element: ExcalidrawLinearElement,
  points: readonly (readonly [number, number])[],
  sharpness: ExcalidrawElement["strokeSharpness"],
): [number, number, number, number] => {
  // This might be computationally heavey
  const gen = rough.generator();
  const curve =
    sharpness === "sharp"
      ? gen.linearPath(
          points as [number, number][],