pharo-graphics / Alexandrie

FFI bindings and a 2D canvas for Pharo based on Cairo, Freetype and Harfbuzz
MIT License
5 stars 2 forks source link

deadcode in renderBackgroundAlpha: backgroundAlpha hasBorder: hasBorder outskirtsSelector: outskirtsSelector #59

Closed Ducasse closed 6 months ago

Ducasse commented 6 months ago
renderBackgroundAlpha: backgroundAlpha hasBorder: hasBorder outskirtsSelector: outskirtsSelector

    | aeCanvas drawFigureBlock referenceExtent |
    referenceExtent := 50 asPoint.
    aeCanvas := AeCanvas extent: referenceExtent.
    aeCanvas clear: Color yellow.

    drawFigureBlock := [ :depth |

        aeCanvas restoreContextAfter: [ 

            aeCanvas
                pathTranslate: referenceExtent / -10;
                pathScale: 0.75 asPoint.

            aeCanvas pathFactory: [ :cairoContext |
                cairoContext circleRadius: referenceExtent x / 2 ].

            aeCanvas
                setBackgroundWith: [
                    aeCanvas setSourceColor: 
                        (depth odd
                            ifTrue: [ Color green ]
                            ifFalse: [ Color red ]) ]
                alpha: backgroundAlpha.

            hasBorder
                ifTrue: [ 
                    aeCanvas setBorderBlock: [
                        aeCanvas
                            setSourceColor: Color black;
                            "setCapButt; setJoinRound;
                                --> Redundant: both are defaults"
                            setBorderWidth: referenceExtent x / 10 ].
                    aeCanvas perform: outskirtsSelector ]
                ifFalse: [ aeCanvas setBorderOff ].

            aeCanvas drawFigureAndPrepareToClip: depth odd.

            depth > 0 ifTrue: [
                drawFigureBlock value: depth-1 ] ] ].

    "Move to initial position and draw with depth=2"
    aeCanvas pathTranslate: referenceExtent / 4.
    drawFigureBlock value: 2.

    ^ aeCanvas
Ducasse commented 6 months ago
depth > 0 ifTrue: [
                drawFigureBlock value: depth-1 ] ] ].

drawFigureBlock is not defined nor set

tinchodias commented 6 months ago

Hello: I am re-writing it to be less cryptic... This is a static analysis warning, but on execution the variable is defined (kind of recursive a block closure).

It's what generates this variants: image

tinchodias commented 6 months ago

(source of the image: https://pharoweekly.wordpress.com/2022/11/14/bloc-update/)

tinchodias commented 6 months ago

Fixed by https://github.com/pharo-graphics/Alexandrie/commit/5e542fedb8357a5786b4963bc38e0391cc2c8b9a

tinchodias commented 6 months ago

(only in dev for the moment)