Skip to content

Commit

Permalink
Merge pull request #258 from twpayne/separate-examples-module
Browse files Browse the repository at this point in the history
Move examples into a separate module
  • Loading branch information
twpayne authored Jan 16, 2025
2 parents e6ef077 + 47130fb commit 832071f
Show file tree
Hide file tree
Showing 33 changed files with 384 additions and 383 deletions.
23 changes: 11 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ on:
pull_request:
push:
env:
GOFUMPT_VERSION: 0.6.0
GOTOOLCHAIN: local
GOLANGCI_LINT_VERSION: 1.59.1
GOFUMPT_VERSION: 0.7.0
GOLANGCI_LINT_VERSION: 1.63.4
jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a
with:
cache: true
go-version-file: go.mod
Expand All @@ -30,8 +29,8 @@ jobs:
darwin:
runs-on: macos-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a
with:
cache: true
go-version-file: go.mod
Expand All @@ -42,8 +41,8 @@ jobs:
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a
with:
cache: true
go-version-file: go.mod
Expand All @@ -54,12 +53,12 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a
with:
cache: true
go-version-file: go.mod
- uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86
- uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
with:
version: v${{ env.GOLANGCI_LINT_VERSION }}
- name: format
Expand Down
17 changes: 13 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
run:
go: '1.22'

linters:
enable:
- asasalint
Expand All @@ -16,7 +19,6 @@ linters:
- errcheck
- errchkjson
- errorlint
- exportloopref
- fatcontext
- forbidigo
- forcetypeassert
Expand All @@ -33,7 +35,6 @@ linters:
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
Expand Down Expand Up @@ -82,6 +83,14 @@ linters:
- wastedassign
- whitespace
- zerologlint
- copyloopvar
- exptostd
- iface
- goheader
- intrange
- nilnesserr
- recvcheck
- usetesting
disable:
- cyclop
- depguard
Expand All @@ -94,8 +103,7 @@ linters:
- goconst
- gocyclo
- godox
- goheader
- gomnd
- mnd
- lll
- maintidx
- nestif
Expand All @@ -108,6 +116,7 @@ linters:
- varnamelen
- wrapcheck
- wsl
- gosec

linters-settings:
gci:
Expand Down
22 changes: 11 additions & 11 deletions bounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ type Bounds struct {
// NewBounds creates a new Bounds.
func NewBounds(layout Layout) *Bounds {
stride := layout.Stride()
min, max := make(Coord, stride), make(Coord, stride)
for i := 0; i < stride; i++ {
min[i], max[i] = math.Inf(1), math.Inf(-1)
minValue, maxValue := make(Coord, stride), make(Coord, stride)
for i := range stride {
minValue[i], maxValue[i] = math.Inf(1), math.Inf(-1)
}
return &Bounds{
layout: layout,
min: min,
max: max,
min: minValue,
max: maxValue,
}
}

Expand Down Expand Up @@ -103,19 +103,19 @@ func (b *Bounds) Set(args ...float64) *Bounds {
}
stride := len(args) / 2
b.extendStride(stride)
for i := 0; i < stride; i++ {
for i := range stride {
b.min[i], b.max[i] = args[i], args[i+stride]
}
return b
}

// SetCoords sets the minimum and maximum values of the Bounds.
func (b *Bounds) SetCoords(min, max Coord) *Bounds {
func (b *Bounds) SetCoords(minCoord, maxCoord Coord) *Bounds {
b.min = Coord(make([]float64, b.layout.Stride()))
b.max = Coord(make([]float64, b.layout.Stride()))
for i := 0; i < b.layout.Stride(); i++ {
b.min[i] = math.Min(min[i], max[i])
b.max[i] = math.Max(min[i], max[i])
for i := range b.layout.Stride() {
b.min[i] = math.Min(minCoord[i], maxCoord[i])
b.max[i] = math.Max(minCoord[i], maxCoord[i])
}
return b
}
Expand All @@ -134,7 +134,7 @@ func (b *Bounds) OverlapsPoint(layout Layout, point Coord) bool {
func (b *Bounds) extendFlatCoords(flatCoords []float64, offset, end, stride int) *Bounds {
b.extendStride(stride)
for i := offset; i < end; i += stride {
for j := 0; j < stride; j++ {
for j := range stride {
b.min[j] = math.Min(b.min[j], flatCoords[i+j])
b.max[j] = math.Max(b.max[j], flatCoords[i+j])
}
Expand Down
16 changes: 8 additions & 8 deletions encoding/ewkb/ewkb.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func Read(r io.Reader) (geom.T, error) {
return nil, wkbcommon.ErrGeometryTooLarge{Level: 1, N: int(n), Limit: limit}
}
mp := geom.NewMultiPoint(layout).SetSRID(int(srid))
for i := uint32(0); i < n; i++ {
for range n {
g, err := Read(r)
if err != nil {
return nil, err
Expand All @@ -123,7 +123,7 @@ func Read(r io.Reader) (geom.T, error) {
return nil, wkbcommon.ErrGeometryTooLarge{Level: 2, N: int(n), Limit: limit}
}
mls := geom.NewMultiLineString(layout).SetSRID(int(srid))
for i := uint32(0); i < n; i++ {
for range n {
g, err := Read(r)
if err != nil {
return nil, err
Expand All @@ -146,7 +146,7 @@ func Read(r io.Reader) (geom.T, error) {
return nil, wkbcommon.ErrGeometryTooLarge{Level: 3, N: int(n), Limit: limit}
}
mp := geom.NewMultiPolygon(layout).SetSRID(int(srid))
for i := uint32(0); i < n; i++ {
for range n {
g, err := Read(r)
if err != nil {
return nil, err
Expand All @@ -169,7 +169,7 @@ func Read(r io.Reader) (geom.T, error) {
return nil, wkbcommon.ErrGeometryTooLarge{Level: 1, N: int(n), Limit: limit}
}
gc := geom.NewGeometryCollection().SetSRID(int(srid))
for i := uint32(0); i < n; i++ {
for range n {
g, err := Read(r)
if err != nil {
return nil, err
Expand Down Expand Up @@ -274,7 +274,7 @@ func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T) error {
if err := binary.Write(w, byteOrder, uint32(n)); err != nil {
return err
}
for i := 0; i < n; i++ {
for i := range n {
if err := Write(w, byteOrder, g.Point(i)); err != nil {
return err
}
Expand All @@ -285,7 +285,7 @@ func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T) error {
if err := binary.Write(w, byteOrder, uint32(n)); err != nil {
return err
}
for i := 0; i < n; i++ {
for i := range n {
if err := Write(w, byteOrder, g.LineString(i)); err != nil {
return err
}
Expand All @@ -296,7 +296,7 @@ func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T) error {
if err := binary.Write(w, byteOrder, uint32(n)); err != nil {
return err
}
for i := 0; i < n; i++ {
for i := range n {
if err := Write(w, byteOrder, g.Polygon(i)); err != nil {
return err
}
Expand All @@ -307,7 +307,7 @@ func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T) error {
if err := binary.Write(w, byteOrder, uint32(n)); err != nil {
return err
}
for i := 0; i < n; i++ {
for i := range n {
if err := Write(w, byteOrder, g.Geom(i)); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion encoding/geojson/geojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (c *nestedFloat64WithMaxDecimalDigits) marshalJSON(
switch val.Kind() {
case reflect.Slice:
buf = append(buf, '[')
for i := 0; i < val.Len(); i++ {
for i := range val.Len() {
if i > 0 {
buf = append(buf, ',')
}
Expand Down
8 changes: 4 additions & 4 deletions encoding/igc/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ func parseDec(s string, start, stop int) (int, error) {

// parseDecInRange parsers a decimal value in s[start:stop], and returns an
// error if it is outside the range [min, max).
func parseDecInRange(s string, start, stop, min, max int) (int, error) {
func parseDecInRange(s string, start, stop, minValue, maxValue int) (int, error) {
result, err := parseDec(s, start, stop)
switch {
case err != nil:
return result, err
case result < min || max <= result:
return result, fmt.Errorf("value out of range: %d, want %d-%d", result, min, max)
case result < minValue || maxValue <= result:
return result, fmt.Errorf("value out of range: %d, want %d-%d", result, minValue, maxValue)
}
return result, nil
}
Expand Down Expand Up @@ -255,7 +255,7 @@ func (p *parser) parseI(line string) error {
if len(line) < 7*n+3 {
return fmt.Errorf("invalid I record length: %d, want %d", len(line), 7*n+3)
}
for i := 0; i < n; i++ {
for i := range n {
var start, stop int
if start, err = parseDec(line, 7*i+3, 7*i+5); err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions encoding/igc/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ type Encoder struct {
// An EncoderOption sets an option on an Encoder.
type EncoderOption func(*Encoder)

func clamp(x, min, max int) int {
func clamp(x, minValue, maxValue int) int {
switch {
case x < min:
return min
case x > max:
return max
case x < minValue:
return minValue
case x > maxValue:
return maxValue
default:
return x
}
Expand Down
1 change: 0 additions & 1 deletion encoding/wkb/sql_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func Example_value_different_shapes() {
}

for _, s := range shapes {
s := s
result, err := db.Exec(`INSERT INTO objects (name, location) VALUES (?, ?);`, s.Name, &s.Geom)
if err != nil {
log.Fatal(err)
Expand Down
16 changes: 8 additions & 8 deletions encoding/wkb/wkb.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func Read(r io.Reader, opts ...wkbcommon.WKBOption) (geom.T, error) {
return nil, wkbcommon.ErrGeometryTooLarge{Level: 1, N: int(n), Limit: limit}
}
mp := geom.NewMultiPoint(layout)
for i := uint32(0); i < n; i++ {
for range n {
g, err := Read(r, opts...)
if err != nil {
return nil, err
Expand All @@ -127,7 +127,7 @@ func Read(r io.Reader, opts ...wkbcommon.WKBOption) (geom.T, error) {
return nil, wkbcommon.ErrGeometryTooLarge{Level: 2, N: int(n), Limit: limit}
}
mls := geom.NewMultiLineString(layout)
for i := uint32(0); i < n; i++ {
for range n {
g, err := Read(r, opts...)
if err != nil {
return nil, err
Expand All @@ -150,7 +150,7 @@ func Read(r io.Reader, opts ...wkbcommon.WKBOption) (geom.T, error) {
return nil, wkbcommon.ErrGeometryTooLarge{Level: 3, N: int(n), Limit: limit}
}
mp := geom.NewMultiPolygon(layout)
for i := uint32(0); i < n; i++ {
for range n {
g, err := Read(r, opts...)
if err != nil {
return nil, err
Expand All @@ -170,7 +170,7 @@ func Read(r io.Reader, opts ...wkbcommon.WKBOption) (geom.T, error) {
return nil, err
}
gc := geom.NewGeometryCollection()
for i := uint32(0); i < n; i++ {
for range n {
g, err := Read(r, opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -281,7 +281,7 @@ func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T, opts ...wkbcommon.
if err := wkbcommon.WriteUInt32(w, byteOrder, uint32(n)); err != nil {
return err
}
for i := 0; i < n; i++ {
for i := range n {
if err := Write(w, byteOrder, g.Point(i), opts...); err != nil {
return err
}
Expand All @@ -292,7 +292,7 @@ func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T, opts ...wkbcommon.
if err := wkbcommon.WriteUInt32(w, byteOrder, uint32(n)); err != nil {
return err
}
for i := 0; i < n; i++ {
for i := range n {
if err := Write(w, byteOrder, g.LineString(i), opts...); err != nil {
return err
}
Expand All @@ -303,7 +303,7 @@ func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T, opts ...wkbcommon.
if err := wkbcommon.WriteUInt32(w, byteOrder, uint32(n)); err != nil {
return err
}
for i := 0; i < n; i++ {
for i := range n {
if err := Write(w, byteOrder, g.Polygon(i), opts...); err != nil {
return err
}
Expand All @@ -314,7 +314,7 @@ func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T, opts ...wkbcommon.
if err := wkbcommon.WriteUInt32(w, byteOrder, uint32(n)); err != nil {
return err
}
for i := 0; i < n; i++ {
for i := range n {
if err := Write(w, byteOrder, g.Geom(i), opts...); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions encoding/wkb/wkb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestRandom(t *testing.T) {
}

func BenchmarkUnmarshal(b *testing.B) {
for n := 0; n < b.N; n++ {
for range b.N {
for _, tc := range testdata.Random {
if _, err := Unmarshal(tc.WKB); err != nil {
b.Errorf("unmarshal error %v", err)
Expand All @@ -350,7 +350,7 @@ func BenchmarkUnmarshal(b *testing.B) {
}

func BenchmarkMarshal(b *testing.B) {
for n := 0; n < b.N; n++ {
for range b.N {
for _, tc := range testdata.Random {
if _, err := Marshal(tc.G, NDR); err != nil {
b.Errorf("marshal error %v", err)
Expand Down
2 changes: 1 addition & 1 deletion encoding/wkbcommon/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func WriteByte(w io.Writer, value byte) error {
// WriteEmptyPointAsNaN outputs EmptyPoint as NaN values.
func WriteEmptyPointAsNaN(w io.Writer, byteOrder binary.ByteOrder, numCoords int) error {
coords := make([]float64, numCoords)
for i := 0; i < numCoords; i++ {
for i := range numCoords {
coords[i] = geom.PointEmptyCoord()
}
return WriteFlatCoords0(w, byteOrder, coords)
Expand Down
Loading

0 comments on commit 832071f

Please sign in to comment.