If point lies outside rectangle `r`, return the nearest point on the boundary of rect `r`, otherwise return point itself. (see Squeak Smalltalk, Point>>adhereTo:)
function(r) {
	    if (r.containsPoint(this)){
	        return this;
	    }
	    this.x = mmin(mmax(this.x, r.x), r.x + r.width);
	    this.y = mmin(mmax(this.y, r.y), r.y + r.height);
	    return this;
        }