paths extends a conrecLine function to build a set of contours that represent paths along contour lines. It is used as the engine for a closure where ends and conts are closed around in a conrecLine function, and l and z are the line and height values provided by conrec. At the end of a conrec call,
(l line, z float64, ends map[float64]endMap, conts contourSet)
| 343 | // line and height values provided by conrec. At the end of a conrec call, |
| 344 | // conts will contain a map keyed on the set of paths. |
| 345 | func paths(l line, z float64, ends map[float64]endMap, conts contourSet) { |
| 346 | zEnds, ok := ends[z] |
| 347 | if !ok { |
| 348 | zEnds = make(endMap) |
| 349 | ends[z] = zEnds |
| 350 | c := newContour(l, z) |
| 351 | zEnds[l.p1] = c |
| 352 | zEnds[l.p2] = c |
| 353 | conts[c] = struct{}{} |
| 354 | return |
| 355 | } |
| 356 | |
| 357 | c1, ok1 := zEnds[l.p1] |
| 358 | c2, ok2 := zEnds[l.p2] |
| 359 | |
| 360 | // New segment. |
| 361 | if !ok1 && !ok2 { |
| 362 | c := newContour(l, z) |
| 363 | zEnds[l.p1] = c |
| 364 | zEnds[l.p2] = c |
| 365 | conts[c] = struct{}{} |
| 366 | return |
| 367 | } |
| 368 | |
| 369 | if ok1 { |
| 370 | // Add l.p2 to end of l.p1's contour. |
| 371 | if !c1.extend(l, zEnds) { |
| 372 | panic("internal link") |
| 373 | } |
| 374 | } else if ok2 { |
| 375 | // Add l.p1 to end of l.p2's contour. |
| 376 | if !c2.extend(l, zEnds) { |
| 377 | panic("internal link") |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if c1 == c2 { |
| 382 | return |
| 383 | } |
| 384 | |
| 385 | // Join conts. |
| 386 | if ok1 && ok2 { |
| 387 | if !c1.connect(c2, zEnds) { |
| 388 | panic("internal link") |
| 389 | } |
| 390 | delete(conts, c2) |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | // path is a set of points forming a path. |
| 395 | type path []point |
no test coverage detected