Skip to content

Commit c73751a

Browse files
author
Ivo Zilkenat
committed
Merge origin/tmm-dev into tmm-dev
2 parents af9212d + efedb74 commit c73751a

7 files changed

+204
-224
lines changed

source/GM-TE/GMTEBrush.class.st

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

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+
1530
{
1631
#category : #accessing,
1732
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
@@ -46,18 +61,18 @@ GMTEBrush >> currentMatrixIndex: anObject [
4661

4762
{
4863
#category : #'as yet unclassified',
49-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:47'
64+
#'squeak_changestamp' : 'JS 7/11/2024 13:59'
5065
}
5166
GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
5267

5368
self currentMatrixIndex: anIndex.
5469
self layer: aLayer.
55-
^ self currentBrush value.
70+
^ self currentBrush value
5671
]
5772

5873
{
5974
#category : #forms,
60-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04'
75+
#'squeak_changestamp' : 'JS 7/11/2024 14:07'
6176
}
6277
GMTEBrush >> fillBrush [
6378

@@ -67,27 +82,27 @@ GMTEBrush >> fillBrush [
6782

6883
visited := Matrix rows: (self layer rowCount) columns: self layer columnCount.
6984
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.
7186

72-
collection add: currentMatrixIndex.
87+
collection add: self currentMatrixIndex.
7388
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true.
7489

7590
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection.
7691
self outputSet: collection asSet.
7792

78-
^ self outputSet.
93+
^ self outputSet
7994
]
8095

8196
{
8297
#category : #forms,
83-
#'squeak_changestamp' : 'JS 7/6/2024 16:46'
98+
#'squeak_changestamp' : 'JS 7/11/2024 13:58'
8499
}
85100
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andCollection: aCollection [
86101

87102
| borderingOffsets |
88103
self flag: 'REFACTOR!'.
89104
borderingOffsets := {(-1)@0. 0@(-1). 1@0. 0@1}.
90-
borderingOffsets do: [: offset|
105+
borderingOffsets do: [:offset |
91106
| newIndex newTile |
92107
newIndex := offset + anIndex.
93108
((self layer inBounds: newIndex) and: [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue:[
@@ -97,10 +112,10 @@ GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile:
97112
aVisitedMatrix at: newIndex y at: newIndex x put: true.
98113
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]
99114
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]]]]
104119
]
105120

106121
{
@@ -121,12 +136,12 @@ GMTEBrush >> firstMatrixIndex: anObject [
121136

122137
{
123138
#category : #forms,
124-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:33'
139+
#'squeak_changestamp' : 'JS 7/11/2024 13:59'
125140
}
126141
GMTEBrush >> initialize [
127142

128143
super initialize.
129-
self resetOutputSet.
144+
self resetOutputSet
130145
]
131146

132147
{
@@ -147,59 +162,34 @@ GMTEBrush >> layer: anObject [
147162

148163
{
149164
#category : #forms,
150-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:53'
165+
#'squeak_changestamp' : 'JS 7/11/2024 16:16'
151166
}
152167
GMTEBrush >> lineBrush [
153-
| radius collection start end deltaX deltaY stepX stepY error error2 x y offsets |
154168

155-
radius := self radius - 1.
169+
| offsets |
156170
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)
200180

201181
]
202182

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+
203193
{
204194
#category : #accessing,
205195
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:18'
@@ -234,71 +224,85 @@ GMTEBrush >> radius: anObject [
234224

235225
{
236226
#category : #forms,
237-
#'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 12:37'
227+
#'squeak_changestamp' : 'JS 7/11/2024 16:14'
238228
}
239229
GMTEBrush >> radiusBrush [
240230

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.
243235

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

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.
258261

259-
collection do: [:i | self outputSet add: i].
262+
collection := OrderedCollection new.
260263

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
262278

263279
]
264280

265281
{
266282
#category : #forms,
267-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04'
283+
#'squeak_changestamp' : 'JS 7/11/2024 16:29'
268284
}
269285
GMTEBrush >> rectangleBrush [
270286

271-
| collection startRow endRow startCol endCol |
272287
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)]].
290294

291-
^ self outputSet.
295+
^ self outputSet
292296

293297
]
294298

295299
{
296300
#category : #select,
297-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:26'
301+
#'squeak_changestamp' : 'JS 7/11/2024 13:43'
298302
}
299303
GMTEBrush >> resetOutputSet [
300304

301-
self outputSet: Set new.
305+
self outputSet: Set new
302306
]
303307

304308
{

source/GM-TE/GMTEDeleteLayersCommand.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Class {
22
#name : #GMTEDeleteLayersCommand,
3-
#superclass : #GMTETilemapSizeCommand,
3+
#superclass : #GMTEEditTilesCommand,
44
#instVars : [
55
'layers'
66
],

0 commit comments

Comments
 (0)