Skip to content

Commit

Permalink
brush refactoring ...
Browse files Browse the repository at this point in the history
  • Loading branch information
valteu committed Jul 11, 2024
1 parent efedb74 commit 449925e
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions source/GM-TE/GMTEBrush.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ Class {
#category : #'GM-TE-UI'
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:01'
}
GMTEBrush class >> borderingOffsets [

^ {(-1)@0. 0@(-1). 1@0. 0@1}
]

{
#category : #forms,
#'squeak_changestamp' : 'JS 7/11/2024 15:40'
Expand Down Expand Up @@ -61,61 +70,57 @@ GMTEBrush >> currentMatrixIndex: anObject [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JS 7/11/2024 13:59'
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:10'
}
GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [

anIndex ifNil: [^ nil].
self currentMatrixIndex: anIndex.
self layer: aLayer.
^ self currentBrush value
]

{
#category : #forms,
#'squeak_changestamp' : 'JS 7/11/2024 14:07'
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:10'
}
GMTEBrush >> fillBrush [

| collection startTile visited |
| startTile visited |
self resetOutputSet.
self currentMatrixIndex ifNil: [^nil].

visited := Matrix rows: (self layer rowCount) columns: self layer columnCount.
collection := OrderedCollection new.
startTile := self layer at: self currentMatrixIndex y at: self currentMatrixIndex x.

collection add: self currentMatrixIndex.
self outputSet add: self currentMatrixIndex.
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true.

self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection.
self outputSet: collection asSet.
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andSet: self outputSet.

^ self outputSet
]

{
#category : #forms,
#'squeak_changestamp' : 'JS 7/11/2024 13:58'
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:05'
}
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andCollection: aCollection [
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andSet: aSet [

| borderingOffsets |
self flag: 'REFACTOR!'.
borderingOffsets := {(-1)@0. 0@(-1). 1@0. 0@1}.
borderingOffsets do: [:offset |
GMTEBrush borderingOffsets do: [:offset |
| newIndex newTile |
newIndex := offset + anIndex.
((self layer inBounds: newIndex) and: [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue:[
newTile := self layer at: newIndex y at: newIndex x.
anOriginTile
ifNil: [newTile ifNil: [aCollection add: newIndex.
ifNil: [newTile ifNil: [aSet add: newIndex.
aVisitedMatrix at: newIndex y at: newIndex x put: true.
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andSet: aSet]]
ifNotNil: [
(newTile isNil not and: [anOriginTile imageForm bits hash = newTile imageForm bits hash]) ifTrue: [
aCollection add: newIndex.
aSet add: newIndex.
aVisitedMatrix at: newIndex y at: newIndex x put: true.
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]]
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andSet: aSet]]]]
]

{
Expand Down Expand Up @@ -162,18 +167,15 @@ GMTEBrush >> layer: anObject [

{
#category : #forms,
#'squeak_changestamp' : 'JS 7/11/2024 16:16'
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:11'
}
GMTEBrush >> lineBrush [

| offsets |
self resetOutputSet.
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].

offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius.

self firstMatrixIndex ifNil: [^nil].

(self rasterizeLineBetweenAStart: self firstMatrixIndex andAnEnd: self currentMatrixIndex) do: [:point |
offsets do: [:offset |
(self calculateOffsetsForRadius: self offsetCorrectedRadius) do: [:offset |
self outputSet add: (point + offset)]].

^(self outputSet)
Expand Down Expand Up @@ -208,32 +210,29 @@ GMTEBrush >> outputSet: anObject [

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:11'
}
GMTEBrush >> radius [

^ radius
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:08'
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:15'
}
GMTEBrush >> radius: anObject [
radius := anObject
GMTEBrush >> radius: aNumber [

radius := aNumber
]

{
#category : #forms,
#'squeak_changestamp' : 'JS 7/11/2024 16:14'
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:09'
}
GMTEBrush >> radiusBrush [

| offsets |
self currentMatrixIndex ifNil: [^nil].

offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius.

offsets do: [:i |
(self calculateOffsetsForRadius: self offsetCorrectedRadius) do: [:i |
self outputSet add: (self currentMatrixIndex + i)].

^ self outputSet
Expand Down Expand Up @@ -280,12 +279,12 @@ GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [

{
#category : #forms,
#'squeak_changestamp' : 'JS 7/11/2024 16:29'
#'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:09'
}
GMTEBrush >> rectangleBrush [

self resetOutputSet.
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
self firstMatrixIndex ifNil: [^ nil].

self flag: 'besser machen?'.
(self currentMatrixIndex x min: self firstMatrixIndex x) to: (self currentMatrixIndex x max: self firstMatrixIndex x) do: [:row |
Expand Down

0 comments on commit 449925e

Please sign in to comment.