* Find start and end index of a line.
(points, count, loop, spanGaps)
| 155 | * Find start and end index of a line. |
| 156 | */ |
| 157 | function findStartAndEnd(points, count, loop, spanGaps) { |
| 158 | let start = 0; |
| 159 | let end = count - 1; |
| 160 | |
| 161 | if (loop && !spanGaps) { |
| 162 | // loop and not spanning gaps, first find a gap to start from |
| 163 | while (start < count && !points[start].skip) { |
| 164 | start++; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | // find first non skipped point (after the first gap possibly) |
| 169 | while (start < count && points[start].skip) { |
| 170 | start++; |
| 171 | } |
| 172 | |
| 173 | // if we looped to count, start needs to be 0 |
| 174 | start %= count; |
| 175 | |
| 176 | if (loop) { |
| 177 | // loop will go past count, if start > 0 |
| 178 | end += start; |
| 179 | } |
| 180 | |
| 181 | while (end > start && points[end % count].skip) { |
| 182 | end--; |
| 183 | } |
| 184 | |
| 185 | // end could be more than count, normalize |
| 186 | end %= count; |
| 187 | |
| 188 | return {start, end}; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Compute solid segments from Points, when spanGaps === false |