Skip to content

Commit 449925e

Browse files
committed
brush refactoring ...
1 parent efedb74 commit 449925e

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

source/GM-TE/GMTEBrush.class.st

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ Class {
1212
#category : #'GM-TE-UI'
1313
}
1414

15+
{
16+
#category : #'as yet unclassified',
17+
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:01'
18+
}
19+
GMTEBrush class >> borderingOffsets [
20+
21+
^ {(-1)@0. 0@(-1). 1@0. 0@1}
22+
]
23+
1524
{
1625
#category : #forms,
1726
#'squeak_changestamp' : 'JS 7/11/2024 15:40'
@@ -61,61 +70,57 @@ GMTEBrush >> currentMatrixIndex: anObject [
6170

6271
{
6372
#category : #'as yet unclassified',
64-
#'squeak_changestamp' : 'JS 7/11/2024 13:59'
73+
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:10'
6574
}
6675
GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
6776

77+
anIndex ifNil: [^ nil].
6878
self currentMatrixIndex: anIndex.
6979
self layer: aLayer.
7080
^ self currentBrush value
7181
]
7282

7383
{
7484
#category : #forms,
75-
#'squeak_changestamp' : 'JS 7/11/2024 14:07'
85+
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:10'
7686
}
7787
GMTEBrush >> fillBrush [
7888

79-
| collection startTile visited |
89+
| startTile visited |
8090
self resetOutputSet.
81-
self currentMatrixIndex ifNil: [^nil].
8291

8392
visited := Matrix rows: (self layer rowCount) columns: self layer columnCount.
84-
collection := OrderedCollection new.
8593
startTile := self layer at: self currentMatrixIndex y at: self currentMatrixIndex x.
8694

87-
collection add: self currentMatrixIndex.
95+
self outputSet add: self currentMatrixIndex.
8896
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true.
8997

90-
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection.
91-
self outputSet: collection asSet.
98+
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andSet: self outputSet.
9299

93100
^ self outputSet
94101
]
95102

96103
{
97104
#category : #forms,
98-
#'squeak_changestamp' : 'JS 7/11/2024 13:58'
105+
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:05'
99106
}
100-
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andCollection: aCollection [
107+
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andSet: aSet [
101108

102-
| borderingOffsets |
103109
self flag: 'REFACTOR!'.
104-
borderingOffsets := {(-1)@0. 0@(-1). 1@0. 0@1}.
105-
borderingOffsets do: [:offset |
110+
GMTEBrush borderingOffsets do: [:offset |
106111
| newIndex newTile |
107112
newIndex := offset + anIndex.
108113
((self layer inBounds: newIndex) and: [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue:[
109114
newTile := self layer at: newIndex y at: newIndex x.
110115
anOriginTile
111-
ifNil: [newTile ifNil: [aCollection add: newIndex.
116+
ifNil: [newTile ifNil: [aSet add: newIndex.
112117
aVisitedMatrix at: newIndex y at: newIndex x put: true.
113-
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]
118+
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andSet: aSet]]
114119
ifNotNil: [
115120
(newTile isNil not and: [anOriginTile imageForm bits hash = newTile imageForm bits hash]) ifTrue: [
116-
aCollection add: newIndex.
121+
aSet add: newIndex.
117122
aVisitedMatrix at: newIndex y at: newIndex x put: true.
118-
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]]
123+
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andSet: aSet]]]]
119124
]
120125

121126
{
@@ -162,18 +167,15 @@ GMTEBrush >> layer: anObject [
162167

163168
{
164169
#category : #forms,
165-
#'squeak_changestamp' : 'JS 7/11/2024 16:16'
170+
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:11'
166171
}
167172
GMTEBrush >> lineBrush [
168173

169-
| offsets |
170174
self resetOutputSet.
171-
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
172-
173-
offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius.
174-
175+
self firstMatrixIndex ifNil: [^nil].
176+
175177
(self rasterizeLineBetweenAStart: self firstMatrixIndex andAnEnd: self currentMatrixIndex) do: [:point |
176-
offsets do: [:offset |
178+
(self calculateOffsetsForRadius: self offsetCorrectedRadius) do: [:offset |
177179
self outputSet add: (point + offset)]].
178180

179181
^(self outputSet)
@@ -208,32 +210,29 @@ GMTEBrush >> outputSet: anObject [
208210

209211
{
210212
#category : #accessing,
211-
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
213+
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:11'
212214
}
213215
GMTEBrush >> radius [
216+
214217
^ radius
215218
]
216219

217220
{
218221
#category : #accessing,
219-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:08'
222+
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:15'
220223
}
221-
GMTEBrush >> radius: anObject [
222-
radius := anObject
224+
GMTEBrush >> radius: aNumber [
225+
226+
radius := aNumber
223227
]
224228

225229
{
226230
#category : #forms,
227-
#'squeak_changestamp' : 'JS 7/11/2024 16:14'
231+
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:09'
228232
}
229233
GMTEBrush >> radiusBrush [
230234

231-
| offsets |
232-
self currentMatrixIndex ifNil: [^nil].
233-
234-
offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius.
235-
236-
offsets do: [:i |
235+
(self calculateOffsetsForRadius: self offsetCorrectedRadius) do: [:i |
237236
self outputSet add: (self currentMatrixIndex + i)].
238237

239238
^ self outputSet
@@ -280,12 +279,12 @@ GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [
280279

281280
{
282281
#category : #forms,
283-
#'squeak_changestamp' : 'JS 7/11/2024 16:29'
282+
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:09'
284283
}
285284
GMTEBrush >> rectangleBrush [
286285

287286
self resetOutputSet.
288-
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
287+
self firstMatrixIndex ifNil: [^ nil].
289288

290289
self flag: 'besser machen?'.
291290
(self currentMatrixIndex x min: self firstMatrixIndex x) to: (self currentMatrixIndex x max: self firstMatrixIndex x) do: [:row |

0 commit comments

Comments
 (0)