double GetPointDistance(double point_st, double point_end) {
double y2 = point_end[1];
double y1 = point_st[1];
double x1 = point_st[0];
double x2 = point_end[0];
return sqrt((x1 - x2) (x1 - x2) + (y1 - y2) (y1 - y2));
}
double GetNearestDistance(double point, double point_st, double* point_end) {
double a = 0.0, b = 0.0, c = 0.0;
a = GetPointDistance(point_end, point);
b = GetPointDistance(point_st, point);
c = GetPointDistance(point_end, point_st);
if (a a >= b b + c * c)
return b;
if (b b >= a a + c * c)
return a;
float l = (a + b + c) / 2;
float s = sqrt(abs(l (l - a) (l - b) * (l - c)));
return 2 * s / c;
}
static int PolygonIsContainPoint_with_gap(double point, double polyline, int pointcount, double* middle, double gap) {
int result = -1, tempI,temp2;
if (gap != 0)
gap = gap * 11.52339 / 1000000;
double maxx = 0, minx = 0, maxy = 0, miny = 0;
if (polyline == NULL || point == NULL)
return result;
int i;
double dis=10000.0;
int j = pointcount-1;
for (i = 0; i < pointcount; i++) {
if (i == 0) {
tempI = j+j;
temp2=0;
}
else{
tempI = i+i;
temp2 = tempI-2;
}
dis = GetNearestDistance(point, polyline+tempI, polyline+temp2);
if (dis <= gap) {
ems_log_debug("spe_cal",
"PolygonIsContainPoint gap find dis=%f <= gap=%f", dis,
gap);
result = 1;
break;
}
}
return result;
}