Skip to content

Commit 113bd39

Browse files
author
Joshua Storost
committed
Merge origin/tmm-dev into tmm-dev
2 parents eb9f8eb + 5c9b3d7 commit 113bd39

File tree

2 files changed

+137
-146
lines changed

2 files changed

+137
-146
lines changed

source/GM-TE/GMTEBrush.class.st

Lines changed: 104 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
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+
"
14
Class {
25
#name : #GMTEBrush,
36
#superclass : #Object,
@@ -9,7 +12,8 @@ Class {
912
'firstMatrixIndex',
1013
'outputSet'
1114
],
12-
#category : #'GM-TE-UI'
15+
#category : #'GM-TE-UI',
16+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:49'
1317
}
1418

1519
{
@@ -22,54 +26,58 @@ GMTEBrush class >> borderingOffsets [
2226
]
2327

2428
{
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'
2731
}
2832
GMTEBrush >> calculateOffsetsForRadius: aRadius [
2933

3034
|offsets|
3135
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 |
3438
((dx squared + dy squared) <= aRadius squared) ifTrue: [offsets add: dx @ dy]]].
3539

36-
^offsets
40+
^ offsets
3741
]
3842

3943
{
4044
#category : #accessing,
41-
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
45+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:40'
4246
}
4347
GMTEBrush >> currentBrush [
48+
4449
^ currentBrush
4550
]
4651

4752
{
4853
#category : #accessing,
49-
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
54+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:40'
5055
}
51-
GMTEBrush >> currentBrush: anObject [
52-
currentBrush := anObject
56+
GMTEBrush >> currentBrush: aBrush [
57+
58+
currentBrush := aBrush
5359
]
5460

5561
{
5662
#category : #accessing,
57-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:47'
63+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:41'
5864
}
5965
GMTEBrush >> currentMatrixIndex [
66+
6067
^ currentMatrixIndex
6168
]
6269

6370
{
6471
#category : #accessing,
65-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:47'
72+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:41'
6673
}
67-
GMTEBrush >> currentMatrixIndex: anObject [
68-
currentMatrixIndex := anObject
74+
GMTEBrush >> currentMatrixIndex: anIndex [
75+
76+
currentMatrixIndex := anIndex
6977
]
7078

7179
{
72-
#category : #'as yet unclassified',
80+
#category : #execute,
7381
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:10'
7482
}
7583
GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
@@ -81,8 +89,8 @@ GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
8189
]
8290

8391
{
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'
8694
}
8795
GMTEBrush >> fillBrush [
8896

@@ -95,51 +103,49 @@ GMTEBrush >> fillBrush [
95103
self outputSet add: self currentMatrixIndex.
96104
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true.
97105

98-
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andSet: self outputSet.
106+
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile.
99107

100108
^ self outputSet
101109
]
102110

103111
{
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'
106114
}
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 |
110118
GMTEBrush borderingOffsets do: [:offset |
111-
| newIndex newTile tilesNil tilesSame |
112119
newIndex := offset + anIndex.
113120
((self layer inBounds: newIndex) and: [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue:[
114121
newTile := self layer at: newIndex y at: newIndex x.
115122

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.
121125
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]]]
123127
]
124128

125129
{
126130
#category : #accessing,
127-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:49'
131+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:41'
128132
}
129133
GMTEBrush >> firstMatrixIndex [
134+
130135
^ firstMatrixIndex
131136
]
132137

133138
{
134139
#category : #accessing,
135-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:49'
140+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:42'
136141
}
137-
GMTEBrush >> firstMatrixIndex: anObject [
138-
firstMatrixIndex := anObject
142+
GMTEBrush >> firstMatrixIndex: anIndex [
143+
144+
firstMatrixIndex := anIndex
139145
]
140146

141147
{
142-
#category : #forms,
148+
#category : #initialization,
143149
#'squeak_changestamp' : 'JS 7/11/2024 13:59'
144150
}
145151
GMTEBrush >> initialize [
@@ -150,34 +156,36 @@ GMTEBrush >> initialize [
150156

151157
{
152158
#category : #accessing,
153-
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:51'
159+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:42'
154160
}
155161
GMTEBrush >> layer [
162+
156163
^ layer
157164
]
158165

159166
{
160167
#category : #accessing,
161-
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:51'
168+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:42'
162169
}
163-
GMTEBrush >> layer: anObject [
164-
layer := anObject
170+
GMTEBrush >> layer: aLayer [
171+
172+
layer := aLayer
165173
]
166174

167175
{
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'
170178
}
171179
GMTEBrush >> lineBrush [
172180

173181
self resetOutputSet.
174-
self firstMatrixIndex ifNil: [^nil].
182+
self firstMatrixIndex ifNil: [^ nil].
175183

176-
(self rasterizeLineBetweenAStart: self firstMatrixIndex andAnEnd: self currentMatrixIndex) do: [:point |
184+
(self rasterizeLineBetweenStart: self firstMatrixIndex andEnd: self currentMatrixIndex) do: [:index |
177185
(self calculateOffsetsForRadius: self offsetCorrectedRadius) do: [:offset |
178-
self outputSet add: (point + offset)]].
186+
self outputSet add: (index + offset)]].
179187

180-
^(self outputSet)
188+
^ self outputSet
181189

182190
]
183191

@@ -193,18 +201,20 @@ GMTEBrush >> offsetCorrectedRadius [
193201

194202
{
195203
#category : #accessing,
196-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:18'
204+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:43'
197205
}
198206
GMTEBrush >> outputSet [
207+
199208
^ outputSet
200209
]
201210

202211
{
203212
#category : #accessing,
204-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:18'
213+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:43'
205214
}
206-
GMTEBrush >> outputSet: anObject [
207-
outputSet := anObject
215+
GMTEBrush >> outputSet: aSet [
216+
217+
outputSet := aSet
208218
]
209219

210220
{
@@ -218,15 +228,15 @@ GMTEBrush >> radius [
218228

219229
{
220230
#category : #accessing,
221-
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:15'
231+
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:43'
222232
}
223-
GMTEBrush >> radius: aNumber [
233+
GMTEBrush >> radius: aRadius [
224234

225-
radius := aNumber
235+
radius := aRadius
226236
]
227237

228238
{
229-
#category : #forms,
239+
#category : #brushes,
230240
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:09'
231241
}
232242
GMTEBrush >> radiusBrush [
@@ -239,62 +249,64 @@ GMTEBrush >> radiusBrush [
239249
]
240250

241251
{
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'
244254
}
245-
GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [
255+
GMTEBrush >> rasterizeLineBetweenStart: aStartIndex andEnd: anEndIndex [
246256
"implementation of Bresenhams Line Algorithm"
247257

248-
| linePointsCollection deltaX deltaY stepX stepY error error2 x y |
258+
| lineIndexCollection deltaX deltaY stepX stepY error error2 x y index |
249259

250-
self flag: 'todo: method extraction? - Ich glaube geht schlecht'.
260+
self flag: 'repeat formatting'.
251261

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].
256266
error := deltaX - deltaY.
257-
x := aStartPoint x.
258-
y := aStartPoint y.
267+
x := aStartIndex x.
268+
y := aStartIndex y.
259269

260-
linePointsCollection := OrderedCollection new.
270+
lineIndexCollection := OrderedCollection new.
261271

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].
268275
error2 := 2 * error.
269276
(error2 > (0 - deltaY)) ifTrue: [
270277
error := error - deltaY.
271278
x := x + stepX].
272279
(error2 < deltaX) ifTrue: [
273280
error := error + deltaX.
274-
y := y + stepY]
275-
] repeat
281+
y := y + stepY]] repeat
276282

277283
]
278284

279285
{
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'
282288
}
283289
GMTEBrush >> rectangleBrush [
284290

291+
| endCol endRow startCol startRow |
285292
self resetOutputSet.
286293
self firstMatrixIndex ifNil: [^ nil].
287294

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)]].
291303

292304
^ self outputSet
293305

294306
]
295307

296308
{
297-
#category : #select,
309+
#category : #brushHelper,
298310
#'squeak_changestamp' : 'JS 7/11/2024 13:43'
299311
}
300312
GMTEBrush >> resetOutputSet [
@@ -337,3 +349,16 @@ GMTEBrush >> selectRectangleBrush [
337349

338350
self currentBrush: [self rectangleBrush]
339351
]
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

Comments
 (0)