Finding a point-in-a-polygon is a common problem, however, I don't understand why many have made edge cases for the prime meridian, equator and international date line. Don't the negative values for points west of the prime meridian and positive values for points east of the prime meridian take care of any problems?
The function below tries to see if a point exists within a rectangle (i.e. it uses two points to determine the rectangle). It doesn't make any checks for the prime meridian or equator and so far I have yet to find a single edge case that my function fails on. Am I missing something or have many programmers unnecessarily tried to deal with this edge case?
Can anyone find any edge cases where the following function would return true/false when it should have returned vice versa? I'm assuming if someone does find one it'd deal with a point in between the prime meridian, equator or international date line.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct point_s
{
long latitude;
long longitude;
} point_t;
bool find_point_on_plane(point_t *, point_t *, point_t *);
int main(int argc, char * argv[])
{
point_t * london = (point_t *) malloc(sizeof(point_t));
point_t * cambridge = (point_t *) malloc(sizeof(point_t));
point_t * x = (point_t *) malloc(sizeof(point_t));
london->latitude = 51.5074;
london->longitude = -.1278;
cambridge->latitude = 52.2053;
cambridge->longitude = 0.1218;
x->latitude = 52.0;
x->longitude = 0.0;
find_point_on_plane(london, cambridge, x) ? printf("True.\n") : printf("False.\n");
return 0;
}
bool find_point_on_plane(point_t * lower_left, point_t * upper_right, point_t * x)
{
if(x->latitude <= upper_right->latitude &&
x->latitude >= lower_left->latitude &&
x->longitude <= upper_right->longitude &&
x->longitude >= lower_left->longitude)
{
return true;
}
return false;
}