forked from Snider/Poindexter
Add examples for KDTree and enable errcheck linter in CI
This commit is contained in:
parent
3ba2b4fce3
commit
ca6f89a99c
4 changed files with 49 additions and 0 deletions
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
|
|
@ -21,6 +21,7 @@ jobs:
|
|||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
cache: true
|
||||
|
||||
- name: Go env
|
||||
run: go env
|
||||
|
|
|
|||
|
|
@ -8,13 +8,22 @@ linters:
|
|||
- ineffassign
|
||||
- gofmt
|
||||
- revive
|
||||
- errcheck
|
||||
issues:
|
||||
exclude-use-default: false
|
||||
max-issues-per-linter: 0
|
||||
max-same-issues: 0
|
||||
exclude-rules:
|
||||
# Errcheck is noisy in examples and doc tests; ignore *_test.go for errcheck only.
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- errcheck
|
||||
linters-settings:
|
||||
revive:
|
||||
severity: warning
|
||||
rules:
|
||||
- name: exported
|
||||
arguments: ["disable"] # keep comments pragmatic; we have pkg docs and key API docs
|
||||
errcheck:
|
||||
# Be pragmatic: don't require checking of Close for defer patterns in tests/examples.
|
||||
# (Keep defaults; exclusions above handle test files.)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- pkg.go.dev Examples: `ExampleNewKDTreeFromDim_Insert`, `ExampleKDTree_TiesBehavior`, `ExampleKDTree_Radius_none`.
|
||||
- Lint: enable `errcheck` in `.golangci.yml` with test-file exclusion to reduce noise.
|
||||
- CI: enable module cache in `actions/setup-go` to speed up workflows.
|
||||
|
||||
## [0.2.1] - 2025-11-03
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -163,3 +163,38 @@ func ExampleBuild4DWithStats() {
|
|||
fmt.Println(tr.Dim())
|
||||
// Output: 4
|
||||
}
|
||||
|
||||
func ExampleNewKDTreeFromDim_Insert() {
|
||||
// Construct an empty 2D tree, insert a point, then query.
|
||||
tr, _ := poindexter.NewKDTreeFromDim[string](2)
|
||||
tr.Insert(poindexter.KDPoint[string]{ID: "A", Coords: []float64{0.1, 0.2}, Value: "alpha"})
|
||||
p, _, ok := tr.Nearest([]float64{0, 0})
|
||||
fmt.Printf("ok=%v id=%s dim=%d len=%d", ok, p.ID, tr.Dim(), tr.Len())
|
||||
// Output: ok=true id=A dim=2 len=1
|
||||
}
|
||||
|
||||
func ExampleKDTree_TiesBehavior() {
|
||||
// Two points equidistant from the query; tie ordering is arbitrary,
|
||||
// but distances are equal.
|
||||
pts := []poindexter.KDPoint[int]{
|
||||
{ID: "L", Coords: []float64{-1}},
|
||||
{ID: "R", Coords: []float64{+1}},
|
||||
}
|
||||
tr, _ := poindexter.NewKDTree(pts)
|
||||
ns, ds := tr.KNearest([]float64{0}, 2)
|
||||
_ = ns // neighbor order is unspecified
|
||||
fmt.Printf("equal=%.1f==%.1f? %v", ds[0], ds[1], ds[0] == ds[1])
|
||||
// Output: equal=1.0==1.0? true
|
||||
}
|
||||
|
||||
func ExampleKDTree_Radius_none() {
|
||||
// Radius query that yields no matches.
|
||||
pts := []poindexter.KDPoint[int]{
|
||||
{ID: "a", Coords: []float64{10}},
|
||||
{ID: "b", Coords: []float64{20}},
|
||||
}
|
||||
tr, _ := poindexter.NewKDTree(pts)
|
||||
within, _ := tr.Radius([]float64{0}, 5)
|
||||
fmt.Println(len(within))
|
||||
// Output: 0
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue