Skip to content

Commit 8f15160

Browse files
committed
Merge origin/tmm-dev into tmm-dev
2 parents ec11500 + efedb74 commit 8f15160

File tree

1 file changed

+80
-76
lines changed

1 file changed

+80
-76
lines changed

source/GM-TE/GMTEBrush.class.st

Lines changed: 80 additions & 76 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'
@@ -129,15 +144,6 @@ GMTEBrush >> initialize [
129144
self resetOutputSet
130145
]
131146

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)
139-
]
140-
141147
{
142148
#category : #accessing,
143149
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:51'
@@ -156,51 +162,32 @@ GMTEBrush >> layer: anObject [
156162

157163
{
158164
#category : #forms,
159-
#'squeak_changestamp' : 'JS 7/11/2024 14:09'
165+
#'squeak_changestamp' : 'JS 7/11/2024 16:16'
160166
}
161167
GMTEBrush >> lineBrush [
162-
| radius collection start end deltaX deltaY stepX stepY error error2 x y offsets |
163-
self flag: 'refactor - do instead of collect or select'.
164-
radius := self radius - 1.
165-
self resetOutputSet.
166-
self flag: 'todo: method extraction'.
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]]].
172168

169+
| offsets |
173170
self resetOutputSet.
174171
(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)]].
175178

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.
179+
^(self outputSet)
185180

186-
collection := OrderedCollection new.
181+
]
187182

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
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"
203189

190+
^ self radius - 1
204191
]
205192

206193
{
@@ -237,56 +224,73 @@ GMTEBrush >> radius: anObject [
237224

238225
{
239226
#category : #forms,
240-
#'squeak_changestamp' : 'JS 7/11/2024 14:06'
227+
#'squeak_changestamp' : 'JS 7/11/2024 16:14'
241228
}
242229
GMTEBrush >> radiusBrush [
243230

244-
| collection xMin xMax yMin yMax |
231+
| offsets |
245232
self currentMatrixIndex ifNil: [^nil].
246233

247-
collection := OrderedCollection new.
248-
self flag: 'radius offset is bad'.
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).
253-
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]]].
234+
offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius.
258235

259-
collection do: [:i |
260-
self outputSet add: i].
236+
offsets do: [:i |
237+
self outputSet add: (self currentMatrixIndex + i)].
261238

262239
^ self outputSet
263240

264241
]
265242

266243
{
267244
#category : #forms,
268-
#'squeak_changestamp' : 'JS 7/11/2024 13:49'
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.
261+
262+
collection := OrderedCollection new.
263+
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
278+
279+
]
280+
281+
{
282+
#category : #forms,
283+
#'squeak_changestamp' : 'JS 7/11/2024 16:29'
269284
}
270285
GMTEBrush >> rectangleBrush [
271286

272-
| collection startRow endRow startCol endCol |
273287
self resetOutputSet.
274288
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
275-
collection := OrderedCollection new.
276289

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-
289-
self outputSet: collection asSet.
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

291295
^ self outputSet
292296

0 commit comments

Comments
 (0)