spatial/vptree: return error rather than panic

This commit is contained in:
Dan Kortschak
2019-06-28 14:40:10 +09:30
parent 6006dfb55c
commit 536a303fd6
4 changed files with 71 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ package vptree_test
import (
"fmt"
"log"
"gonum.org/v1/gonum/spatial/vptree"
)
@@ -21,7 +22,10 @@ func ExampleTree() {
vptree.Point{7, 2},
}
t := vptree.New(points, 3, nil)
t, err := vptree.New(points, 3, nil)
if err != nil {
log.Fatal(err)
}
q := vptree.Point{8, 7}
p, d := t.Nearest(q)
fmt.Printf("%v is closest point to %v, d=%f\n", p, q, d)
@@ -41,7 +45,10 @@ func ExampleTree_Do() {
}
// Print all points in the data set within 3 of (3, 5).
t := vptree.New(points, 0, nil)
t, err := vptree.New(points, 0, nil)
if err != nil {
log.Fatal(err)
}
q := vptree.Point{3, 5}
t.Do(func(c vptree.Comparable, _ int) (done bool) {
// Compare each distance and output points