You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Answer the element at the given coordinates. If the coordinates are outside the grid bounds, they wrap around using 1-based indexing logic to ensure seamless boundary traversal."
199
+
200
+
| wrappedColwrappedRow |
201
+
wrappedCol := ((col -1) \\self width) +1.
202
+
wrappedRow := ((row -1) \\self height) +1.
203
+
204
+
^selfatColumn: wrappedCol atRow: wrappedRow
205
+
]
206
+
207
+
{ #category : 'accessing' }
208
+
CTArray2D>>atColumnWrap: col atRowWrap: row put: aValue [
209
+
"Store the given value at the specified coordinates. If the coordinates are outside the grid bounds, they wrap around using 1-based indexing logic (e.g., in a grid of width 3, column 4 wraps to 1, and column 0 wraps to 3)."
"Answer a collection of up to 8 valid elements surrounding the given origin. This method does not wrap; neighbors that would fall outside the grid are ignored. Throws an error if the starting origin coordinates are out of bounds."
381
+
382
+
| neighbors |
383
+
384
+
(col between:1and: self width) ifFalse: [ selferror:'Column out of bounds' ].
385
+
(row between:1and: self height) ifFalse: [ selferror:'Row out of bounds' ].
CTArray2D>>neighborsAtColumnWrap: col atRowWrap: row [
401
+
"Answer a collection of exactly 8 elements surrounding the given origin, wrapping across grid boundaries where necessary. Throws an error if the starting origin coordinates are out of bounds."
402
+
403
+
| neighbors |
404
+
405
+
(col between:1and: self width) ifFalse: [ selferror:'Column out of bounds' ].
406
+
(row between:1and: self height) ifFalse: [ selferror:'Row out of bounds' ].
407
+
408
+
neighbors :=OrderedCollectionnew.
409
+
410
+
row -1to: row +1do: [ :r |
411
+
col -1to: col +1do: [ :c |
412
+
(r = row and: [ c = col ]) ifFalse: [
413
+
neighbors add: (selfatColumnWrap: c atRowWrap: r) ] ] ].
414
+
415
+
^ neighbors
416
+
]
417
+
356
418
{ #category : 'accessing - compatibility' }
357
419
CTArray2D>> numberOfColumns [
358
420
"Answer the receiver's width, i.e., its number of x"
0 commit comments