{"library":"point-in-big-polygon","title":"Industrial Strength Point-in-Polygon Test","description":"point-in-big-polygon is a JavaScript library providing an industrial-strength solution for the point-in-polygon problem. It specializes in classifying a single point against a potentially large and complex 2D polygon with high precision. The library preprocesses the polygon in O(n log(n)) time to create an optimized classification function, which then determines if any given point is inside, on the boundary, or outside the polygon in O(log(n)) operations. All internal computations utilize exact arithmetic, guaranteeing robust and precise results even with degenerate cases or floating-point inaccuracies. The current stable version is 2.0.1, and while its last major update was around 2014, it remains a reliable tool for specialized geospatial or geometric computations in CommonJS environments, including Node.js and browsers via bundlers like Browserify. Its primary differentiation lies in its optimized performance and exactness for single, complex polygons.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install point-in-big-polygon"],"cli":null},"imports":["const preprocessPolygon = require('point-in-big-polygon')","const classifyPoint = preprocessPolygon(loops)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const preprocessPolygon = require('point-in-big-polygon')\n\n//Define the polygon loops (outer loop clockwise, inner loop counter-clockwise assumed for holes)\nconst loops = [\n  [ [-10, -10], [-10, 10], [10, 10], [10, -10] ], // Outer square\n  [ [-1, -1], [1, -1], [1, 1], [-1, 1] ] // Inner square (hole)\n]\n\n//Preprocess the polygon to get a classification function\nconst classifyPoint = preprocessPolygon(loops)\n\n//Render polygon test in ASCII to console\nconst img = []\nfor(let y=-12; y<=12; y+=1) {\n  let row = []\n  for(let x=-12; x<=12; x+=0.5) {\n    const v = classifyPoint([x, y])\n    if(v < 0) {\n      row.push('-') // Inside\n    } else if(v === 0) {\n      row.push('o') // On boundary\n    } else {\n      row.push('+') // Outside\n    }\n  }\n  img.push(row.join(''))\n}\nconsole.log(img.join('\\n'))","lang":"javascript","description":"Classifies points against a polygon with a hole and renders the result as an ASCII image to the console, illustrating inside (-), boundary (o), and outside (+) regions using the `classifyPoint` function.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}