import { track } from '@tldraw/state-react' import { modulate } from '@tldraw/utils' import { useEditor } from '../hooks/useEditor' import { Geometry2d } from '../primitives/geometry/Geometry2d' import { Group2d } from '../primitives/geometry/Group2d' export const GeometryDebuggingView = track(function GeometryDebuggingView({ showStroke = true, showVertices = true, showClosestPointOnOutline = true, }: { showStroke?: boolean showVertices?: boolean showClosestPointOnOutline?: boolean }) { const editor = useEditor() const zoomLevel = editor.getZoomLevel() const renderingShapes = editor.getRenderingShapes() const currentPagePoint = editor.inputs.getCurrentPagePoint() return ( {renderingShapes.map((result) => { const shape = editor.getShape(result.id)! if (shape.type === 'group') return null const geometry = editor.getShapeGeometry(shape) const pageTransform = editor.getShapePageTransform(shape)! const pointInShapeSpace = editor.getPointInShapeSpace(shape, currentPagePoint) const nearestPointOnShape = geometry.nearestPoint(pointInShapeSpace) const distanceToPoint = geometry.distanceToPoint(pointInShapeSpace, true) const dist = Math.abs(distanceToPoint) * zoomLevel const hitInside = distanceToPoint < 0 const { vertices } = geometry return ( {showStroke && ( )} {showVertices && vertices.map((v, i) => ( ))} {showClosestPointOnOutline && dist < 150 && ( )} ) })} ) }) function GeometryStroke({ geometry }: { geometry: Geometry2d }) { if (geometry instanceof Group2d) { return ( {[...geometry.children, ...geometry.ignoredChildren].map((child, i) => ( ))} ) } return }