Mercurial > gemma
comparison pkg/octree/vertex.go @ 940:be7b83638ec8
Simplified line merging in generating contour lines.
Now its ~40% faster.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 09 Oct 2018 13:30:45 +0200 |
parents | ae1531e00344 |
children | 6ab012d0f0c2 |
comparison
equal
deleted
inserted
replaced
939:a22f66acfd96 | 940:be7b83638ec8 |
---|---|
423 | 423 |
424 again: | 424 again: |
425 for head, lines := range heads { | 425 for head, lines := range heads { |
426 for i, line := range *lines { | 426 for i, line := range *lines { |
427 tail := quant(line[len(line)-1]) | 427 tail := quant(line[len(line)-1]) |
428 if hs := heads[tail]; hs != nil { | 428 for hs := heads[tail]; hs != nil && len(*hs) > 0; hs = heads[tail] { |
429 l := len(*hs) | 429 l := len(*hs) |
430 last := (*hs)[l-1] | 430 last := (*hs)[l-1] |
431 if l == 1 { | 431 (*hs)[l-1] = nil |
432 delete(heads, tail) | 432 *hs = (*hs)[:l-1] |
433 } else { | |
434 (*hs)[l-1] = nil | |
435 *hs = (*hs)[:l-1] | |
436 } | |
437 line = line.Join(last) | 433 line = line.Join(last) |
438 | 434 |
439 if head == quant(line[len(line)-1]) { // its a ring | 435 if tail = quant(line[len(line)-1]); head == tail { // its a ring |
440 out = append(out, line) | 436 out = append(out, line) |
441 // remove from current lines | 437 // remove from current lines |
442 copy((*lines)[i:], (*lines)[i+1:]) | 438 copy((*lines)[i:], (*lines)[i+1:]) |
443 (*lines)[len(*lines)-1] = nil | 439 (*lines)[len(*lines)-1] = nil |
444 *lines = (*lines)[:len(*lines)-1] | 440 *lines = (*lines)[:len(*lines)-1] |
445 } else { | 441 goto again |
446 // overwrite in current lines | |
447 (*lines)[i] = line | |
448 } | 442 } |
449 goto again | 443 // overwrite in current lines |
444 (*lines)[i] = line | |
450 } | 445 } |
451 } | 446 } |
452 } | 447 } |
453 | 448 |
454 rings := len(out) | 449 rings := len(out) |