From 73c72eed5e854546ca5080ae2ce7ded9e4b93ffb Mon Sep 17 00:00:00 2001 From: HossamSaberr Date: Tue, 10 Mar 2026 06:05:16 +0200 Subject: [PATCH 1/2] ix CI: Replace pointTo:do: with loops in CTAlternateArray2D --- src/Containers-Array2D/CTAlternateArray2D.class.st | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Containers-Array2D/CTAlternateArray2D.class.st b/src/Containers-Array2D/CTAlternateArray2D.class.st index 42ccfd4..7f8a477 100644 --- a/src/Containers-Array2D/CTAlternateArray2D.class.st +++ b/src/Containers-Array2D/CTAlternateArray2D.class.st @@ -32,17 +32,22 @@ 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 width do: [ :x | + 1 to: self height do: [ :y | + aBlock value: x@y ] ] ] { #category : 'iterate' } -CTAlternateArray2D >> allPositionsWithin: someDistance from: someOrigin [ +CTAlternateArray2D >> allPositionsWithin: someDistance from: someOrigin [ | answer topLeft bottomRight | answer := OrderedCollection new. topLeft := someOrigin - someDistance max: self firstPosition. bottomRight := someOrigin + someDistance min: self dimension. - topLeft pointTo: bottomRight do: [ :each | answer add: each ]. + + topLeft x to: bottomRight x do: [ :x | + topLeft y to: bottomRight y do: [ :y | + answer add: x@y ] ]. + ^ answer ] From e4f8e36d3f07233077f31264c9ca629edbbc353d Mon Sep 17 00:00:00 2001 From: HossamSaberr Date: Tue, 10 Mar 2026 08:00:36 +0200 Subject: [PATCH 2/2] Add fromRows:pad: to CTNewArray2D to align creation APIs --- .../CTNewArray2DTest.class.st | 12 ++++++++++++ src/Containers-Array2D/CTNewArray2D.class.st | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Containers-Array2D-Tests/CTNewArray2DTest.class.st b/src/Containers-Array2D-Tests/CTNewArray2DTest.class.st index fed2802..98aeed7 100644 --- a/src/Containers-Array2D-Tests/CTNewArray2DTest.class.st +++ b/src/Containers-Array2D-Tests/CTNewArray2DTest.class.st @@ -171,6 +171,18 @@ CTNewArray2DTest >> testFromRightToLeftFromTopToBottomDo [ self assert: res equals: #(2 1 4 3 6 5) asOrderedCollection ] +{ #category : 'tests' } +CTNewArray2DTest >> testFromRowsPad [ + | array | + array := self arrayClass fromRows: #( #(1 2) #(3 4 5) #(6) ) pad: 0. + + self assert: array width equals: 3. + self assert: array height equals: 3. + self assert: (array atRow: 1) equals: #(1 2 0). + self assert: (array atRow: 2) equals: #(3 4 5). + self assert: (array atRow: 3) equals: #(6 0 0). +] + { #category : 'tests' } CTNewArray2DTest >> testFromTopToBottomFromLeftToRightDo [ |foo res| diff --git a/src/Containers-Array2D/CTNewArray2D.class.st b/src/Containers-Array2D/CTNewArray2D.class.st index ab24bf8..56ee976 100644 --- a/src/Containers-Array2D/CTNewArray2D.class.st +++ b/src/Containers-Array2D/CTNewArray2D.class.st @@ -42,6 +42,21 @@ CTNewArray2D class >> fromArray: aCollection width: aSize [ ] +{ #category : 'instance creation' } +CTNewArray2D class >> fromRows: rows pad: paddingElement [ + | width contents pad | + width := rows max: [ :row | row size ]. + contents := rows first species new: (width * rows size) streamContents: [ :aStream | + rows do: [ :row | + aStream nextPutAll: row. + pad := width - row size. + pad > 0 ifTrue: [ aStream next: pad put: paddingElement ]. + ] + ]. + + ^ self fromArray: contents width: width +] + { #category : 'instance creation' } CTNewArray2D class >> new [