Mercurial > gemma
changeset 1790:fe1aa62195c2
Octree: Same emtry tree fix for horizontal as for vertical traversal. Re-worked both to be BCE friendly.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 14 Jan 2019 11:09:10 +0100 |
parents | 4a7aa3f57efe |
children | 0f98ef2531a5 |
files | pkg/octree/tree.go |
diffstat | 1 files changed, 26 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/octree/tree.go Mon Jan 14 10:33:20 2019 +0100 +++ b/pkg/octree/tree.go Mon Jan 14 11:09:10 2019 +0100 @@ -75,26 +75,28 @@ stack = stack[:len(stack)-1] if top.pos > 0 { // node - for i := int32(0); i < 4; i++ { - a := ot.index[top.pos+i] - b := ot.index[top.pos+i+4] - if a == 0 && b == 0 { - continue - } - dx := top.X2 - top.X1 - dy := top.Y2 - top.Y1 - nbox := Box2D{ - dx*scale[i][0] + top.X1, - dy*scale[i][1] + top.Y1, - dx*scale[i][2] + top.X1, - dy*scale[i][3] + top.Y1, - } - if nbox.Intersects(box) && nbox.IntersectsPlane(line) { - if a != 0 { - stack = append(stack, frame{a, nbox}) + if index := ot.index[top.pos:]; len(index) > 7 { + for i := 0; i < 4; i++ { + a := index[i] + b := index[i+4] + if a == 0 && b == 0 { + continue } - if b != 0 { - stack = append(stack, frame{b, nbox}) + dx := top.X2 - top.X1 + dy := top.Y2 - top.Y1 + nbox := Box2D{ + dx*scale[i][0] + top.X1, + dy*scale[i][1] + top.Y1, + dx*scale[i][2] + top.X1, + dy*scale[i][3] + top.Y1, + } + if nbox.Intersects(box) && nbox.IntersectsPlane(line) { + if a != 0 { + stack = append(stack, frame{a, nbox}) + } + if b != 0 { + stack = append(stack, frame{b, nbox}) + } } } } @@ -162,12 +164,12 @@ } else { max = mid } - if pos+3 < int32(len(ot.index)) { + if index := ot.index[pos:]; len(index) > 3 { stack = append(stack, - frame{ot.index[pos+0], min, max}, - frame{ot.index[pos+1], min, max}, - frame{ot.index[pos+2], min, max}, - frame{ot.index[pos+3], min, max}) + frame{index[0], min, max}, + frame{index[1], min, max}, + frame{index[2], min, max}, + frame{index[3], min, max}) } } else { // leaf pos = -pos - 1