Skip to content

Fixes #29 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 12 additions & 5 deletions src/Containers-Array2D/CTAlternateArray2D.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@ CTAlternateArray2D class >> width2Height3 [
{ #category : 'iterate' }
CTAlternateArray2D >> allPositionsDo: aBlock [
"Execute a Block on all the positions (points) of the receiver."
self firstPosition pointTo: self dimension do: aBlock
1 to: self height do: [ :y |
1 to: self width do: [ :x |aBlock value: (x @ y)]]
]

{ #category : 'iterate' }
CTAlternateArray2D >> allPositionsWithin: someDistance from: someOrigin [
| answer topLeft bottomRight |
| answer xRange yRange |
answer := OrderedCollection new.
topLeft := someOrigin - someDistance max: self firstPosition.
bottomRight := someOrigin + someDistance min: self dimension.
topLeft pointTo: bottomRight do: [ :each | answer add: each ].
xRange := (someOrigin x - someDistance x max: 1) to:
(someOrigin x + someDistance x min: self width).

yRange := (someOrigin y - someDistance y max: 1) to:
(someOrigin y + someDistance y min: self height).

yRange do: [ :y |
answer addAll: (xRange collect: [ :x | x @ y ]) ].

^ answer
]

Expand Down