changeset 4733:1c205bb3d0fd stack-polygons

Take another point into account when checking containment.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 18 Oct 2019 02:10:56 +0200
parents 7083fd1da169
children 56bd9ba0354c
files pkg/octree/areas.go
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/octree/areas.go	Fri Oct 18 01:41:24 2019 +0200
+++ b/pkg/octree/areas.go	Fri Oct 18 02:10:56 2019 +0200
@@ -236,6 +236,11 @@
 	roots []*bboxNode
 }
 
+func (cnt contour) contains(o contour) bool {
+	return contains(cnt, o[0].X, o[0].Y) ||
+		contains(cnt, o[len(o)/2].X, o[len(o)/2].Y)
+}
+
 func (cnt contour) closed() bool {
 	return len(cnt) >= 3
 }
@@ -274,7 +279,7 @@
 	var nr *bboxNode
 
 	for i, r := range bn.children {
-		if r.box.Inside(box) && contains(cnt, r.cnt[0].X, r.cnt[0].Y) {
+		if r.box.Inside(box) && cnt.contains(r.cnt) {
 			if nr == nil {
 				nr = &bboxNode{box: box, cnt: cnt}
 			}
@@ -301,7 +306,7 @@
 
 	// check if new is inside an old
 	for _, r := range bn.children {
-		if box.Inside(r.box) && contains(r.cnt, cnt[0].X, cnt[0].Y) {
+		if box.Inside(r.box) && r.cnt.contains(cnt) {
 			r.insert(cnt, box)
 			return
 		}
@@ -319,7 +324,7 @@
 	var nr *bboxNode
 
 	for i, r := range bf.roots {
-		if r.box.Inside(box) && contains(cnt, r.cnt[0].Y, r.cnt[0].Y) {
+		if r.box.Inside(box) && cnt.contains(r.cnt) {
 			if nr == nil {
 				nr = &bboxNode{box: box, cnt: cnt}
 			}
@@ -346,7 +351,7 @@
 
 	// check if new is inside an old
 	for _, r := range bf.roots {
-		if box.Inside(r.box) && contains(r.cnt, cnt[0].X, cnt[0].Y) {
+		if box.Inside(r.box) && r.cnt.contains(cnt) {
 			r.insert(cnt, box)
 			return
 		}
@@ -432,7 +437,6 @@
 	}
 
 	bf.generate(out)
-	log.Printf("generated: %d\n", len(mp))
 
 	return mp
 }