changeset 5702:fe83406fe7ed sr-v2

Fix bug in sorting the vertices.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 14 Feb 2024 22:38:14 +0100
parents c23fa3d1824c
children d2ccf6bb6940
files pkg/mesh/meshserialize_v2.go
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/mesh/meshserialize_v2.go	Tue Feb 13 23:25:48 2024 +0100
+++ b/pkg/mesh/meshserialize_v2.go	Wed Feb 14 22:38:14 2024 +0100
@@ -20,7 +20,6 @@
 	"io"
 	"math"
 	"slices"
-	"sort"
 
 	"gemma.intevation.de/gemma/pkg/common"
 )
@@ -353,17 +352,17 @@
 
 	for p := indices; len(p) > 0; d1, d2 = d2, d1 {
 		l := min(len(p), t)
-		slices.SortStableFunc(p[:l], d2)
+		slices.SortStableFunc(p[:l], d1)
 		p = p[l:]
 	}
 
-	// We really need to to sort the vertices actually, too.
-	sort.Slice(vertices, func(i, j int) bool { return indices[i] < indices[j] })
-
+	v2 := make([]Vertex, len(vertices))
 	reindices := make([]int32, len(indices))
 	for i, idx := range indices {
+		v2[i] = vertices[idx]
 		reindices[idx] = int32(i)
 	}
+	copy(vertices, v2)
 
 	// Update the indices in the triangles.
 	for _, tri := range s.tin.Triangles {