MCPcopy
hub / github.com/greensock/GSAP / pointsToSegment

Function pointsToSegment

esm/utils/paths.js:1189–1289  ·  view source on GitHub ↗
(points, curviness)

Source from the content-addressed store, hash-verified

1187} //points is an array of x/y points, like [x, y, x, y, x, y]
1188
1189export function pointsToSegment(points, curviness) {
1190 //points = simplifyPoints(points, tolerance);
1191 _abs(points[0] - points[2]) < 1e-4 && _abs(points[1] - points[3]) < 1e-4 && (points = points.slice(2)); // if the first two points are super close, dump the first one.
1192
1193 var l = points.length - 2,
1194 x = +points[0],
1195 y = +points[1],
1196 nextX = +points[2],
1197 nextY = +points[3],
1198 segment = [x, y, x, y],
1199 dx2 = nextX - x,
1200 dy2 = nextY - y,
1201 nonSmooth = points.nonSmooth || [],
1202 // populated by segmentToDistributedPoints(). The x slot will have 1 if it's a non-smooth point, in which case we should skip the smoothing here, obviously.
1203 closed = Math.abs(points[l] - x) < 0.001 && Math.abs(points[l + 1] - y) < 0.001,
1204 prevX,
1205 prevY,
1206 i,
1207 dx1,
1208 dy1,
1209 r1,
1210 r2,
1211 r3,
1212 tl,
1213 mx1,
1214 mx2,
1215 mxm,
1216 my1,
1217 my2,
1218 mym;
1219
1220 if (!l) {
1221 return [x, y, x, y, x, y, x, y];
1222 }
1223
1224 if (closed) {
1225 // if the start and end points are basically on top of each other, close the segment by adding the 2nd point to the end, and the 2nd-to-last point to the beginning (we'll remove them at the end, but this allows the curvature to look perfect)
1226 points.push(nextX, nextY);
1227 nextX = x;
1228 nextY = y;
1229 x = points[l - 2];
1230 y = points[l - 1];
1231 points.unshift(x, y);
1232 l += 4;
1233 nonSmooth = [0, 0].concat(nonSmooth);
1234 }
1235
1236 curviness = curviness || curviness === 0 ? +curviness : 1;
1237
1238 for (i = 2; i < l; i += 2) {
1239 prevX = x;
1240 prevY = y;
1241 x = nextX;
1242 y = nextY;
1243 nextX = +points[i + 2];
1244 nextY = +points[i + 3];
1245
1246 if (x === nextX && y === nextY) {

Callers 3

_smoothRawPathFunction · 0.90
PathEditor.jsFile · 0.90

Calls 1

_roundFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…