Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function pointInPolyWithHoles(pt: [number, number], polyWithHoles: number[][][]): boolean {
const poly = polyWithHoles[0]
// log('testing', pt, 'in', poly, 'in', polyWithHoles)
if (pointInPoly(pt, poly)) {
// log('pt in poly')
const holes = polyWithHoles.slice(1)
for (const hole of holes) {
if (pointInPoly(pt, hole)) {
// log('pt in hole')
return false
}
}
// log('pt in poly but not holes')
return true
}
// log('pt in none polys')
return false
}
import inside from 'point-in-polygon';
const polygon = [ [ 1, 1 ], [ 1, 2 ], [ 2, 2 ], [ 2, 1 ] ];
const inPolygon: boolean = inside([ 1.5, 1.5 ], polygon);
import inside from 'point-in-polygon';
const polygon = [ [ 1, 1 ], [ 1, 2 ], [ 2, 2 ], [ 2, 1 ] ];
const inPolygon: boolean = inside([ 1.5, 1.5 ], polygon);
MapModel.prototype.getRandomPointForCountryBorder = function (country, coordinates) {
if (!this._countryBoundsCache[country]) {
this._countryBoundsCache[country] = MapModel.getBounds(coordinates);
}
var bounds = this._countryBoundsCache[country];
var la, lo;
var count = 0;
do {
la = Math.random() * (bounds.maxLa - bounds.minLa) + bounds.minLa;
lo = Math.random() * (bounds.maxLo - bounds.minLo) + bounds.minLo;
count++;
} while (!inside([la, lo], coordinates) && count < 100);
if (count == 100) {
//console.log('could not create random point for ' + country);
return [0, 0];
}
return [la, lo];
};
markersArray.forEach(marker=>{
const x = marker.getPosition().lat();
const y = marker.getPosition().lng();
if (!isInside([x,y],polygon)) {
marker.setMap(null)
} else {
insideMarkers.push(marker);
if (!marker.map) {
marker.setMap(this.map)
}
}
})
if (this.props.handleReturnedMarkers) {
path => inside(pointDimensions, path[0])
)
function isPointIn(p: Vector, polygon: Array<[number, number]>) {
const point = [p.x, p.y];
return inside(point, polygon);
}
.filter(point => pointInPolygon(point, this.thickerX));
return testPts.every( (p) => pointInPolygon([p.x,p.y], polyPtsAsArray));
}