changeset 4543:2a707732331f iso-areas

Look into cuts for finding real class borders.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 26 Sep 2019 18:34:54 +0200
parents 56f4e8cbfab7
children e5ae16f6d846
files cmd/isoareas/main.go
diffstat 1 files changed, 40 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/isoareas/main.go	Thu Sep 26 18:11:38 2019 +0200
+++ b/cmd/isoareas/main.go	Thu Sep 26 18:34:54 2019 +0200
@@ -89,12 +89,12 @@
 	}
 }
 
-func intersectTriangles(tri *octree.Triangulation, heights []float64) [][]octree.LineStringZ {
+type indexedCut struct {
+	cut   octree.LineStringZ
+	index int32
+}
 
-	type indexedCut struct {
-		cut   octree.LineStringZ
-		index int32
-	}
+func intersectTriangles(tri *octree.Triangulation, heights []float64) [][]octree.LineStringZ {
 
 	cuts := make([][]indexedCut, len(heights))
 
@@ -171,17 +171,32 @@
 
 						// TODO: Look into cuts to see
 						// if there are real intersections
-						k := (j + 1) % 3
-						front := tri.Points[ti[j]]
-						back := tri.Points[ti[k]]
+
+						var curr octree.LineStringZ
 
-						curr := octree.LineStringZ{front, back}
+						for l := i - 1; l <= i; l++ {
+							if l < 0 || l >= len(cuts) {
+								continue
+							}
+							if curr = findCut(ns[j], cuts[l]); curr != nil {
+								break
+							}
+						}
+
+						if curr == nil {
+							k := (j + 1) % 3
+							front := tri.Points[ti[j]]
+							back := tri.Points[ti[k]]
+							curr = octree.LineStringZ{front, back}
+						}
 
 					segment:
 						for e := pb.open.Front(); e != nil; e = e.Next() {
 							line := e.Value.(octree.LineStringZ)
 							first, last := line[0], line[len(line)-1]
 
+							front, back := curr[0], curr[len(curr)-1]
+
 							if back.EpsEquals(first) {
 								curr = append(curr, line[1:]...)
 								pb.open.Remove(e)
@@ -256,6 +271,22 @@
 	return t.Halfedges[idx : idx+3]
 }
 
+func findCut(needle int32, haystack []indexedCut) octree.LineStringZ {
+	lo, hi := 0, len(haystack)-1
+	for lo <= hi {
+		mid := (hi-lo)/2 + lo
+		switch v := haystack[mid].index; {
+		case v < needle:
+			lo = mid + 1
+		case v > needle:
+			hi = mid - 1
+		default:
+			return haystack[mid].cut
+		}
+	}
+	return nil
+}
+
 func contains(needle int32, haystack []int32) bool {
 	lo, hi := 0, len(haystack)-1
 	for lo <= hi {