Reputation: 311
I get geo coords in lon and lat, like NorthWest and SouthEast lon/lat. So, when I got them I translating into metric system. So here I get my first rectangle with north_west and south_east coords, then I have bounding-rectangle in same metric system with north, south, west and east coords. And I needed check this two rect on intersection within edges touch, what I wrote:
bool filter(TilePosition const& tile_position) const noexcept override
{
MetricBoundingBox tile_bounds{tile_position};
bool cond1 = (tile_bounds.north <= south_east_.lon);
bool cond2 = (tile_bounds.south >= north_west_.lon);
bool cond3 = (tile_bounds.west <= south_east_.lat);
bool cond4 = (tile_bounds.east >= north_west_.lat);
return cond1 && cond2 && cond3 && cond4;
}
And I'm not sure if I did it right? My requirement is if the borders of the second rect intersect with the borders of the first rect, then the second must be left. Else, filter.
Upvotes: 0
Views: 735
Reputation: 283604
Your solution is not correct.
Besides confusing the meaning of latitude and longitude, you have a fundamental problem that algorithms designed for cartesian coordinate space do not work in cylindrical coordinates, because longitude is periodic. Things may look ok for rectangles near the meridian, but when you start testing near the wrap point (+/- 180 degrees longitude) this method will fail.
One simple fix is to break each rectangle that crosses the wrap point into two that do not cross.
Upvotes: 1