Mercurial > gemma
comparison pkg/octree/tree.go @ 2572:7686c7c23506
Morphological differences: Moved some code into octree package.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 11 Mar 2019 14:00:49 +0100 |
parents | 1ec4c5633eb6 |
children | a6c671abbc35 |
comparison
equal
deleted
inserted
replaced
2571:eec11d3d74f9 | 2572:7686c7c23506 |
---|---|
266 } | 266 } |
267 } | 267 } |
268 } | 268 } |
269 } | 269 } |
270 } | 270 } |
271 | |
272 func (ot *Tree) Diff(other *Tree) PointMap { | |
273 | |
274 firstVs, secondVs := ot.Vertices(), other.Vertices() | |
275 | |
276 result := make(PointMap, len(firstVs)+len(secondVs)) | |
277 | |
278 sliceWork( | |
279 firstVs, | |
280 result, | |
281 func(slice []Vertex, turn func([]Vertex) []Vertex) { | |
282 p := turn(nil) | |
283 for i := range slice { | |
284 v := &slice[i] | |
285 if z, found := other.Value(v.X, v.Y); found { | |
286 p = append(p, Vertex{v.X, v.Y, v.Z - z}) | |
287 if len(p) == cap(p) { | |
288 p = turn(p) | |
289 } | |
290 } | |
291 } | |
292 if len(p) > 0 { | |
293 turn(p) | |
294 } | |
295 }) | |
296 | |
297 sliceWork( | |
298 secondVs, | |
299 result, | |
300 func( | |
301 slice []Vertex, turn func([]Vertex) []Vertex) { | |
302 p := turn(nil) | |
303 for i := range slice { | |
304 v := &slice[i] | |
305 if z, found := ot.Value(v.X, v.Y); found { | |
306 p = append(p, Vertex{v.X, v.Y, z - v.Z}) | |
307 if len(p) == cap(p) { | |
308 p = turn(p) | |
309 } | |
310 } | |
311 } | |
312 if len(p) > 0 { | |
313 turn(p) | |
314 } | |
315 }) | |
316 | |
317 return result | |
318 } |