diff pkg/octree/builder.go @ 1691:de09bd3b5c05

Octree: Fixed a few golint quirks and normalized logging a bit.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 30 Dec 2018 16:24:51 +0100
parents fbdd7c3cfeac
children f3a9e125f630
line wrap: on
line diff
--- a/pkg/octree/builder.go	Sun Dec 30 15:14:29 2018 +0100
+++ b/pkg/octree/builder.go	Sun Dec 30 16:24:51 2018 +0100
@@ -22,6 +22,7 @@
 	"github.com/golang/snappy"
 )
 
+// Builder is used to turn a TIN into an Octree.
 type Builder struct {
 	t      *Tin
 	nodes  int
@@ -57,10 +58,12 @@
 	}
 }
 
+// NewBuilder creates a new Builder for a TIN.
 func NewBuilder(t *Tin) *Builder {
 	return &Builder{t: t}
 }
 
+// Build builds the Octree.
 func (tb *Builder) Build() {
 
 	triangles := make([]int32, len(tb.t.Triangles))
@@ -72,9 +75,9 @@
 
 	tb.buildRecursive(triangles, tb.t.Min, tb.t.Max, 0)
 	tb.index[0] = int32(len(tb.index))
-	log.Printf("num nodes: %d\n", tb.index[0])
+	log.Printf("info: num nodes: %d\n", tb.index[0])
 
-	log.Printf("nodes: %d leaves: %d index %d\n",
+	log.Printf("info: nodes: %d leaves: %d index %d\n",
 		tb.nodes, tb.leaves, tb.index[0])
 }
 
@@ -144,7 +147,7 @@
 	return int32(pos)
 }
 
-func (tb *Builder) Serialize(w io.Writer) error {
+func (tb *Builder) serialize(w io.Writer) error {
 	var buf [binary.MaxVarintLen32]byte
 
 	if err := binary.Write(w, binary.LittleEndian, tb.index[0]); err != nil {
@@ -167,7 +170,7 @@
 
 		last = x
 	}
-	log.Printf("compressed octree index in bytes: %d (%d)\n",
+	log.Printf("info: compressed octree index in bytes: %d (%d)\n",
 		written, 4*len(tb.index))
 
 	return nil
@@ -175,15 +178,16 @@
 
 func (tb *Builder) writeTo(w io.Writer) error {
 	out := snappy.NewBufferedWriter(w)
-	if err := tb.t.Serialize(out); err != nil {
+	if err := tb.t.serialize(out); err != nil {
 		return err
 	}
-	if err := tb.Serialize(out); err != nil {
+	if err := tb.serialize(out); err != nil {
 		return err
 	}
 	return out.Flush()
 }
 
+// Bytes serializes an Octree into a byte slice.
 func (tb *Builder) Bytes() ([]byte, error) {
 	var buf bytes.Buffer
 	if err := tb.writeTo(&buf); err != nil {
@@ -192,6 +196,7 @@
 	return buf.Bytes(), nil
 }
 
+// Tree returns an Octree from the Builder.
 func (tb *Builder) Tree() *Tree {
 	return &Tree{
 		EPSG:      tb.t.EPSG,