Is point within a rectangle

I came up with this neat function to check if a point [x,y] is within a rectangle [x, y, width, height].

It´s made in Javascript but can be applied to ALL languages.

// Comment
Utils.pointWithinRect = function(point, rect) {
var px = point[0];
var py = point[1];
var top = rect.y;
var left = rect.x;
var bottom = rect.y + rect.height;
var right = rect.x + rect.width;
return (px >= left && px = top && py <= bottom);
}

About Anthon Fredriksson

2013 Programming