Checking if an xy position is within a rectangular bounds
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);
}