changeset 4544:e5ae16f6d846 iso-areas

Lay foundation to join cut segments to longer arcs.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 27 Sep 2019 13:21:20 +0200
parents 2a707732331f
children e7970d84cb4f
files cmd/isoareas/main.go
diffstat 1 files changed, 63 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/isoareas/main.go	Thu Sep 26 18:34:54 2019 +0200
+++ b/cmd/isoareas/main.go	Fri Sep 27 13:21:20 2019 +0200
@@ -89,17 +89,62 @@
 	}
 }
 
-type indexedCut struct {
-	cut   octree.LineStringZ
+type indexedArc struct {
+	arc   int32
 	index int32
 }
 
+func glue(a, b octree.LineStringZ) (octree.LineStringZ, bool) {
+
+	a1, a2 := a[0], a[len(a)-1]
+	b1, b2 := b[0], b[len(b)-1]
+
+	if a1.EpsEquals(b2) {
+		c := make(octree.LineStringZ, len(a)-1+len(b))
+		copy(c, b)
+		copy(c[len(b):], a[1:])
+		return c, true
+	}
+
+	if a2.EpsEquals(b1) {
+		c := make(octree.LineStringZ, len(a)-1+len(b))
+		copy(c, a)
+		copy(c[len(a):], b[1:])
+		return c, true
+	}
+
+	if a1.EpsEquals(b1) {
+		c := make(octree.LineStringZ, len(a)-1+len(b))
+		copy(c, b)
+		c[:len(b)].Reverse()
+		copy(c[len(b):], a[1:])
+		return c, true
+	}
+
+	if a2.EpsEquals(b2) {
+		c := make(octree.LineStringZ, len(a)-1+len(b))
+		copy(c, a)
+		copy(c[len(a):], b[:len(b)-1])
+		c[len(a):].Reverse()
+		return c, true
+	}
+
+	return nil, false
+}
+
+func connectArcs(tri *octree.Triangulation, cut []indexedArc, arcs *[]octree.LineStringZ) {
+
+	// TODO: Implement me!
+}
+
 func intersectTriangles(tri *octree.Triangulation, heights []float64) [][]octree.LineStringZ {
 
-	cuts := make([][]indexedCut, len(heights))
+	cuts := make([][]indexedArc, len(heights))
 
 	classes := make([][]int32, len(heights)+1)
 
+	var arcs []octree.LineStringZ
+
 all:
 	for i := int32(0); i < int32(len(tri.Triangles)); i += 3 {
 		ti := tri.Triangles[i : i+3]
@@ -133,11 +178,19 @@
 			t := octree.Triangle{v0, v1, v2}
 			cut := t.IntersectHorizontal(h)
 			if len(cut) >= 2 {
-				cuts[j] = append(cuts[j], indexedCut{cut, i / 3})
+				arc := int32(len(arcs))
+				arcs = append(arcs, cut)
+				cuts[j] = append(cuts[j], indexedArc{arc, i / 3})
 			}
 		}
 	}
 
+	// connect the arcs in a cut list to longer arcs.
+
+	for _, c := range cuts {
+		connectArcs(tri, c, &arcs)
+	}
+
 	result := make([][]octree.LineStringZ, len(classes))
 
 	log.Println("inside classes:")
@@ -178,7 +231,9 @@
 							if l < 0 || l >= len(cuts) {
 								continue
 							}
-							if curr = findCut(ns[j], cuts[l]); curr != nil {
+
+							if arc := findArc(ns[j], cuts[l]); arc >= 0 {
+								curr = arcs[arc]
 								break
 							}
 						}
@@ -271,7 +326,7 @@
 	return t.Halfedges[idx : idx+3]
 }
 
-func findCut(needle int32, haystack []indexedCut) octree.LineStringZ {
+func findArc(needle int32, haystack []indexedArc) int32 {
 	lo, hi := 0, len(haystack)-1
 	for lo <= hi {
 		mid := (hi-lo)/2 + lo
@@ -281,10 +336,10 @@
 		case v > needle:
 			hi = mid - 1
 		default:
-			return haystack[mid].cut
+			return haystack[mid].arc
 		}
 	}
-	return nil
+	return -1
 }
 
 func contains(needle int32, haystack []int32) bool {