Skip to content

Commit a25911e

Browse files
committed
Address Claude review feedback
- Sample freehand vertices at a 3px minimum spacing. Taking every mousemove let a slow trace grow the ring without bound, and both the path rebuild in render() and the closing intersection test scale with its length.
1 parent a510655 commit a25911e

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

packages/map/src/MapCanvas.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ const MAPLIBRE_TILE_SIZE = 512;
4848
const WMS_IDENTIFY_QUERY_SIZE = 101;
4949
const WMS_IDENTIFY_QUERY_CENTER = Math.floor(WMS_IDENTIFY_QUERY_SIZE / 2);
5050
const WMS_IDENTIFY_INFO_FORMATS = ["application/json", "text/html", "text/plain"];
51+
/**
52+
* Minimum screen distance, in pixels, between two vertices of a freehand
53+
* selection ring. Small enough that the traced outline still reads as a smooth
54+
* curve, large enough that a slow drag cannot grow the ring without bound.
55+
*/
56+
const FREEHAND_MIN_POINT_DISTANCE = 3;
5157

5258
export interface MapCanvasProps {
5359
controllerRef?: React.MutableRefObject<MapController | null>;
@@ -1470,8 +1476,15 @@ export const MapCanvas = memo(function MapCanvas({
14701476
};
14711477
const onMouseMove = (event: maplibregl.MapMouseEvent) => {
14721478
if (!dragging) return;
1473-
if (request.shape === "freehand") points.push(event.point);
1474-
else points = [points[0], event.point];
1479+
if (request.shape === "freehand") {
1480+
// Sample rather than take every mousemove: a slow trace would
1481+
// otherwise accumulate thousands of near-coincident vertices, and
1482+
// both render() (which rebuilds the whole path string) and the
1483+
// closing intersection test scale with the ring.
1484+
const last = points.at(-1);
1485+
if (last && last.dist(event.point) < FREEHAND_MIN_POINT_DISTANCE) return;
1486+
points.push(event.point);
1487+
} else points = [points[0], event.point];
14751488
render();
14761489
};
14771490
const onMouseUp = (event: maplibregl.MapMouseEvent) => {

0 commit comments

Comments
 (0)