| 6491 | cases[t2 << 3].forEach(stitch); |
| 6492 | |
| 6493 | function stitch(line) { |
| 6494 | var start = [line[0][0] + x, line[0][1] + y], |
| 6495 | end = [line[1][0] + x, line[1][1] + y], |
| 6496 | startIndex = index(start), |
| 6497 | endIndex = index(end), |
| 6498 | f, g; |
| 6499 | if (f = fragmentByEnd[startIndex]) { |
| 6500 | if (g = fragmentByStart[endIndex]) { |
| 6501 | delete fragmentByEnd[f.end]; |
| 6502 | delete fragmentByStart[g.start]; |
| 6503 | if (f === g) { |
| 6504 | f.ring.push(end); |
| 6505 | callback(f.ring); |
| 6506 | } else { |
| 6507 | fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)}; |
| 6508 | } |
| 6509 | } else { |
| 6510 | delete fragmentByEnd[f.end]; |
| 6511 | f.ring.push(end); |
| 6512 | fragmentByEnd[f.end = endIndex] = f; |
| 6513 | } |
| 6514 | } else if (f = fragmentByStart[endIndex]) { |
| 6515 | if (g = fragmentByEnd[startIndex]) { |
| 6516 | delete fragmentByStart[f.start]; |
| 6517 | delete fragmentByEnd[g.end]; |
| 6518 | if (f === g) { |
| 6519 | f.ring.push(end); |
| 6520 | callback(f.ring); |
| 6521 | } else { |
| 6522 | fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)}; |
| 6523 | } |
| 6524 | } else { |
| 6525 | delete fragmentByStart[f.start]; |
| 6526 | f.ring.unshift(start); |
| 6527 | fragmentByStart[f.start = startIndex] = f; |
| 6528 | } |
| 6529 | } else { |
| 6530 | fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]}; |
| 6531 | } |
| 6532 | } |
| 6533 | } |
| 6534 | |
| 6535 | function index(point) { |