MCPcopy
hub / github.com/msgbyte/tianji / getLineWidth

Function getLineWidth

src/client/hooks/useStrokeDasharray.ts:121–141  ·  view source on GitHub ↗
(points: GraphicalItemPoint[])

Source from the content-addressed store, hash-verified

119 const items = props?.formattedGraphicalItems;
120
121 const getLineWidth = (points: GraphicalItemPoint[]) => {
122 const width = points?.reduce((acc, point, index) => {
123 if (!index) return acc;
124
125 const prevPoint = points?.[index - 1];
126
127 const xAxis = point?.x || 0;
128 const prevXAxis = prevPoint?.x || 0;
129 const xWidth = xAxis - prevXAxis;
130
131 const yAxis = point?.y || 0;
132 const prevYAxis = prevPoint?.y || 0;
133 const yWidth = Math.abs(yAxis - prevYAxis);
134
135 const hypotenuse = Math.sqrt(xWidth * xWidth + yWidth * yWidth);
136 acc += hypotenuse;
137 return acc;
138 }, 0);
139
140 return width || 0;
141 };
142
143 items?.forEach((line) => {
144 const linePoints = line?.props?.points ?? [];

Callers 1

useStrokeDasharrayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected