Line data Source code
1 : import type { LinkSegment } from '@comfyorg/graph-model/interfaces'
2 : import type { Point2D as Point } from '@comfyorg/shared-frontend-utils/geometry'
3 :
4 : interface LazyPolyline {
5 : compute: () => readonly Point[]
6 : points?: readonly Point[]
7 : }
8 :
9 2356 : const polylines = new WeakMap<LinkSegment, LazyPolyline>()
10 :
11 114771 : export function setLinkPolyline(
12 : segment: LinkSegment,
13 : compute: () => readonly Point[]
14 : ) {
15 114771 : polylines.set(segment, { compute })
16 : }
17 :
18 34 : export function getLinkPolyline(
19 : segment: LinkSegment
20 : ): readonly Point[] | undefined {
21 34 : const polyline = polylines.get(segment)
22 34 : if (!polyline) return undefined
23 34 : polyline.points ??= polyline.compute()
24 34 : return polyline.points
25 : }
|