comparison pkg/octree/tree.go @ 4658:4bbfe3dd2ab5 stree-experiment

Completed usage of STRTrees.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 14 Oct 2019 14:58:04 +0200
parents 3eda5a7215ab
children
comparison
equal deleted inserted replaced
4656:a2f16987911b 4658:4bbfe3dd2ab5
310 } 310 }
311 } 311 }
312 } 312 }
313 } 313 }
314 } 314 }
315
316 func (ot *Tree) Diff(other *Tree) PointMap {
317
318 firstVs, secondVs := ot.Vertices(), other.Vertices()
319
320 result := make(PointMap, len(firstVs)+len(secondVs))
321
322 sliceWork(
323 firstVs,
324 result,
325 func(slice []Vertex, turn func([]Vertex) []Vertex) {
326 p := turn(nil)
327 for i := range slice {
328 v := &slice[i]
329 if z, found := other.Value(v.X, v.Y); found {
330 p = append(p, Vertex{v.X, v.Y, v.Z - z})
331 if len(p) == cap(p) {
332 p = turn(p)
333 }
334 }
335 }
336 if len(p) > 0 {
337 turn(p)
338 }
339 })
340
341 sliceWork(
342 secondVs,
343 result,
344 func(
345 slice []Vertex, turn func([]Vertex) []Vertex) {
346 p := turn(nil)
347 for i := range slice {
348 v := &slice[i]
349 if z, found := ot.Value(v.X, v.Y); found {
350 p = append(p, Vertex{v.X, v.Y, z - v.Z})
351 if len(p) == cap(p) {
352 p = turn(p)
353 }
354 }
355 }
356 if len(p) > 0 {
357 turn(p)
358 }
359 })
360
361 return result
362 }