SOURCE

var Tools = {
    isPointInCircle: function(checkPoint , circleInfo){

    },
    isPointInPolygon: function(checkPoint , points){
        var counter = 0;
        var i;
        var xinters;
        var p1, p2;
        var polygonPoints = points;
        var pointCount = polygonPoints.length;
        p1 = polygonPoints[0];

        for (i = 1; i <= pointCount; i++) {
            p2 = polygonPoints[i % pointCount];
            if ( checkPoint[0] > Math.min(p1.x, p2.x) && checkPoint[0] <= Math.max(p1.x, p2.x)) {
                if (checkPoint[1] <= Math.max(p1.y, p2.y)) {
                    if (p1.x != p2.x) {
                        xinters = (checkPoint[0] - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
                        if (p1.y == p2.y || checkPoint[1] <= xinters) {
                            counter++;
                        }
                    }
                }
            }
            p1 = p2;
        }
        if (counter % 2 == 0) {
            return false;
        } else {
            return true;
        }
    }
}
console 命令行工具 X clear

                    
>
console