@@ -46,18 +46,18 @@ GMTEBrush >> currentMatrixIndex: anObject [
46
46
47
47
{
48
48
#category : #' as yet unclassified' ,
49
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 08:47 '
49
+ #' squeak_changestamp' : ' JS 7/11 /2024 13:59 '
50
50
}
51
51
GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
52
52
53
53
self currentMatrixIndex: anIndex.
54
54
self layer: aLayer.
55
- ^ self currentBrush value.
55
+ ^ self currentBrush value
56
56
]
57
57
58
58
{
59
59
#category : #forms ,
60
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 22:04 '
60
+ #' squeak_changestamp' : ' JS 7/11 /2024 14:07 '
61
61
}
62
62
GMTEBrush >> fillBrush [
63
63
@@ -67,27 +67,27 @@ GMTEBrush >> fillBrush [
67
67
68
68
visited := Matrix rows: (self layer rowCount) columns: self layer columnCount.
69
69
collection := OrderedCollection new .
70
- startTile := layer at: self currentMatrixIndex y at: self currentMatrixIndex x.
70
+ startTile := self layer at: self currentMatrixIndex y at: self currentMatrixIndex x.
71
71
72
- collection add: currentMatrixIndex.
72
+ collection add: self currentMatrixIndex.
73
73
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true .
74
74
75
75
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection.
76
76
self outputSet: collection asSet.
77
77
78
- ^ self outputSet.
78
+ ^ self outputSet
79
79
]
80
80
81
81
{
82
82
#category : #forms ,
83
- #' squeak_changestamp' : ' JS 7/6 /2024 16:46 '
83
+ #' squeak_changestamp' : ' JS 7/11 /2024 13:58 '
84
84
}
85
85
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andCollection: aCollection [
86
86
87
87
| borderingOffsets |
88
88
self flag: ' REFACTOR!' .
89
89
borderingOffsets := {(- 1 )@0 . 0 @(- 1 ). 1 @0 . 0 @1 }.
90
- borderingOffsets do: [: offset|
90
+ borderingOffsets do: [:offset |
91
91
| newIndex newTile |
92
92
newIndex := offset + anIndex.
93
93
((self layer inBounds: newIndex) and : [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue: [
@@ -97,10 +97,10 @@ GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile:
97
97
aVisitedMatrix at: newIndex y at: newIndex x put: true .
98
98
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]
99
99
ifNotNil: [
100
- (newTile isNil not and : [anOriginTile imageForm bits hash = newTile imageForm bits hash])
101
- ifTrue: [ aCollection add: newIndex.
102
- aVisitedMatrix at: newIndex y at: newIndex x put: true .
103
- self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]]
100
+ (newTile isNil not and : [anOriginTile imageForm bits hash = newTile imageForm bits hash]) ifTrue: [
101
+ aCollection add: newIndex.
102
+ aVisitedMatrix at: newIndex y at: newIndex x put: true .
103
+ self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]]
104
104
]
105
105
106
106
{
@@ -121,12 +121,21 @@ GMTEBrush >> firstMatrixIndex: anObject [
121
121
122
122
{
123
123
#category : #forms ,
124
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 21:33 '
124
+ #' squeak_changestamp' : ' JS 7/11 /2024 13:59 '
125
125
}
126
126
GMTEBrush >> initialize [
127
127
128
128
super initialize.
129
- self resetOutputSet.
129
+ self resetOutputSet
130
+ ]
131
+
132
+ {
133
+ #category : #forms ,
134
+ #' squeak_changestamp' : ' JS 7/11/2024 14:04'
135
+ }
136
+ GMTEBrush >> isPointInRadius: aPoint [
137
+ self flag: ' to long? - refactor with lineBrush in mind' .
138
+ ^ (( self currentMatrixIndex x - aPoint x) squared + ( self currentMatrixIndex y - aPoint y) squared <= (self radius - 1 ) squared)
130
139
]
131
140
132
141
{
@@ -147,56 +156,50 @@ GMTEBrush >> layer: anObject [
147
156
148
157
{
149
158
#category : #forms ,
150
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 22:53 '
159
+ #' squeak_changestamp' : ' JS 7/11 /2024 14:09 '
151
160
}
152
161
GMTEBrush >> lineBrush [
153
- | radius collection start end deltaX deltaY stepX stepY error error2 x y offsets |
154
-
162
+ | radius collection start end deltaX deltaY stepX stepY error error2 x y offsets |
163
+ self flag: ' refactor - do instead of collect or select ' .
155
164
radius := self radius - 1 .
156
165
self resetOutputSet.
157
166
self flag: ' todo: method extraction' .
158
- " Helper method to generate radius offsets"
159
- offsets := OrderedCollection new .
160
- (0 - radius to: radius) do: [:dx |
161
- (0 - radius to: radius) do: [:dy |
162
- (dx * dx + dy * dy <= (radius * radius)) ifTrue: [
163
- offsets add: dx @ dy.
164
- ].
165
- ].
166
- ].
167
-
168
- self resetOutputSet.
169
- (self currentMatrixIndex isNil or : [self firstMatrixIndex isNil]) ifTrue: [^ nil ].
170
-
171
- start := self firstMatrixIndex.
172
- end := self currentMatrixIndex.
173
- deltaX := (end x - start x) abs.
174
- deltaY := (end y - start y) abs.
175
- stepX := (start x < end x) ifTrue: [1 ] ifFalse: [- 1 ].
176
- stepY := (start y < end y) ifTrue: [1 ] ifFalse: [- 1 ].
177
- error := deltaX - deltaY.
178
- x := start x.
179
- y := start y.
180
-
181
- collection := OrderedCollection new .
182
-
183
- [
184
- | point |
185
- point := x @ y.
186
- offsets do: [:offset | collection add: (point + offset)].
187
- (x = end x and : [y = end y]) ifTrue: [
188
- self outputSet: collection asSet.
189
- ^ self outputSet.].
190
- error2 := 2 * error.
191
- (error2 > (0 - deltaY)) ifTrue: [
192
- error := error - deltaY.
193
- x := x + stepX.
194
- ].
195
- (error2 < deltaX) ifTrue: [
196
- error := error + deltaX.
197
- y := y + stepY.
198
- ].
199
- ] repeat.
167
+ " Helper method to generate radius offsets"
168
+ offsets := OrderedCollection new .
169
+ (0 - radius to: radius) do: [:dx |
170
+ (0 - radius to: radius) do: [:dy |
171
+ ((dx * dx) + (dy * dy) <= (radius * radius)) ifTrue: [offsets add: dx @ dy]]].
172
+
173
+ self resetOutputSet.
174
+ (self currentMatrixIndex isNil or : [self firstMatrixIndex isNil]) ifTrue: [^ nil ].
175
+
176
+ start := self firstMatrixIndex.
177
+ end := self currentMatrixIndex.
178
+ deltaX := (end x - start x) abs.
179
+ deltaY := (end y - start y) abs.
180
+ stepX := (start x < end x) ifTrue: [1 ] ifFalse: [- 1 ].
181
+ stepY := (start y < end y) ifTrue: [1 ] ifFalse: [- 1 ].
182
+ error := deltaX - deltaY.
183
+ x := start x.
184
+ y := start y.
185
+
186
+ collection := OrderedCollection new .
187
+
188
+ [
189
+ | point |
190
+ point := x @ y.
191
+ offsets do: [:offset | collection add: (point + offset)].
192
+ (x = end x and : [y = end y]) ifTrue: [
193
+ self outputSet: collection asSet.
194
+ ^ self outputSet].
195
+ error2 := 2 * error.
196
+ (error2 > (0 - deltaY)) ifTrue: [
197
+ error := error - deltaY.
198
+ x := x + stepX].
199
+ (error2 < deltaX) ifTrue: [
200
+ error := error + deltaX.
201
+ y := y + stepY]
202
+ ] repeat
200
203
201
204
]
202
205
@@ -234,71 +237,68 @@ GMTEBrush >> radius: anObject [
234
237
235
238
{
236
239
#category : #forms ,
237
- #' squeak_changestamp' : ' Valentin Teutschbein 7/10 /2024 12:37 '
240
+ #' squeak_changestamp' : ' JS 7/11 /2024 14:06 '
238
241
}
239
242
GMTEBrush >> radiusBrush [
240
243
241
- | collection xMin xMax yMin yMax |
242
- self currentMatrixIndex ifNil: [^ nil ].
244
+ | collection xMin xMax yMin yMax |
245
+ self currentMatrixIndex ifNil: [^ nil ].
243
246
244
- collection := OrderedCollection new .
247
+ collection := OrderedCollection new .
245
248
self flag: ' radius offset is bad' .
246
- xMin := self currentMatrixIndex x - (self radius - 1 ).
247
- xMax := self currentMatrixIndex x + (self radius - 1 ).
248
- yMin := self currentMatrixIndex y - (self radius - 1 ).
249
- yMax := self currentMatrixIndex y + (self radius - 1 ).
249
+ xMin := self currentMatrixIndex x - (self radius - 1 ).
250
+ xMax := self currentMatrixIndex x + (self radius - 1 ).
251
+ yMin := self currentMatrixIndex y - (self radius - 1 ).
252
+ yMax := self currentMatrixIndex y + (self radius - 1 ).
250
253
251
- (xMin to: xMax) do: [:x |
252
- (yMin to: yMax) do: [:y |
253
- (( self currentMatrixIndex x - x) squared + ( self currentMatrixIndex y - y) squared <= (self radius - 1 ) squared) ifTrue: [
254
- collection add: x@y
255
- ].
256
- ].
257
- ].
254
+ self flag: ' select instead of do?' .
255
+ (xMin to: xMax) do: [:x |
256
+ (yMin to: yMax) do: [:y |
257
+ (self isPointInRadius: x @ y) ifTrue: [collection add: x @ y]]].
258
258
259
- collection do: [:i | self outputSet add: i].
259
+ collection do: [:i |
260
+ self outputSet add: i].
260
261
261
- ^ self outputSet.
262
+ ^ self outputSet
262
263
263
264
]
264
265
265
266
{
266
267
#category : #forms ,
267
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 22:04 '
268
+ #' squeak_changestamp' : ' JS 7/11 /2024 13:49 '
268
269
}
269
270
GMTEBrush >> rectangleBrush [
270
271
271
- | collection startRow endRow startCol endCol |
272
+ | collection startRow endRow startCol endCol |
272
273
self resetOutputSet.
273
- (self currentMatrixIndex isNil or : [self firstMatrixIndex isNil]) ifTrue: [^ nil ].
274
- collection := OrderedCollection new .
275
-
276
- " Determine the starting and ending rows and columns"
277
-
278
- startRow := (self currentMatrixIndex x min: self firstMatrixIndex x).
279
- endRow := (self currentMatrixIndex x max: self firstMatrixIndex x).
280
- startCol := (self currentMatrixIndex y min: self firstMatrixIndex y).
281
- endCol := (self currentMatrixIndex y max: self firstMatrixIndex y).
282
-
283
- " Fill the collection with all indices within the rectangle"
284
- startRow to: endRow do: [:row |
285
- startCol to: endCol do: [:col |
286
- collection add: (row@col)
287
- ].
288
- ].
274
+ (self currentMatrixIndex isNil or : [self firstMatrixIndex isNil]) ifTrue: [^ nil ].
275
+ collection := OrderedCollection new .
276
+
277
+ " Determine the starting and ending rows and columns"
278
+ self flag: ' method extraction' .
279
+ startRow := (self currentMatrixIndex x min: self firstMatrixIndex x).
280
+ endRow := (self currentMatrixIndex x max: self firstMatrixIndex x).
281
+ startCol := (self currentMatrixIndex y min: self firstMatrixIndex y).
282
+ endCol := (self currentMatrixIndex y max: self firstMatrixIndex y).
283
+
284
+ " Fill the collection with all indices within the rectangle"
285
+ startRow to: endRow do: [:row |
286
+ startCol to: endCol do: [:col |
287
+ collection add: (row @ col)]].
288
+
289
289
self outputSet: collection asSet.
290
290
291
- ^ self outputSet.
291
+ ^ self outputSet
292
292
293
293
]
294
294
295
295
{
296
296
#category : #select ,
297
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 21:26 '
297
+ #' squeak_changestamp' : ' JS 7/11 /2024 13:43 '
298
298
}
299
299
GMTEBrush >> resetOutputSet [
300
300
301
- self outputSet: Set new .
301
+ self outputSet: Set new
302
302
]
303
303
304
304
{
0 commit comments