Skip to content

Commit

Permalink
AePixelComparison: Split method in 3
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchodias committed Jul 28, 2023
1 parent d9e79c5 commit 2cfb3a0
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions src/Alexandrie-Base-Tests/AePixelComparison.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,11 @@ AePixelComparison >> actualVsExpectedMergedDiffForm [
actualDiffForm := Form extent: actualForm extent depth: actualForm depth.
expectedDiffForm := Form extent: expectedForm extent depth: expectedForm depth.

1 to: (actualForm width min: expectedForm width) do: [ :x |
1 to: (actualForm height min: expectedForm height) do: [ :y |

| currentPoint actualColor expectedColor |
currentPoint := x@y - (1@1). "Weird: forms are 0-indexed"
actualColor := actualForm colorAt: currentPoint.
expectedColor := expectedForm colorAt: currentPoint.
actualColor = expectedColor ifFalse: [
actualDiffForm colorAt: currentPoint put: actualColor.
expectedDiffForm colorAt: currentPoint put: expectedColor ]

] ].
self mismatchingPixelsDo: [ :currentPoint :actualColor :expectedColor |
actualDiffForm colorAt: currentPoint put: actualColor.
expectedDiffForm colorAt: currentPoint put: expectedColor ].

^ self concatenatedForm: actualDiffForm and: expectedDiffForm

]

{ #category : #'accessing diff' }
Expand Down Expand Up @@ -95,6 +85,18 @@ AePixelComparison >> expectedForm: aForm [
expectedForm := aForm
]

{ #category : #'accessing diff' }
AePixelComparison >> intersectionHeight [

^ actualForm height min: expectedForm height
]

{ #category : #'accessing diff' }
AePixelComparison >> intersectionWidth [

^ actualForm width min: expectedForm width
]

{ #category : #testing }
AePixelComparison >> isMatch [

Expand All @@ -117,6 +119,28 @@ AePixelComparison >> label: aString [
label := aString
]

{ #category : #'accessing diff' }
AePixelComparison >> mismatchingPixelsDo: aBlock [
"For each mismatching pixel (in the intersecting area), evaluate a block with the following arguments:
* 0-indexed points Note: forms are 0-indexed
* the actual color
* the expected color"

0 to: self intersectionWidth - 1 do: [ :x |
0 to: self intersectionHeight - 1 do: [ :y |

| currentPoint actualColor expectedColor |
currentPoint := x@y.
actualColor := actualForm colorAt: currentPoint.
expectedColor := expectedForm colorAt: currentPoint.

actualColor = expectedColor ifFalse: [
aBlock
value: currentPoint
value: actualColor
value: expectedColor ] ] ]
]

{ #category : #printing }
AePixelComparison >> printOn: aStream [

Expand Down

0 comments on commit 2cfb3a0

Please sign in to comment.