changeset 2498:843f39b9327e octree-diff

Handle hole more precisely.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 04 Mar 2019 14:46:49 +0100
parents c18ae8992070
children 62adfe9cbbde
files pkg/octree/polygon.go
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/octree/polygon.go	Mon Mar 04 13:32:57 2019 +0100
+++ b/pkg/octree/polygon.go	Mon Mar 04 14:46:49 2019 +0100
@@ -17,6 +17,7 @@
 	"bytes"
 	"encoding/binary"
 	"fmt"
+	"log"
 	"math"
 
 	"github.com/tidwall/rtree"
@@ -237,7 +238,7 @@
 	point := []float64{box.X1, box.Y1}
 
 	// Check holes first: inside a hole means outside.
-	if len(p.rings) > 0 {
+	if len(p.rings) > 1 {
 		for _, hole := range p.rings[1:] {
 			if hole.contains(point) {
 				return IntersectionOutSide
@@ -280,7 +281,7 @@
 	point := []float64{t[0].X, t[0].Y}
 
 	// Check holes first: inside a hole means outside.
-	if len(p.rings) > 0 {
+	if len(p.rings) > 1 {
 		for _, hole := range p.rings[1:] {
 			if hole.contains(point) {
 				return IntersectionOutSide
@@ -302,7 +303,9 @@
 		return false
 	}
 
-	contains := intersectsWithRaycast(point, rng[:2], rng[len(rng)-2:len(rng)])
+	end := len(rng)/2 - 1
+
+	contains := intersectsWithRaycast(point, rng[:2], rng[end*2:end*2+2])
 
 	for i := 2; i < len(rng); i += 2 {
 		if intersectsWithRaycast(point, rng[i-2:i], rng[i:i+2]) {
@@ -396,12 +399,16 @@
 
 	rngs := make([]ring, numRings)
 
+	log.Printf("info: Number of rings: %d\n", len(rngs))
+
 	for rng := uint32(0); rng < numRings; rng++ {
 		var numVertices uint32
 		if err = binary.Read(r, order, &numVertices); err != nil {
 			return err
 		}
 
+		log.Printf("info: Number of vertices in ring %d: %d\n", rng, numVertices)
+
 		numVertices *= 2
 		vertices := make([]float64, numVertices)