mirror of https://gitee.com/bigwinds/arangodb
include points on the boundary
This commit is contained in:
parent
beafbe6a5c
commit
d56cbde03f
|
@ -2962,28 +2962,25 @@ function AQL_IS_IN_POLYGON (points, latitude, longitude) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchLat, searchLon, pointLat, pointLon, geoJson = false;
|
var search, pointLat, pointLon, geoJson = false;
|
||||||
if (TYPEWEIGHT(latitude) === TYPEWEIGHT_LIST) {
|
if (TYPEWEIGHT(latitude) === TYPEWEIGHT_LIST) {
|
||||||
geoJson = AQL_TO_BOOL(longitude);
|
geoJson = AQL_TO_BOOL(longitude);
|
||||||
if (geoJson) {
|
if (geoJson) {
|
||||||
// first list value is longitude, then latitude
|
// first list value is longitude, then latitude
|
||||||
searchLat = latitude[1];
|
search = latitude;
|
||||||
searchLon = latitude[0];
|
|
||||||
pointLat = 1;
|
pointLat = 1;
|
||||||
pointLon = 0;
|
pointLon = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// first list value is latitude, then longitude
|
// first list value is latitude, then longitude
|
||||||
searchLat = latitude[0];
|
search = latitude;
|
||||||
searchLon = latitude[1];
|
|
||||||
pointLat = 0;
|
pointLat = 0;
|
||||||
pointLon = 1;
|
pointLon = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (TYPEWEIGHT(latitude) === TYPEWEIGHT_NUMBER &&
|
else if (TYPEWEIGHT(latitude) === TYPEWEIGHT_NUMBER &&
|
||||||
TYPEWEIGHT(longitude) === TYPEWEIGHT_NUMBER) {
|
TYPEWEIGHT(longitude) === TYPEWEIGHT_NUMBER) {
|
||||||
searchLat = latitude;
|
search = [ latitude, longitude ];
|
||||||
searchLon = longitude;
|
|
||||||
pointLat = 0;
|
pointLat = 0;
|
||||||
pointLon = 1;
|
pointLon = 1;
|
||||||
}
|
}
|
||||||
|
@ -2992,32 +2989,39 @@ function AQL_IS_IN_POLYGON (points, latitude, longitude) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var i, j = points.length - 1;
|
if (points.length === 0) {
|
||||||
var oddNodes = false;
|
|
||||||
|
|
||||||
for (i = 0; i < points.length; ++i) {
|
|
||||||
if (TYPEWEIGHT(points[i]) !== TYPEWEIGHT_LIST) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((points[i][pointLat] < searchLat && points[j][pointLat] >= searchLat) ||
|
|
||||||
(points[j][pointLat] < searchLat && points[i][pointLat] >= searchLat)) &&
|
|
||||||
(points[i][pointLon] <= searchLon || points[j][pointLon] <= searchLon)) {
|
|
||||||
oddNodes ^= ((points[i][pointLon] + (searchLat - points[i][pointLat]) /
|
|
||||||
(points[j][pointLat] - points[i][pointLat]) *
|
|
||||||
(points[j][pointLon] - points[i][pointLon])) < searchLon);
|
|
||||||
}
|
|
||||||
|
|
||||||
j = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oddNodes) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var i, n = points.length;
|
||||||
|
var wn = 0;
|
||||||
|
points.push(points[0]);
|
||||||
|
|
||||||
|
var isLeft = function (p0, p1, p2) {
|
||||||
|
return ((p1[pointLon] - p0[pointLon]) * (p2[pointLat] - p0[pointLat]) -
|
||||||
|
(p2[pointLon] - p0[pointLon]) * (p1[pointLat] - p0[pointLat]));
|
||||||
|
};
|
||||||
|
|
||||||
|
for (i = 0; i < n; ++i) {
|
||||||
|
if (points[i][pointLat] <= search[pointLat]) {
|
||||||
|
if (points[i + 1][pointLat] >= search[pointLat]) {
|
||||||
|
if (isLeft(points[i], points[i + 1], search) >= 0) {
|
||||||
|
++wn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (points[i + 1][pointLat] <= search[pointLat]) {
|
||||||
|
if (isLeft(points[i], points[i + 1], search) <= 0) {
|
||||||
|
--wn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (wn !== 0);
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- fulltext functions
|
// --SECTION-- fulltext functions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue