I have done something like this:
`Function checkOverlap(thisRectangle, otherRectangle):
if thisRectangle.UpperRight.Longitude < otherRectangle.LowerLeft.Longitude
return false
if thisRectangle.LowerLeft.Longitude > otherRectangle.UpperRight.Longitude
return false
if thisRectangle.UpperRight.Latitude < otherRectangle.LowerLeft.Latitude
return false
if thisRectangle.LowerLeft.Latitude > otherRectangle.UpperRight.Latitude
return false
return true`
But I also have to deal with the international date-line. Any suggestions to how to account for this?
I was thinking something along the lines:
`Function CrossesDateLine(lowerLeft, upperRight):
If lowerLeft.Longitude < 0 AND upperRight.Longitude > 0:
Swap lowerLeft and upperRight
newUpper = NormalizeLongitude(upperRight)
Return (lowerLeft.Longitude, newUpper)
Else:
Return (lowerLeft.Longitude, upperRight.Longitude)
End If
End Function
Function NormalizeLongitude(coordinate):
Return coordinate.Longitude + 360
End Function`
The reason for this is, in a situation where we have a coordinate with 170 and another -170 and wanted to make a bounding box, then -170 would be lowerleft and 170 upperright, even though it should actually be the other way around – and our intersection checks would fail.
Anyone has any suggestion? Not sure about mine
Martin Yakoslaw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.