Determine if point is within bounding box

后端 未结 7 1925
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 11:02

How would you determine if a given point is within the bounding box?

My point is 48.847172 , 2.386597.

Boundingbox:

    \"48.7998602295\",
           


        
7条回答
  •  情歌与酒
    2020-12-08 11:40

    This should be faster.

    function doesPointCollide(p,box) {
        return !(p.x < box.left || p.x > box.right || p.y > box.bottom || p.y < box.top)
    }
    

    If the point is outside any of the dimensions we know that it's not in the bounding box, else it is in the bounding box, so we can ignore negated cases more quickly.

提交回复
热议问题