@@ -12,6 +12,21 @@ Class {
12
12
#category : #' GM-TE-UI'
13
13
}
14
14
15
+ {
16
+ #category : #forms ,
17
+ #' squeak_changestamp' : ' JS 7/11/2024 15:40'
18
+ }
19
+ GMTEBrush >> calculateOffsetsForRadius: aRadius [
20
+
21
+ |offsets |
22
+ offsets := OrderedCollection new .
23
+ (0 - radius to: radius) do: [:dx |
24
+ (0 - radius to: radius) do: [:dy |
25
+ ((dx squared + dy squared) <= aRadius squared) ifTrue: [offsets add: dx @ dy]]].
26
+
27
+ ^ offsets
28
+ ]
29
+
15
30
{
16
31
#category : #accessing ,
17
32
#' squeak_changestamp' : ' Valentin Teutschbein 7/6/2024 12:48'
@@ -46,18 +61,18 @@ GMTEBrush >> currentMatrixIndex: anObject [
46
61
47
62
{
48
63
#category : #' as yet unclassified' ,
49
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 08:47 '
64
+ #' squeak_changestamp' : ' JS 7/11 /2024 13:59 '
50
65
}
51
66
GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
52
67
53
68
self currentMatrixIndex: anIndex.
54
69
self layer: aLayer.
55
- ^ self currentBrush value.
70
+ ^ self currentBrush value
56
71
]
57
72
58
73
{
59
74
#category : #forms ,
60
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 22:04 '
75
+ #' squeak_changestamp' : ' JS 7/11 /2024 14:07 '
61
76
}
62
77
GMTEBrush >> fillBrush [
63
78
@@ -67,27 +82,27 @@ GMTEBrush >> fillBrush [
67
82
68
83
visited := Matrix rows: (self layer rowCount) columns: self layer columnCount.
69
84
collection := OrderedCollection new .
70
- startTile := layer at: self currentMatrixIndex y at: self currentMatrixIndex x.
85
+ startTile := self layer at: self currentMatrixIndex y at: self currentMatrixIndex x.
71
86
72
- collection add: currentMatrixIndex.
87
+ collection add: self currentMatrixIndex.
73
88
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true .
74
89
75
90
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection.
76
91
self outputSet: collection asSet.
77
92
78
- ^ self outputSet.
93
+ ^ self outputSet
79
94
]
80
95
81
96
{
82
97
#category : #forms ,
83
- #' squeak_changestamp' : ' JS 7/6 /2024 16:46 '
98
+ #' squeak_changestamp' : ' JS 7/11 /2024 13:58 '
84
99
}
85
100
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andCollection: aCollection [
86
101
87
102
| borderingOffsets |
88
103
self flag: ' REFACTOR!' .
89
104
borderingOffsets := {(- 1 )@0 . 0 @(- 1 ). 1 @0 . 0 @1 }.
90
- borderingOffsets do: [: offset|
105
+ borderingOffsets do: [:offset |
91
106
| newIndex newTile |
92
107
newIndex := offset + anIndex.
93
108
((self layer inBounds: newIndex) and : [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue: [
@@ -97,10 +112,10 @@ GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile:
97
112
aVisitedMatrix at: newIndex y at: newIndex x put: true .
98
113
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]
99
114
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]]]]
115
+ (newTile isNil not and : [anOriginTile imageForm bits hash = newTile imageForm bits hash]) ifTrue: [
116
+ aCollection add: newIndex.
117
+ aVisitedMatrix at: newIndex y at: newIndex x put: true .
118
+ self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]]
104
119
]
105
120
106
121
{
@@ -121,12 +136,12 @@ GMTEBrush >> firstMatrixIndex: anObject [
121
136
122
137
{
123
138
#category : #forms ,
124
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 21:33 '
139
+ #' squeak_changestamp' : ' JS 7/11 /2024 13:59 '
125
140
}
126
141
GMTEBrush >> initialize [
127
142
128
143
super initialize.
129
- self resetOutputSet.
144
+ self resetOutputSet
130
145
]
131
146
132
147
{
@@ -147,59 +162,34 @@ GMTEBrush >> layer: anObject [
147
162
148
163
{
149
164
#category : #forms ,
150
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 22:53 '
165
+ #' squeak_changestamp' : ' JS 7/11 /2024 16:16 '
151
166
}
152
167
GMTEBrush >> lineBrush [
153
- | radius collection start end deltaX deltaY stepX stepY error error2 x y offsets |
154
168
155
- radius := self radius - 1 .
169
+ | offsets |
156
170
self resetOutputSet.
157
- 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.
171
+ (self currentMatrixIndex isNil or : [self firstMatrixIndex isNil]) ifTrue: [^ nil ].
172
+
173
+ offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius.
174
+
175
+ (self rasterizeLineBetweenAStart: self firstMatrixIndex andAnEnd: self currentMatrixIndex) do: [:point |
176
+ offsets do: [:offset |
177
+ self outputSet add: (point + offset)]].
178
+
179
+ ^ (self outputSet)
200
180
201
181
]
202
182
183
+ {
184
+ #category : #accessing ,
185
+ #' squeak_changestamp' : ' JS 7/11/2024 16:16'
186
+ }
187
+ GMTEBrush >> offsetCorrectedRadius [
188
+ " In order to display a more intuitive radius for the user, we need to offset it by 1 for the calculations"
189
+
190
+ ^ self radius - 1
191
+ ]
192
+
203
193
{
204
194
#category : #accessing ,
205
195
#' squeak_changestamp' : ' Valentin Teutschbein 7/9/2024 21:18'
@@ -234,71 +224,85 @@ GMTEBrush >> radius: anObject [
234
224
235
225
{
236
226
#category : #forms ,
237
- #' squeak_changestamp' : ' Valentin Teutschbein 7/10 /2024 12:37 '
227
+ #' squeak_changestamp' : ' JS 7/11 /2024 16:14 '
238
228
}
239
229
GMTEBrush >> radiusBrush [
240
230
241
- | collection xMin xMax yMin yMax |
242
- self currentMatrixIndex ifNil: [^ nil ].
231
+ | offsets |
232
+ self currentMatrixIndex ifNil: [^ nil ].
233
+
234
+ offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius.
243
235
244
- collection := OrderedCollection new .
245
- 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 ).
236
+ offsets do: [:i |
237
+ self outputSet add: (self currentMatrixIndex + i)].
250
238
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
- ].
239
+ ^ self outputSet
240
+
241
+ ]
242
+
243
+ {
244
+ #category : #forms ,
245
+ #' squeak_changestamp' : ' JS 7/11/2024 16:16'
246
+ }
247
+ GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [
248
+ " implementation of Bresenhams Line Algorithm"
249
+
250
+ | collection deltaX deltaY stepX stepY error error2 x y |
251
+
252
+ self flag: ' todo: method extraction? - Ich glaube geht schlecht' .
253
+
254
+ deltaX := (anEndPoint x - aStartPoint x) abs.
255
+ deltaY := (anEndPoint y - aStartPoint y) abs.
256
+ stepX := (aStartPoint x < anEndPoint x) ifTrue: [1 ] ifFalse: [- 1 ].
257
+ stepY := (aStartPoint y < anEndPoint y) ifTrue: [1 ] ifFalse: [- 1 ].
258
+ error := deltaX - deltaY.
259
+ x := aStartPoint x.
260
+ y := aStartPoint y.
258
261
259
- collection do: [ :i | self outputSet add: i] .
262
+ collection := OrderedCollection new .
260
263
261
- ^ self outputSet.
264
+ [
265
+ | point |
266
+ point := x @ y.
267
+ collection add: point.
268
+ (x = anEndPoint x and : [y = anEndPoint y]) ifTrue: [
269
+ ^ collection].
270
+ error2 := 2 * error.
271
+ (error2 > (0 - deltaY)) ifTrue: [
272
+ error := error - deltaY.
273
+ x := x + stepX].
274
+ (error2 < deltaX) ifTrue: [
275
+ error := error + deltaX.
276
+ y := y + stepY]
277
+ ] repeat
262
278
263
279
]
264
280
265
281
{
266
282
#category : #forms ,
267
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 22:04 '
283
+ #' squeak_changestamp' : ' JS 7/11 /2024 16:29 '
268
284
}
269
285
GMTEBrush >> rectangleBrush [
270
286
271
- | collection startRow endRow startCol endCol |
272
287
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
- ].
289
- self outputSet: collection asSet.
288
+ (self currentMatrixIndex isNil or : [self firstMatrixIndex isNil]) ifTrue: [^ nil ].
289
+
290
+ self flag: ' besser machen?' .
291
+ (self currentMatrixIndex x min: self firstMatrixIndex x) to: (self currentMatrixIndex x max: self firstMatrixIndex x) do: [:row |
292
+ (self currentMatrixIndex y min: self firstMatrixIndex y) to: (self currentMatrixIndex y max: self firstMatrixIndex y) do: [:col |
293
+ self outputSet add: (row @ col)]].
290
294
291
- ^ self outputSet.
295
+ ^ self outputSet
292
296
293
297
]
294
298
295
299
{
296
300
#category : #select ,
297
- #' squeak_changestamp' : ' Valentin Teutschbein 7/9 /2024 21:26 '
301
+ #' squeak_changestamp' : ' JS 7/11 /2024 13:43 '
298
302
}
299
303
GMTEBrush >> resetOutputSet [
300
304
301
- self outputSet: Set new .
305
+ self outputSet: Set new
302
306
]
303
307
304
308
{
0 commit comments