mirror of
https://github.com/gonum/gonum.git
synced 2025-10-22 06:39:26 +08:00
spatial/vptree: return error rather than panic
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user