Program in Smalltalk


' Smalltalk class to constraint a 2D point to a fixed grid
' 

Point subclass: #GriddedPoint
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Exercise11.5'!


!GriddedPoint methodsFor: 'accessing'!

x: xInteger 
        "Set the x coordinate gridded to 10 (using rounding, alternatively I could 
        use truncating)."

        super x: (xInteger roundTo: 10)!

y: yInteger 
        "Set the y coordinate gridded to 10 (using rounding, alternatively I could 
        use truncating)."

        super y: (yInteger roundTo: 10)! !

!GriddedPoint methodsFor: 'private'!

setX: xPoint setY: yPoint 
        "Initialize the instance variables rounding to 10."
        
        super setX: (xPoint roundTo: 10) setY: (yPoint roundTo: 10)! !

Back: 1951-1970