1
+ "
2
+ A GMTEBrush is responsible for returning a set of indices that are selected by the user and selecting the interchangeable algorithm for the execution.
3
+ "
1
4
Class {
2
5
#name : #GMTEBrush ,
3
6
#superclass : #Object ,
9
12
' firstMatrixIndex' ,
10
13
' outputSet'
11
14
],
12
- #category : #' GM-TE-UI'
15
+ #category : #' GM-TE-UI' ,
16
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12/2024 13:49'
13
17
}
14
18
15
19
{
@@ -22,54 +26,58 @@ GMTEBrush class >> borderingOffsets [
22
26
]
23
27
24
28
{
25
- #category : #forms ,
26
- #' squeak_changestamp' : ' JS 7/11 /2024 15:40 '
29
+ #category : #brushHelper ,
30
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 14:03 '
27
31
}
28
32
GMTEBrush >> calculateOffsetsForRadius: aRadius [
29
33
30
34
|offsets |
31
35
offsets := OrderedCollection new .
32
- (0 - radius to: radius) do: [:dx |
33
- (0 - radius to: radius) do: [:dy |
36
+ (0 - self radius to: self radius) do: [:dx |
37
+ (0 - self radius to: self radius) do: [:dy |
34
38
((dx squared + dy squared) <= aRadius squared) ifTrue: [offsets add: dx @ dy]]].
35
39
36
- ^ offsets
40
+ ^ offsets
37
41
]
38
42
39
43
{
40
44
#category : #accessing ,
41
- #' squeak_changestamp' : ' Valentin Teutschbein 7/6 /2024 12:48 '
45
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:40 '
42
46
}
43
47
GMTEBrush >> currentBrush [
48
+
44
49
^ currentBrush
45
50
]
46
51
47
52
{
48
53
#category : #accessing ,
49
- #' squeak_changestamp' : ' Valentin Teutschbein 7/6 /2024 12:48 '
54
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:40 '
50
55
}
51
- GMTEBrush >> currentBrush: anObject [
52
- currentBrush := anObject
56
+ GMTEBrush >> currentBrush: aBrush [
57
+
58
+ currentBrush := aBrush
53
59
]
54
60
55
61
{
56
62
#category : #accessing ,
57
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 08:47 '
63
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:41 '
58
64
}
59
65
GMTEBrush >> currentMatrixIndex [
66
+
60
67
^ currentMatrixIndex
61
68
]
62
69
63
70
{
64
71
#category : #accessing ,
65
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 08:47 '
72
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:41 '
66
73
}
67
- GMTEBrush >> currentMatrixIndex: anObject [
68
- currentMatrixIndex := anObject
74
+ GMTEBrush >> currentMatrixIndex: anIndex [
75
+
76
+ currentMatrixIndex := anIndex
69
77
]
70
78
71
79
{
72
- #category : #' as yet unclassified ' ,
80
+ #category : #execute ,
73
81
#' squeak_changestamp' : ' Valentin Teutschbein 7/11/2024 17:10'
74
82
}
75
83
GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
@@ -81,8 +89,8 @@ GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
81
89
]
82
90
83
91
{
84
- #category : #forms ,
85
- #' squeak_changestamp' : ' Valentin Teutschbein 7/11 /2024 17:10 '
92
+ #category : #brushes ,
93
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:26 '
86
94
}
87
95
GMTEBrush >> fillBrush [
88
96
@@ -95,51 +103,49 @@ GMTEBrush >> fillBrush [
95
103
self outputSet add: self currentMatrixIndex.
96
104
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true .
97
105
98
- self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andSet: self outputSet .
106
+ self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile.
99
107
100
108
^ self outputSet
101
109
]
102
110
103
111
{
104
- #category : #forms ,
105
- #' squeak_changestamp' : ' JS 7/11 /2024 18:28 '
112
+ #category : #brushHelper ,
113
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:32 '
106
114
}
107
- GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andSet: aSet [
108
- self flag: ' REFACTOR! ' .
109
-
115
+ GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile [
116
+
117
+ | newIndex newTile |
110
118
GMTEBrush borderingOffsets do: [:offset |
111
- | newIndex newTile tilesNil tilesSame |
112
119
newIndex := offset + anIndex.
113
120
((self layer inBounds: newIndex) and : [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue: [
114
121
newTile := self layer at: newIndex y at: newIndex x.
115
122
116
- tilesNil := (anOriginTile isNil) and : [newTile isNil].
117
- tilesSame := (anOriginTile isNil not and : [newTile isNil not ]) and : [anOriginTile imageForm bits hash = newTile imageForm bits hash].
118
-
119
- (tilesNil or : tilesSame) ifTrue: [
120
- aSet add: newIndex.
123
+ (self tile: anOriginTile equalsTile: newTile) ifTrue: [
124
+ self outputSet add: newIndex.
121
125
aVisitedMatrix at: newIndex y at: newIndex x put: true .
122
- self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andSet: aSet ]]]
126
+ self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile]]]
123
127
]
124
128
125
129
{
126
130
#category : #accessing ,
127
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 08:49 '
131
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:41 '
128
132
}
129
133
GMTEBrush >> firstMatrixIndex [
134
+
130
135
^ firstMatrixIndex
131
136
]
132
137
133
138
{
134
139
#category : #accessing ,
135
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 08:49 '
140
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:42 '
136
141
}
137
- GMTEBrush >> firstMatrixIndex: anObject [
138
- firstMatrixIndex := anObject
142
+ GMTEBrush >> firstMatrixIndex: anIndex [
143
+
144
+ firstMatrixIndex := anIndex
139
145
]
140
146
141
147
{
142
- #category : #forms ,
148
+ #category : #initialization ,
143
149
#' squeak_changestamp' : ' JS 7/11/2024 13:59'
144
150
}
145
151
GMTEBrush >> initialize [
@@ -150,34 +156,36 @@ GMTEBrush >> initialize [
150
156
151
157
{
152
158
#category : #accessing ,
153
- #' squeak_changestamp' : ' Valentin Teutschbein 7/6 /2024 14:51 '
159
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:42 '
154
160
}
155
161
GMTEBrush >> layer [
162
+
156
163
^ layer
157
164
]
158
165
159
166
{
160
167
#category : #accessing ,
161
- #' squeak_changestamp' : ' Valentin Teutschbein 7/6 /2024 14:51 '
168
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:42 '
162
169
}
163
- GMTEBrush >> layer: anObject [
164
- layer := anObject
170
+ GMTEBrush >> layer: aLayer [
171
+
172
+ layer := aLayer
165
173
]
166
174
167
175
{
168
- #category : #forms ,
169
- #' squeak_changestamp' : ' Valentin Teutschbein 7/11 /2024 17:11 '
176
+ #category : #brushes ,
177
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:53 '
170
178
}
171
179
GMTEBrush >> lineBrush [
172
180
173
181
self resetOutputSet.
174
- self firstMatrixIndex ifNil: [^ nil ].
182
+ self firstMatrixIndex ifNil: [^ nil ].
175
183
176
- (self rasterizeLineBetweenAStart : self firstMatrixIndex andAnEnd : self currentMatrixIndex) do: [:point |
184
+ (self rasterizeLineBetweenStart : self firstMatrixIndex andEnd : self currentMatrixIndex) do: [:index |
177
185
(self calculateOffsetsForRadius: self offsetCorrectedRadius) do: [:offset |
178
- self outputSet add: (point + offset)]].
186
+ self outputSet add: (index + offset)]].
179
187
180
- ^ ( self outputSet)
188
+ ^ self outputSet
181
189
182
190
]
183
191
@@ -193,18 +201,20 @@ GMTEBrush >> offsetCorrectedRadius [
193
201
194
202
{
195
203
#category : #accessing ,
196
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 21:18 '
204
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:43 '
197
205
}
198
206
GMTEBrush >> outputSet [
207
+
199
208
^ outputSet
200
209
]
201
210
202
211
{
203
212
#category : #accessing ,
204
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 21:18 '
213
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:43 '
205
214
}
206
- GMTEBrush >> outputSet: anObject [
207
- outputSet := anObject
215
+ GMTEBrush >> outputSet: aSet [
216
+
217
+ outputSet := aSet
208
218
]
209
219
210
220
{
@@ -218,15 +228,15 @@ GMTEBrush >> radius [
218
228
219
229
{
220
230
#category : #accessing ,
221
- #' squeak_changestamp' : ' Valentin Teutschbein 7/11 /2024 17:15 '
231
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:43 '
222
232
}
223
- GMTEBrush >> radius: aNumber [
233
+ GMTEBrush >> radius: aRadius [
224
234
225
- radius := aNumber
235
+ radius := aRadius
226
236
]
227
237
228
238
{
229
- #category : #forms ,
239
+ #category : #brushes ,
230
240
#' squeak_changestamp' : ' Valentin Teutschbein 7/11/2024 17:09'
231
241
}
232
242
GMTEBrush >> radiusBrush [
@@ -239,62 +249,64 @@ GMTEBrush >> radiusBrush [
239
249
]
240
250
241
251
{
242
- #category : #forms ,
243
- #' squeak_changestamp' : ' JS 7/11 /2024 18:26 '
252
+ #category : #brushHelper ,
253
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:52 '
244
254
}
245
- GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [
255
+ GMTEBrush >> rasterizeLineBetweenStart: aStartIndex andEnd: anEndIndex [
246
256
" implementation of Bresenhams Line Algorithm"
247
257
248
- | linePointsCollection deltaX deltaY stepX stepY error error2 x y |
258
+ | lineIndexCollection deltaX deltaY stepX stepY error error2 x y index |
249
259
250
- self flag: ' todo: method extraction? - Ich glaube geht schlecht ' .
260
+ self flag: ' repeat formatting ' .
251
261
252
- deltaX := (anEndPoint x - aStartPoint x) abs.
253
- deltaY := (anEndPoint y - aStartPoint y) abs.
254
- stepX := (aStartPoint x < anEndPoint x) ifTrue: [1 ] ifFalse: [- 1 ].
255
- stepY := (aStartPoint y < anEndPoint y) ifTrue: [1 ] ifFalse: [- 1 ].
262
+ deltaX := (anEndIndex x - aStartIndex x) abs.
263
+ deltaY := (anEndIndex y - aStartIndex y) abs.
264
+ stepX := (aStartIndex x < anEndIndex x) ifTrue: [1 ] ifFalse: [- 1 ].
265
+ stepY := (aStartIndex y < anEndIndex y) ifTrue: [1 ] ifFalse: [- 1 ].
256
266
error := deltaX - deltaY.
257
- x := aStartPoint x.
258
- y := aStartPoint y.
267
+ x := aStartIndex x.
268
+ y := aStartIndex y.
259
269
260
- linePointsCollection := OrderedCollection new .
270
+ lineIndexCollection := OrderedCollection new .
261
271
262
- [
263
- | point |
264
- point := x @ y.
265
- linePointsCollection add: point.
266
- (x = anEndPoint x and : [y = anEndPoint y]) ifTrue: [
267
- ^ linePointsCollection].
272
+ [ index := x @ y.
273
+ lineIndexCollection add: index.
274
+ (x = anEndIndex x and : [y = anEndIndex y]) ifTrue: [^ lineIndexCollection].
268
275
error2 := 2 * error.
269
276
(error2 > (0 - deltaY)) ifTrue: [
270
277
error := error - deltaY.
271
278
x := x + stepX].
272
279
(error2 < deltaX) ifTrue: [
273
280
error := error + deltaX.
274
- y := y + stepY]
275
- ] repeat
281
+ y := y + stepY]] repeat
276
282
277
283
]
278
284
279
285
{
280
- #category : #forms ,
281
- #' squeak_changestamp' : ' JS 7/11 /2024 17:34 '
286
+ #category : #brushes ,
287
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12 /2024 13:57 '
282
288
}
283
289
GMTEBrush >> rectangleBrush [
284
290
291
+ | endCol endRow startCol startRow |
285
292
self resetOutputSet.
286
293
self firstMatrixIndex ifNil: [^ nil ].
287
294
288
- (self currentMatrixIndex x min: self firstMatrixIndex x) to: (self currentMatrixIndex x max: self firstMatrixIndex x) do: [:row |
289
- (self currentMatrixIndex y min: self firstMatrixIndex y) to: (self currentMatrixIndex y max: self firstMatrixIndex y) do: [:col |
290
- self outputSet add: (row @ col)]].
295
+ startRow := (self currentMatrixIndex x min: self firstMatrixIndex x).
296
+ endRow := (self currentMatrixIndex x max: self firstMatrixIndex x).
297
+ startCol := (self currentMatrixIndex y min: self firstMatrixIndex y).
298
+ endCol := (self currentMatrixIndex y max: self firstMatrixIndex y).
299
+
300
+ startRow to: endRow do: [:row |
301
+ startCol to: endCol do: [:col |
302
+ self outputSet add: (row@col)]].
291
303
292
304
^ self outputSet
293
305
294
306
]
295
307
296
308
{
297
- #category : #select ,
309
+ #category : #brushHelper ,
298
310
#' squeak_changestamp' : ' JS 7/11/2024 13:43'
299
311
}
300
312
GMTEBrush >> resetOutputSet [
@@ -337,3 +349,16 @@ GMTEBrush >> selectRectangleBrush [
337
349
338
350
self currentBrush: [self rectangleBrush]
339
351
]
352
+
353
+ {
354
+ #category : #brushHelper ,
355
+ #' squeak_changestamp' : ' Valentin Teutschbein 7/12/2024 13:31'
356
+ }
357
+ GMTEBrush >> tile: aTile equalsTile: anotherTile [
358
+
359
+ | tilesNil tilesSame |
360
+ tilesNil := (aTile isNil) and : [anotherTile isNil].
361
+ tilesSame := (aTile isNil not and : [anotherTile isNil not ]) and : [aTile imageForm bits hash = anotherTile imageForm bits hash].
362
+
363
+ ^ (tilesNil or : [tilesSame])
364
+ ]
0 commit comments