Skip to content

Commit 5d3bc36

Browse files
committed
Rename iterator methods
1 parent e3d1e98 commit 5d3bc36

6 files changed

Lines changed: 50 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

88

9-
## [Unreleased](https://github.com/gravitton/grid/compare/v1.1.0...master)
9+
## [Unreleased](https://github.com/gravitton/grid/compare/v1.2.0...master)
10+
11+
12+
## [v1.2.0 (2026-05-12)](https://github.com/gravitton/grid/compare/v1.1.0...v1.2.0)
13+
### Added
14+
- `Array.Values` — iterator over all values (`iter.Seq[*T]`), completing the `Keys` / `Values` / `All` trio
15+
16+
### Changed
17+
- `Array.Iter` renamed to `Array.Keys` — aligns with Go 1.23 iterator conventions (`iter.Seq[K]` iterators are named `Keys`)
18+
- `Array.Iter2` renamed to `Array.All` — aligns with Go 1.23 iterator conventions (`iter.Seq2[K, V]` iterators are named `All`)
19+
- `IterConfig` renamed to `IterOptions`
1020

1121

1222
## [v1.1.0 (2026-05-09)](https://github.com/gravitton/grid/compare/v1.0.0...v1.1.0)
@@ -29,7 +39,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2939
### Added
3040
- `Grid[T]` — generic 2D grid with configurable layout, spatial mapping, and graph operations
3141
- `Cell[T]` — single grid cell with value access, spatial info (`Center`, `Bounds`, `Polygon`), and graph methods (`Neighbors`, `DistanceTo`, `Range`, `PathTo`)
32-
- `Array[T]` — low-level flat 2D array with `Get`, `Set`, `Fill`, `Clear`, `Clone`, `Iter`, `Iter2`
42+
- `Array[T]` — low-level flat 2D array with `Get`, `Set`, `Fill`, `Clear`, `Clone`, `Iter`, `All`
3343
- `NewRectGrid[T]` — rectangular grid with 4-directional (cardinal) movement
3444
- `NewIsometricRectGrid[T]` — isometric (diamond-projection) rectangular grid
3545
- `RectGridOpts.DiagonalMovement()` — option to enable 8-directional movement on rectangular grids

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ path := g.Path(
6464
Iterating a viewport:
6565

6666
```go
67-
for cell := range g.Iter(&grid.IterConfig{Bounds: viewport}) {
67+
for cell := range g.Iter(&grid.IterOptions{Bounds: viewport}) {
6868
draw(cell)
6969
}
7070
```
@@ -147,7 +147,7 @@ g.Clear()
147147
g.Clone() *Grid[T]
148148

149149
// Iteration (draw order resolved automatically from grid type)
150-
g.Iter(config *IterConfig) iter.Seq[*Cell[T]] // config nil = full grid bounds
150+
g.Iter(config *IterOptions) iter.Seq[*Cell[T]] // config nil = full grid bounds
151151
```
152152

153153
### Cell
@@ -193,8 +193,9 @@ a.Set(index ints.Point, value T)
193193
a.Fill(value T)
194194
a.Clear()
195195
a.Clone() Array[T]
196-
a.Iter() iter.Seq[ints.Point]
197-
a.Iter2() iter.Seq2[ints.Point, *T]
196+
a.Keys() iter.Seq[ints.Point]
197+
a.Values() iter.Seq[*T]
198+
a.All() iter.Seq2[ints.Point, *T]
198199
```
199200

200201
### Spatial range

array.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func (a Array[T]) Clone() Array[T] {
7373
return Array[T]{a.size, data}
7474
}
7575

76-
// Iter returns iterator over all points.
77-
func (a Array[T]) Iter() iter.Seq[ints.Point] {
76+
// Keys returns iterator over all points.
77+
func (a Array[T]) Keys() iter.Seq[ints.Point] {
7878
return func(yield func(ints.Point) bool) {
7979
for y := range a.Height() {
8080
for x := range a.Width() {
@@ -86,10 +86,21 @@ func (a Array[T]) Iter() iter.Seq[ints.Point] {
8686
}
8787
}
8888

89-
// Iter2 returns an iterator over all (point, value) pairs.
90-
func (a Array[T]) Iter2() iter.Seq2[ints.Point, *T] {
89+
// Values returns an iterator over all values.
90+
func (a Array[T]) Values() iter.Seq[*T] {
91+
return func(yield func(*T) bool) {
92+
for i := range a.data {
93+
if !yield(&a.data[i]) {
94+
return
95+
}
96+
}
97+
}
98+
}
99+
100+
// All returns an iterator over all (point, value) pairs.
101+
func (a Array[T]) All() iter.Seq2[ints.Point, *T] {
91102
return func(yield func(ints.Point, *T) bool) {
92-
for pt := range a.Iter() {
103+
for pt := range a.Keys() {
93104
if !yield(pt, &a.data[a.index(pt)]) {
94105
return
95106
}

array_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestArray_Clone_Independence(t *testing.T) {
6868
func TestArray_Iter_Order(t *testing.T) {
6969
a := Arr[int](geom.Sz(3, 2))
7070
var points []ints.Point
71-
for p := range a.Iter() {
71+
for p := range a.Keys() {
7272
points = append(points, p)
7373
}
7474
assert.Equal(t, len(points), 6)
@@ -84,7 +84,7 @@ func TestArray_Iter2(t *testing.T) {
8484
a.Set(geom.Pt(1, 0), 42)
8585
count := 0
8686
found := false
87-
for p, v := range a.Iter2() {
87+
for p, v := range a.All() {
8888
count++
8989
if p == geom.Pt(1, 0) {
9090
assert.Equal(t, *v, 42)
@@ -98,7 +98,7 @@ func TestArray_Iter2(t *testing.T) {
9898
func TestArray_Iter_EarlyStop(t *testing.T) {
9999
a := Arr[int](geom.Sz(5, 5))
100100
count := 0
101-
for range a.Iter() {
101+
for range a.Keys() {
102102
count++
103103
if count == 3 {
104104
break

iter.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/gravitton/geometry/types/ints"
1010
)
1111

12-
// IterConfig configures bounds-based grid iteration.
12+
// IterOptions configures bounds-based grid iteration.
1313
// Pass a Bounds to restrict iteration to cells near the visible rectangle; one
1414
// extra row and column are included on every edge so partially visible tiles
1515
// are not culled. Border cells may lie outside the grid (cell.Valid() == false).
@@ -22,37 +22,37 @@ import (
2222
// odd — so tiles in the same visual row are drawn back-to-front.
2323
// - Hex pointy-top (HexPointyTop): row-major; the row offset is along X only,
2424
// so a single pass is sufficient for correct draw order.
25-
type IterConfig struct {
25+
type IterOptions struct {
2626
Bounds floats.Rectangle
2727
}
2828

2929
// Iter returns an iterator over grid cells in draw order (painter's algorithm).
3030
// Pass nil to iterate every cell using the full grid bounds.
31-
// Pass an IterConfig to restrict iteration to a viewport subset.
31+
// Pass an IterOptions to restrict iteration to a viewport subset.
3232
// The iteration strategy is resolved automatically from the grid layout, so
3333
// tiles are always yielded back-to-front regardless of grid type.
3434
// Cells at the boundary of the bounds may lie outside the grid (cell.Valid() == false).
35-
func (g *Grid[T]) Iter(config *IterConfig) iter.Seq[*Cell[T]] {
36-
if config == nil {
37-
config = &IterConfig{}
35+
func (g *Grid[T]) Iter(options *IterOptions) iter.Seq[*Cell[T]] {
36+
if options == nil {
37+
options = &IterOptions{}
3838
}
3939

40-
if config.Bounds.IsZero() {
41-
config.Bounds = g.Bounds()
40+
if options.Bounds.IsZero() {
41+
options.Bounds = g.Bounds()
4242
}
4343

4444
return func(yield func(*Cell[T]) bool) {
4545
switch g.kind {
4646
case kindDefault:
47-
g.iterDefault(config.Bounds, yield)
47+
g.iterDefault(options.Bounds, yield)
4848
case kindIsometric:
49-
g.iterIsometric(config.Bounds, yield)
49+
g.iterIsometric(options.Bounds, yield)
5050
case kindHexagonalFlatTop:
51-
g.iterHexagonal(config.Bounds, yield, false, true)
51+
g.iterHexagonal(options.Bounds, yield, false, true)
5252
case kindHexagonalPointyTop:
53-
g.iterHexagonal(config.Bounds, yield, false, false)
53+
g.iterHexagonal(options.Bounds, yield, false, false)
5454
default:
55-
g.iterDefault(config.Bounds, yield)
55+
g.iterDefault(options.Bounds, yield)
5656
}
5757
}
5858

iter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestGrid_Iter_Bounds(t *testing.T) {
5050
// Viewport covering only cells (0,0)–(1,1) centers plus half-cell padding.
5151
viewport := geom.RectFromMinMax(geom.Pt(0.0, 0.0), geom.Pt(64.0, 64.0))
5252
valid := 0
53-
for cell := range g.Iter(&IterConfig{Bounds: viewport}) {
53+
for cell := range g.Iter(&IterOptions{Bounds: viewport}) {
5454
if cell.Valid() {
5555
valid++
5656
}

0 commit comments

Comments
 (0)