contourPaths returns a collection of vg.Paths describing contour lines based on the input data in m cut at the given levels. The trX and trY function are coordinate transforms. The returned map contains slices of paths keyed on the value of the contour level. contouPaths sorts levels ascending as a
(m GridXYZ, levels []float64, trX, trY func(float64) vg.Length)
| 296 | // on the value of the contour level. contouPaths sorts levels ascending as a |
| 297 | // side effect. |
| 298 | func contourPaths(m GridXYZ, levels []float64, trX, trY func(float64) vg.Length) map[float64][]vg.Path { |
| 299 | sort.Float64s(levels) |
| 300 | |
| 301 | ends := make(map[float64]endMap) |
| 302 | conts := make(contourSet) |
| 303 | conrec(m, levels, func(_, _ int, l line, z float64) { |
| 304 | paths(l, z, ends, conts) |
| 305 | }) |
| 306 | ends = nil |
| 307 | |
| 308 | // TODO(kortschak): Check that all non-loop paths have |
| 309 | // both ends at boundary. If any end is not at a boundary |
| 310 | // it may have a partner near by. Find this partner and join |
| 311 | // the two conts by merging the near by ends at the mean |
| 312 | // location. This operation is done level by level to ensure |
| 313 | // close contours of different heights are not joined. |
| 314 | // A partner should be a float error different end, but I |
| 315 | // suspect that is is possible for a bi- or higher order |
| 316 | // furcation so it may be that the path ends at middle node |
| 317 | // of another path. This needs to be investigated. |
| 318 | |
| 319 | // Excise loops from crossed paths. |
| 320 | for c := range conts { |
| 321 | // Always try to do quick excision in production if possible. |
| 322 | c.exciseLoops(conts, true) |
| 323 | } |
| 324 | |
| 325 | // Build vg.Paths. |
| 326 | paths := make(map[float64][]vg.Path) |
| 327 | for c := range conts { |
| 328 | paths[c.z] = append(paths[c.z], c.path(trX, trY)) |
| 329 | } |
| 330 | |
| 331 | return paths |
| 332 | } |
| 333 | |
| 334 | // contourSet hold a working collection of contours. |
| 335 | type contourSet map[*contour]struct{} |
searching dependent graphs…