Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version-file: go.mod
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v9.2.0
with:
version: v1.50
version: v2.11.4
13 changes: 6 additions & 7 deletions clip/clip.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ func ring(box orb.Bound, in orb.Ring) orb.Ring {
f := in[0]
l := in[len(in)-1]

initClosed := false
if f == l {
initClosed = true
}
initClosed := f == l

for edge := 1; edge <= 8; edge <<= 1 {
out = out[:0]
Expand Down Expand Up @@ -150,9 +147,11 @@ func ring(box orb.Bound, in orb.Ring) orb.Ring {
}

// bitCode returns the point position relative to the bbox:
// left mid right
// top 1001 1000 1010
// mid 0001 0000 0010
//
// left mid right
// top 1001 1000 1010
// mid 0001 0000 0010
//
// bottom 0101 0100 0110
func bitCode(b orb.Bound, p orb.Point) int {
code := 0
Expand Down
6 changes: 3 additions & 3 deletions encoding/ewkb/ewkb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/binary"
"encoding/hex"
"io/ioutil"
"io"
"testing"

"github.com/paulmach/orb"
Expand Down Expand Up @@ -37,7 +37,7 @@ func MustDecodeHex(s string) []byte {

func BenchmarkEncode_Point(b *testing.B) {
g := orb.Point{1, 2}
e := NewEncoder(ioutil.Discard)
e := NewEncoder(io.Discard)

b.ReportAllocs()
b.ResetTimer()
Expand All @@ -54,7 +54,7 @@ func BenchmarkEncode_LineString(b *testing.B) {
{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5},
{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5},
}
e := NewEncoder(ioutil.Discard)
e := NewEncoder(io.Discard)

b.ReportAllocs()
b.ResetTimer()
Expand Down
7 changes: 4 additions & 3 deletions encoding/internal/wkbcommon/wkb.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,12 @@ func readByteOrderType(r io.Reader, buf []byte) (byteOrder, uint32, int, error)
}

var order byteOrder
if buf[0] == 0 {
switch buf[0] {
case 0:
order = bigEndian
} else if buf[0] == 1 {
case 1:
order = littleEndian
} else {
default:
return 0, 0, 0, ErrNotWKB
}

Expand Down
6 changes: 3 additions & 3 deletions encoding/mvt/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"math"
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -388,7 +388,7 @@ func comparePoints(t testing.TB, e, r []orb.Point, xEpsilon, yEpsilon float64) {
}

func loadMVT(t testing.TB, tile maptile.Tile) []byte {
data, err := ioutil.ReadFile(fmt.Sprintf("testdata/%d-%d-%d.mvt", tile.Z, tile.X, tile.Y))
data, err := os.ReadFile(fmt.Sprintf("testdata/%d-%d-%d.mvt", tile.Z, tile.X, tile.Y))
if err != nil {
t.Fatalf("failed to load mvt file: %v", err)
}
Expand All @@ -397,7 +397,7 @@ func loadMVT(t testing.TB, tile maptile.Tile) []byte {
}

func loadGeoJSON(t testing.TB, tile maptile.Tile) map[string]*geojson.FeatureCollection {
data, err := ioutil.ReadFile(fmt.Sprintf("testdata/%d-%d-%d.json", tile.Z, tile.X, tile.Y))
data, err := os.ReadFile(fmt.Sprintf("testdata/%d-%d-%d.json", tile.Z, tile.X, tile.Y))
if err != nil {
t.Fatalf("failed to load mvt file: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions encoding/mvt/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"compress/gzip"
"errors"
"fmt"
"io/ioutil"
"io"

"github.com/paulmach/orb"
"github.com/paulmach/orb/encoding/mvt/vectortile"
Expand All @@ -23,7 +23,7 @@ func UnmarshalGzipped(data []byte) (Layers, error) {
return nil, fmt.Errorf("failed to create gzreader: %v", err)
}

decoded, err := ioutil.ReadAll(gzreader)
decoded, err := io.ReadAll(gzreader)
if err != nil {
return nil, fmt.Errorf("failed to unzip: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions encoding/wkb/wkb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package wkb
import (
"bytes"
"encoding/binary"
"io/ioutil"
"io"
"testing"

"github.com/paulmach/orb"
Expand All @@ -27,7 +27,7 @@ func TestMustMarshal(t *testing.T) {

func BenchmarkEncode_Point(b *testing.B) {
g := orb.Point{1, 2}
e := NewEncoder(ioutil.Discard)
e := NewEncoder(io.Discard)

b.ReportAllocs()
b.ResetTimer()
Expand All @@ -44,7 +44,7 @@ func BenchmarkEncode_LineString(b *testing.B) {
{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5},
{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5},
}
e := NewEncoder(ioutil.Discard)
e := NewEncoder(io.Discard)

b.ReportAllocs()
b.ResetTimer()
Expand Down
4 changes: 2 additions & 2 deletions encoding/wkt/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package wkt

import (
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/paulmach/orb"
Expand Down Expand Up @@ -103,7 +103,7 @@ func BenchmarkUnmarshalMultiPolygon(b *testing.B) {
}

func loadJSON(tb testing.TB, filename string, obj interface{}) {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
tb.Fatalf("failed to load mvt file: %v", err)
}
Expand Down
9 changes: 5 additions & 4 deletions geo/area.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ func ringArea(r orb.Ring) float64 {

area := 0.0
for i := 0; i < l; i++ {
if i == l-3 { // i = N-3
switch i {
case l - 3: // i = N-3
lo = l - 3
mi = l - 2
hi = 0
} else if i == l-2 { // i = N-2
case l - 2: // i = N-2
lo = l - 2
mi = 0
hi = 0
} else if i == l-1 { // i = N-1
case l - 1: // i = N-1
lo = 0
mi = 0
hi = 1
} else { // i = 0 to N-3
default: // i = 0 to N-3
lo = i
mi = i + 1
hi = i + 2
Expand Down
10 changes: 5 additions & 5 deletions geojson/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package geojson
import (
"bytes"
"encoding/json"
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -424,7 +424,7 @@ func TestFeature_MarshalBSON_extraMembers(t *testing.T) {
// }

func BenchmarkFeatureMarshalJSON(b *testing.B) {
data, err := ioutil.ReadFile("../encoding/mvt/testdata/16-17896-24449.json")
data, err := os.ReadFile("../encoding/mvt/testdata/16-17896-24449.json")
if err != nil {
b.Fatalf("could not open file: %v", err)
}
Expand All @@ -446,7 +446,7 @@ func BenchmarkFeatureMarshalJSON(b *testing.B) {
}

func BenchmarkFeatureUnmarshalJSON(b *testing.B) {
data, err := ioutil.ReadFile("../encoding/mvt/testdata/16-17896-24449.json")
data, err := os.ReadFile("../encoding/mvt/testdata/16-17896-24449.json")
if err != nil {
b.Fatalf("could not open file: %v", err)
}
Expand All @@ -463,7 +463,7 @@ func BenchmarkFeatureUnmarshalJSON(b *testing.B) {
}

func BenchmarkFeatureMarshalBSON(b *testing.B) {
data, err := ioutil.ReadFile("../encoding/mvt/testdata/16-17896-24449.json")
data, err := os.ReadFile("../encoding/mvt/testdata/16-17896-24449.json")
if err != nil {
b.Fatalf("could not open file: %v", err)
}
Expand All @@ -485,7 +485,7 @@ func BenchmarkFeatureMarshalBSON(b *testing.B) {
}

func BenchmarkFeatureUnmarshalBSON(b *testing.B) {
data, err := ioutil.ReadFile("../encoding/mvt/testdata/16-17896-24449.json")
data, err := os.ReadFile("../encoding/mvt/testdata/16-17896-24449.json")
if err != nil {
b.Fatalf("could not open file: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/paulmach/orb

go 1.15
go 1.25

require (
github.com/gogo/protobuf v1.3.2
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/paulmach/protoscan v0.2.1 h1:rM0FpcTjUMvPUNk2BhPJrreDKetq43ChnL+x1sRg8O8=
Expand Down Expand Up @@ -68,13 +66,11 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
3 changes: 3 additions & 0 deletions maptile/tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ func (t Tile) Children() Tiles {

// ChildrenInZoomRange returns all the children tiles of tile from ranges [zoomStart, zoomEnd], both ends inclusive.
func ChildrenInZoomRange(tile Tile, zoomStart, zoomEnd Zoom) Tiles {
//nolint:staticcheck // clearer this way
if !(zoomStart <= zoomEnd) {
panic("zoomStart must be <= zoomEnd")
}

//nolint:staticcheck // clearer this way
if !(tile.Z <= zoomStart) {
panic("tile.Z is must be <= zoomStart")
}
Expand Down
12 changes: 6 additions & 6 deletions maptile/tilecover/cover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package tilecover

import (
"encoding/json"
"io/ioutil"
"math"
"os"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestTestdata(t *testing.T) {

// ts := Geometry(f.Geometry, tc.max)
// blob, _ := json.MarshalIndent(MergeUp(ts, tc.min).ToFeatureCollection(), "", " ")
// ioutil.WriteFile("./testdata/"+tc.name+"_out.geojson", blob, 0644)
// os.WriteFile("./testdata/"+tc.name+"_out.geojson", blob, 0644)

expected := loadFeatureCollection(t, "./testdata/"+tc.name+"_out.geojson")

Expand All @@ -108,7 +108,7 @@ func TestTestdata(t *testing.T) {
}

func TestCountries(t *testing.T) {
files, err := ioutil.ReadDir("./testdata/world")
files, err := os.ReadDir("./testdata/world")
if err != nil {
t.Errorf("could not read directory: %v", err)
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func sortFC(fc *geojson.FeatureCollection) {

func loadFeature(t testing.TB, path string) *geojson.Feature {
t.Helper()
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("unable to read file: %v", err)
}
Expand Down Expand Up @@ -210,7 +210,7 @@ func loadFeature(t testing.TB, path string) *geojson.Feature {

func loadFeatureCollection(t testing.TB, path string) *geojson.FeatureCollection {
t.Helper()
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("unable to read file: %v", err)
}
Expand Down Expand Up @@ -250,7 +250,7 @@ func output(t testing.TB, name string, r *geojson.FeatureCollection) {
t.Fatalf("error marshalling json: %v", err)
}

err = ioutil.WriteFile("failure_"+name+".geojson", data, 0644)
err = os.WriteFile("failure_"+name+".geojson", data, 0644)
if err != nil {
t.Fatalf("write file failure: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions planar/contains.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func rayIntersect(p, s, e orb.Point) (intersects, on bool) {
s, e = e, s
}

if p[0] == s[0] {
switch p[0] {
case s[0]:
if p[1] == s[1] {
// p == start
return false, true
Expand All @@ -84,7 +85,7 @@ func rayIntersect(p, s, e orb.Point) (intersects, on bool) {

// Move the y coordinate to deal with degenerate case
p[0] = math.Nextafter(p[0], math.Inf(1))
} else if p[0] == e[0] {
case e[0]:
if p[1] == e[1] {
// matching the end point
return false, true
Expand Down
6 changes: 5 additions & 1 deletion simplify/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ func benchmarkData() orb.LineString {
if err != nil {
panic(err)
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
panic(err)
}
}()

var points []float64
err = json.NewDecoder(f).Decode(&points)
Expand Down
Loading