Checking if an xy position is within a rectangular bounds This is pretty straightforward, but is there a better way to do this?

function isWithinBounds(obj, pos) {
    var oXmin, oXmax, oYmin, oYmax;
    if (obj.startPos.x &lt; obj.endPos.x) {
        oXmin = obj.startPos.x;
        oXmax = obj.endPos.x;
    }
    else {
        oXmin = obj.endPos.x;
        oXmax = obj.startPos.x
    }

    if (obj.startPos.y &lt; obj.endPos.y) {
        oYmin = obj.startPos.y;
        oYmax = obj.endPos.y;
    }
    else {
        oYmin = obj.endPos.y;
        oYmax = obj.startPos.y;
    }

    return (pos.x &gt; oXmin &amp;&amp; pos.x &lt; oXmax &amp;&amp; pos.y &gt; oYmin &amp;&amp; pos.y &lt; oYmax);

}
There is. You can use Math.min and Math.max to determine which is the smaller end and the larger end. This way, you avoid the if statements.

function isWithinBounds(obj, pos) {
    var oXmin = Math.min(obj.startPos.x, obj.endPos.x);
    var oXmax = Math.max(obj.startPos.x, obj.endPos.x);
    var oYmin = Math.min(obj.startPos.y, obj.endPos.y);
    var oYmax = Math.max(obj.startPos.y, obj.endPos.y);
    return ( oXmin &lt; pos.x &amp;&amp; pos.x &lt; oXmax &amp;&amp; oYmin &lt; pos.y &amp;&amp; pos.y &lt; oYmax);
}