changeset 4151:d12c2f4d3483

Made 'golint' more happy with the octree package.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 02 Aug 2019 11:56:48 +0200
parents 40bd6854a294
children 78ec61acf72e
files pkg/octree/tree.go pkg/octree/triangulator.go
diffstat 2 files changed, 53 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/octree/tree.go	Fri Aug 02 11:53:20 2019 +0200
+++ b/pkg/octree/tree.go	Fri Aug 02 11:56:48 2019 +0200
@@ -321,7 +321,7 @@
 	return result
 }
 
-func (t *Tree) GenerateRandomVertices(n int, callback func([]Vertex)) {
+func (ot *Tree) GenerateRandomVertices(n int, callback func([]Vertex)) {
 	var wg sync.WaitGroup
 
 	jobs := make(chan int)
@@ -336,8 +336,8 @@
 		wg.Add(1)
 		go func() {
 			defer wg.Done()
-			xRange := common.Random(t.Min.X, t.Max.X)
-			yRange := common.Random(t.Min.Y, t.Max.Y)
+			xRange := common.Random(ot.Min.X, ot.Max.X)
+			yRange := common.Random(ot.Min.Y, ot.Max.Y)
 
 			for size := range jobs {
 				var vertices []Vertex
@@ -348,7 +348,7 @@
 				}
 				for len(vertices) < size {
 					x, y := xRange(), yRange()
-					if z, ok := t.Value(x, y); ok {
+					if z, ok := ot.Value(x, y); ok {
 						vertices = append(vertices, Vertex{X: x, Y: y, Z: z})
 					}
 				}
--- a/pkg/octree/triangulator.go	Fri Aug 02 11:53:20 2019 +0200
+++ b/pkg/octree/triangulator.go	Fri Aug 02 11:56:48 2019 +0200
@@ -20,7 +20,7 @@
 package octree
 
 import (
-	"fmt"
+	"errors"
 	"math"
 	"sort"
 )
@@ -43,22 +43,22 @@
 
 // sorting a triangulator sorts the `ids` such that the referenced points
 // are in order by their distance to `center`
-func (a *triangulator) Len() int {
-	return len(a.points)
+func (tri *triangulator) Len() int {
+	return len(tri.points)
 }
 
-func (a *triangulator) Swap(i, j int) {
-	a.ids[i], a.ids[j] = a.ids[j], a.ids[i]
+func (tri *triangulator) Swap(i, j int) {
+	tri.ids[i], tri.ids[j] = tri.ids[j], tri.ids[i]
 }
 
-func (a *triangulator) Less(i, j int) bool {
-	d1 := a.squaredDistances[a.ids[i]]
-	d2 := a.squaredDistances[a.ids[j]]
+func (tri *triangulator) Less(i, j int) bool {
+	d1 := tri.squaredDistances[tri.ids[i]]
+	d2 := tri.squaredDistances[tri.ids[j]]
 	if d1 != d2 {
 		return d1 < d2
 	}
-	p1 := a.points[a.ids[i]]
-	p2 := a.points[a.ids[j]]
+	p1 := tri.points[tri.ids[i]]
+	p2 := tri.points[tri.ids[j]]
 	if p1.X != p2.X {
 		return p1.X < p2.X
 	}
@@ -135,7 +135,7 @@
 		}
 	}
 	if minRadius == infinity {
-		return fmt.Errorf("No Delaunay triangulation exists for this input.")
+		return errors.New("no delaunay triangulation exists for this input")
 	}
 
 	// swap the order of the seed points for counter-clockwise orientation
@@ -264,35 +264,35 @@
 	return nil
 }
 
-func (t *triangulator) hashKey(point Vertex) int {
-	d := point.Sub2D(t.center)
-	return int(pseudoAngle(d.X, d.Y) * float64(len(t.hash)))
+func (tri *triangulator) hashKey(point Vertex) int {
+	d := point.Sub2D(tri.center)
+	return int(pseudoAngle(d.X, d.Y) * float64(len(tri.hash)))
 }
 
-func (t *triangulator) hashEdge(e *node) {
-	t.hash[t.hashKey(t.points[e.i])] = e
+func (tri *triangulator) hashEdge(e *node) {
+	tri.hash[tri.hashKey(tri.points[e.i])] = e
 }
 
-func (t *triangulator) addTriangle(i0, i1, i2, a, b, c int32) int32 {
-	i := int32(t.trianglesLen)
-	t.triangles[i] = i0
-	t.triangles[i+1] = i1
-	t.triangles[i+2] = i2
-	t.link(i, a)
-	t.link(i+1, b)
-	t.link(i+2, c)
-	t.trianglesLen += 3
+func (tri *triangulator) addTriangle(i0, i1, i2, a, b, c int32) int32 {
+	i := int32(tri.trianglesLen)
+	tri.triangles[i] = i0
+	tri.triangles[i+1] = i1
+	tri.triangles[i+2] = i2
+	tri.link(i, a)
+	tri.link(i+1, b)
+	tri.link(i+2, c)
+	tri.trianglesLen += 3
 	return i
 }
 
-func (t *triangulator) link(a, b int32) {
-	t.halfedges[a] = b
+func (tri *triangulator) link(a, b int32) {
+	tri.halfedges[a] = b
 	if b >= 0 {
-		t.halfedges[b] = a
+		tri.halfedges[b] = a
 	}
 }
 
-func (t *triangulator) legalize(a int32) int32 {
+func (tri *triangulator) legalize(a int32) int32 {
 	// if the pair of triangles doesn't satisfy the Delaunay condition
 	// (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
 	// then do the same check/flip recursively for the new pair of triangles
@@ -308,7 +308,7 @@
 	//          \||/                  \  /
 	//           pr                    pr
 
-	b := t.halfedges[a]
+	b := tri.halfedges[a]
 
 	a0 := a - a%3
 	b0 := b - b%3
@@ -321,53 +321,53 @@
 		return ar
 	}
 
-	p0 := t.triangles[ar]
-	pr := t.triangles[a]
-	pl := t.triangles[al]
-	p1 := t.triangles[bl]
+	p0 := tri.triangles[ar]
+	pr := tri.triangles[a]
+	pl := tri.triangles[al]
+	p1 := tri.triangles[bl]
 
-	illegal := inCircle(t.points[p0], t.points[pr], t.points[pl], t.points[p1])
+	illegal := inCircle(tri.points[p0], tri.points[pr], tri.points[pl], tri.points[p1])
 
 	if illegal {
-		t.triangles[a] = p1
-		t.triangles[b] = p0
+		tri.triangles[a] = p1
+		tri.triangles[b] = p0
 
 		// edge swapped on the other side of the hull (rare)
 		// fix the halfedge reference
-		if t.halfedges[bl] == -1 {
-			e := t.hull
+		if tri.halfedges[bl] == -1 {
+			e := tri.hull
 			for {
 				if e.t == bl {
 					e.t = a
 					break
 				}
 				e = e.next
-				if e == t.hull {
+				if e == tri.hull {
 					break
 				}
 			}
 		}
 
-		t.link(a, t.halfedges[bl])
-		t.link(b, t.halfedges[ar])
-		t.link(ar, bl)
+		tri.link(a, tri.halfedges[bl])
+		tri.link(b, tri.halfedges[ar])
+		tri.link(ar, bl)
 
 		br := b0 + (b+1)%3
 
-		t.legalize(a)
-		return t.legalize(br)
+		tri.legalize(a)
+		return tri.legalize(br)
 	}
 
 	return ar
 }
 
-func (t *triangulator) convexHull() []Vertex {
+func (tri *triangulator) convexHull() []Vertex {
 	var result []Vertex
-	e := t.hull
+	e := tri.hull
 	for e != nil {
-		result = append(result, t.points[e.i])
+		result = append(result, tri.points[e.i])
 		e = e.prev
-		if e == t.hull {
+		if e == tri.hull {
 			break
 		}
 	}