Skip to content

Commit d74333d

Browse files
committed
minor codestyle fixes for brushes
1 parent 4485bff commit d74333d

File tree

2 files changed

+109
-110
lines changed

2 files changed

+109
-110
lines changed

source/GM-TE/GMTEBrush.class.st

Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ GMTEBrush >> currentMatrixIndex: anObject [
4646

4747
{
4848
#category : #'as yet unclassified',
49-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:47'
49+
#'squeak_changestamp' : 'JS 7/11/2024 13:59'
5050
}
5151
GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
5252

5353
self currentMatrixIndex: anIndex.
5454
self layer: aLayer.
55-
^ self currentBrush value.
55+
^ self currentBrush value
5656
]
5757

5858
{
5959
#category : #forms,
60-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04'
60+
#'squeak_changestamp' : 'JS 7/11/2024 14:07'
6161
}
6262
GMTEBrush >> fillBrush [
6363

@@ -67,27 +67,27 @@ GMTEBrush >> fillBrush [
6767

6868
visited := Matrix rows: (self layer rowCount) columns: self layer columnCount.
6969
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.
7171

72-
collection add: currentMatrixIndex.
72+
collection add: self currentMatrixIndex.
7373
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true.
7474

7575
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection.
7676
self outputSet: collection asSet.
7777

78-
^ self outputSet.
78+
^ self outputSet
7979
]
8080

8181
{
8282
#category : #forms,
83-
#'squeak_changestamp' : 'JS 7/6/2024 16:46'
83+
#'squeak_changestamp' : 'JS 7/11/2024 13:58'
8484
}
8585
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andCollection: aCollection [
8686

8787
| borderingOffsets |
8888
self flag: 'REFACTOR!'.
8989
borderingOffsets := {(-1)@0. 0@(-1). 1@0. 0@1}.
90-
borderingOffsets do: [: offset|
90+
borderingOffsets do: [:offset |
9191
| newIndex newTile |
9292
newIndex := offset + anIndex.
9393
((self layer inBounds: newIndex) and: [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue:[
@@ -97,10 +97,10 @@ GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile:
9797
aVisitedMatrix at: newIndex y at: newIndex x put: true.
9898
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]
9999
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]]]]
104104
]
105105

106106
{
@@ -121,12 +121,21 @@ GMTEBrush >> firstMatrixIndex: anObject [
121121

122122
{
123123
#category : #forms,
124-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:33'
124+
#'squeak_changestamp' : 'JS 7/11/2024 13:59'
125125
}
126126
GMTEBrush >> initialize [
127127

128128
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)
130139
]
131140

132141
{
@@ -147,56 +156,50 @@ GMTEBrush >> layer: anObject [
147156

148157
{
149158
#category : #forms,
150-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:53'
159+
#'squeak_changestamp' : 'JS 7/11/2024 14:09'
151160
}
152161
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'.
155164
radius := self radius - 1.
156165
self resetOutputSet.
157166
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
200203

201204
]
202205

@@ -234,71 +237,68 @@ GMTEBrush >> radius: anObject [
234237

235238
{
236239
#category : #forms,
237-
#'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 12:37'
240+
#'squeak_changestamp' : 'JS 7/11/2024 14:06'
238241
}
239242
GMTEBrush >> radiusBrush [
240243

241-
| collection xMin xMax yMin yMax |
242-
self currentMatrixIndex ifNil: [^nil].
244+
| collection xMin xMax yMin yMax |
245+
self currentMatrixIndex ifNil: [^nil].
243246

244-
collection := OrderedCollection new.
247+
collection := OrderedCollection new.
245248
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).
250253

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]]].
258258

259-
collection do: [:i | self outputSet add: i].
259+
collection do: [:i |
260+
self outputSet add: i].
260261

261-
^ self outputSet.
262+
^ self outputSet
262263

263264
]
264265

265266
{
266267
#category : #forms,
267-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04'
268+
#'squeak_changestamp' : 'JS 7/11/2024 13:49'
268269
}
269270
GMTEBrush >> rectangleBrush [
270271

271-
| collection startRow endRow startCol endCol |
272+
| collection startRow endRow startCol endCol |
272273
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+
289289
self outputSet: collection asSet.
290290

291-
^ self outputSet.
291+
^ self outputSet
292292

293293
]
294294

295295
{
296296
#category : #select,
297-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:26'
297+
#'squeak_changestamp' : 'JS 7/11/2024 13:43'
298298
}
299299
GMTEBrush >> resetOutputSet [
300300

301-
self outputSet: Set new.
301+
self outputSet: Set new
302302
]
303303

304304
{

source/GM-TE/GMTEEditorTileMap.class.st

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,25 @@ GMTEEditorTileMap >> model: anObject [
113113

114114
{
115115
#category : #'event handling',
116-
#'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:07'
116+
#'squeak_changestamp' : 'JS 7/11/2024 14:13'
117117
}
118118
GMTEEditorTileMap >> mouseDown: anEvent [
119119
"Implements placement of tiles"
120120

121-
| selectedCoordinates activeLayer selectedIndex |
121+
| selectedIndex |
122122
self flag: 'refactor; method extraction for "Add tiles to layer" to minimize redundancy with mouseMove?'.
123123
self model singleLayerSelected ifFalse: [^nil].
124-
activeLayer := self model selectedLayers anyOne.
125124
selectedIndex := self tileIndexFromPosition: anEvent position.
126125
self model brush firstMatrixIndex: selectedIndex.
127-
selectedCoordinates := self model brush executeWithMatrixIndex: selectedIndex andLayer: (self tileMatrixStack layer: activeLayer).
126+
self model brush executeWithMatrixIndex: selectedIndex andLayer: (self tileMatrixStack layer: self model selectedLayers anyOne).
128127
anEvent yellowButtonPressed ifTrue: [self tileSelectionSet highlightImage: nil].
129128

130129
^ true
131130
]
132131

133132
{
134133
#category : #'event handling',
135-
#'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:06'
134+
#'squeak_changestamp' : 'JS 7/11/2024 14:01'
136135
}
137136
GMTEEditorTileMap >> mouseMove: anEvent [
138137
"Implements highlighting of tiles when hovering"
@@ -149,12 +148,12 @@ GMTEEditorTileMap >> mouseMove: anEvent [
149148

150149
(selectedCoordinates select: [:c | (self tileMatrixStack layer: activeLayer) inBounds: c]) do: [:t|
151150
hoveredTileHighlighting := self highlightingTileFromIndex: t.
152-
hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]].
151+
hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]]
153152
]
154153

155154
{
156155
#category : #'event handling',
157-
#'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:11'
156+
#'squeak_changestamp' : 'JS 7/11/2024 14:11'
158157
}
159158
GMTEEditorTileMap >> mouseUp: anEvent [
160159

@@ -164,8 +163,8 @@ GMTEEditorTileMap >> mouseUp: anEvent [
164163
activeLayer := self model selectedLayers anyOne.
165164
self updateTiles: (indicesToAdd asCollection) inLayer: activeLayer FromEvent: anEvent.
166165
self model brush resetOutputSet.
167-
(self previousTileStates size > 0) ifTrue: [self saveTileEditChanges].
168-
self tileSelectionSet highlightImage: (self model selectedTile).
166+
(self previousTileStates isEmpty) ifFalse: [self saveTileEditChanges].
167+
self tileSelectionSet highlightImage: (self model selectedTile)
169168
]
170169

171170
{
@@ -284,12 +283,12 @@ GMTEEditorTileMap >> savePreviousImageFromPosition: aPosition inLayer: aLayer [
284283

285284
{
286285
#category : #'command processing',
287-
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 11:52'
286+
#'squeak_changestamp' : 'JS 7/11/2024 14:07'
288287
}
289288
GMTEEditorTileMap >> saveTileEditChanges [
290289

291290
self
292-
model addCommand: (GMTEEditTilesCommand previousTiles: previousTileStates currentTiles: currentTileChanges tilemap: self).
291+
model addCommand: (GMTEEditTilesCommand previousTiles: self previousTileStates currentTiles: self currentTileChanges tilemap: self).
293292
self resetTileEditChanges.
294293
]
295294

@@ -323,12 +322,12 @@ GMTEEditorTileMap >> updateTileSprite: aTile [
323322

324323
{
325324
#category : #updating,
326-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:07'
325+
#'squeak_changestamp' : 'JS 7/11/2024 14:01'
327326
}
328327
GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEvent: anEvent [
329328
"Add currently selected tile (model) to editable matrix stack at mouse position"
330329
| tile |
331-
self flag: 'saveNewImage confict with alex fix?'.
330+
self flag: 'refactor'.
332331
(self tileIndexFromPosition: anEvent position) ifNil: [^ nil].
333332
(anEvent redButtonChanged and: [self model selectedTile notNil])
334333
ifTrue: [

0 commit comments

Comments
 (0)