(segment, totalPoints)
| 1101 | } // plots a number of points along the segment as evenly as possible while retaining non-smooth (angled) anchors. |
| 1102 | |
| 1103 | export function segmentToDistributedPoints(segment, totalPoints) { |
| 1104 | segment.samples || measureSegment(segment); |
| 1105 | var samples = segment.samples, |
| 1106 | lookup = segment.lookup, |
| 1107 | resolution = segment.resolution, |
| 1108 | totalLength = segment.totalLength, |
| 1109 | points = segment.slice(0, 2), |
| 1110 | curveStoppingPoints = [], |
| 1111 | l = segment.length - 4, |
| 1112 | i = 6, |
| 1113 | limit = 0.2, |
| 1114 | startLength = 0, |
| 1115 | curvePointsCumulative = 0, |
| 1116 | t, |
| 1117 | curvePoints, |
| 1118 | min, |
| 1119 | max, |
| 1120 | ci, |
| 1121 | ratioInc, |
| 1122 | j, |
| 1123 | inv, |
| 1124 | curveLength, |
| 1125 | length, |
| 1126 | a, |
| 1127 | nonSmooth, |
| 1128 | curveStoppingPointIndex, |
| 1129 | sampleIndex; // first, loop through each anchor and find out if it's smooth (curve) or not by comparing the angle to each control point (if they're within a certain range, it's smooth). We want to keep pivot points (non-smooth) anchors but allow curved/smooth ones to be subject to simplification. |
| 1130 | |
| 1131 | for (; i < l; i += 6) { |
| 1132 | if (Math.abs(_atan2(segment[i + 1] - segment[i - 1], segment[i] - segment[i - 2]) - _atan2(segment[i + 3] - segment[i + 1], segment[i + 2] - segment[i])) > limit) { |
| 1133 | curveStoppingPoints.push(i); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | curveStoppingPoints.push(segment.length - 2); // the last anchor is always a curve stopping point. |
| 1138 | |
| 1139 | l = curveStoppingPoints.length; |
| 1140 | points.nonSmooth = nonSmooth = [1]; // keep track of which points are non-smooth so that when we call pointsToSegment() we can maintain their angle. |
| 1141 | |
| 1142 | if (totalPoints > l) { |
| 1143 | totalPoints -= l; |
| 1144 | |
| 1145 | for (ci = 0; ci < l; ci++) { |
| 1146 | curveStoppingPointIndex = curveStoppingPoints[ci]; |
| 1147 | sampleIndex = Math.round(curveStoppingPointIndex / 6 * resolution); |
| 1148 | curveLength = samples[sampleIndex - 1] - startLength; |
| 1149 | curvePoints = Math.round(samples[sampleIndex - 1] / totalLength * totalPoints) - curvePointsCumulative; |
| 1150 | curvePointsCumulative += curvePoints; |
| 1151 | ratioInc = 1 / (curvePoints + 1); |
| 1152 | |
| 1153 | for (j = 1; j <= curvePoints; j++) { |
| 1154 | length = startLength + curveLength * j * ratioInc; |
| 1155 | i = lookup.length ? lookup[length < totalLength ? ~~(length / segment.minLength) : lookup.length - 1] || 0 : _getSampleIndex(samples, length, length / totalLength); |
| 1156 | min = i ? samples[i - 1] : 0; |
| 1157 | max = samples[i]; |
| 1158 | |
| 1159 | if (max < length) { |
| 1160 | min = max; |
no test coverage detected
searching dependent graphs…