Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

polygon-points

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polygon-points - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

40

index.js

@@ -8,2 +8,18 @@ // jshint esversion: 6, globalstrict: true, strict: true

PolygonPoints.prototype = {
get pointsLength () {
return this._pointsLength || this._countPointsInPolygon();
},
get boundingBox () {
return [{x: this._minX, y: this._minY}, {x :this._minX, y: this._maxY}, {x: this._maxX, y: this._maxY}, {x: this._maxX, y: this._minY}];
},
set vertexes (value) {
this._checkVertexes(value);
delete this._pointsLength;
},
get vertexes () {
return this._vertexes;
}
};
PolygonPoints.prototype._checkVertexes = function (vertexes) {

@@ -22,7 +38,2 @@ if (!Array.isArray(vertexes) || vertexes.length < 3) {

this._vertexesLength = vertexes.length;
this._calculateBoundingBox();
this._countPointsInPolygon();
};
PolygonPoints.prototype._calculateBoundingBox = function () {
this._maxX = this._vertexes[0].x;

@@ -38,22 +49,13 @@ this._minX = this._vertexes[0].x;

}
this._boundingBox = [{x: this._minX, y: this._minY}, {x :this._minX, y: this._maxY}, {x: this._maxX, y: this._maxY}, {x: this._maxX, y: this._minY}];
};
PolygonPoints.prototype._countPointsInPolygon = function () {
let counter = 0;
this._pointsLength = 0;
for (let y = this._minY; y < this._maxY; y++) {
for (let x = this._minX; x < this._maxX; x++) {
if (this.containsPoint({x: x, y: y}) === true) {
counter++;
this._pointsLength++;
}
}
}
this._pointsLength = counter;
};
PolygonPoints.prototype.boundingBox = function () {
return this._boundingBox;
};
PolygonPoints.prototype.pointsLength = function () {
return this._pointsLength;

@@ -75,5 +77,2 @@ };

const yi = array[i].y;
if (x === xi && y === yi) {
return true;
}
const xj = array[j].x;

@@ -89,3 +88,2 @@ const yj = array[j].y;

module.exports = PolygonPoints;
//todo check if point is on edge of polygon
module.exports = PolygonPoints;
{
"name": "polygon-points",
"version": "0.2.0",
"version": "0.3.0",
"description": "Determine if an x y coordinate exists in a polygon.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -20,6 +20,9 @@ # polygon-points

//get bounding box of polygon
polygonPoints.boundingBox();//returns an array of 4 x y coordinates
polygonPoints.boundingBox;//returns an array of 4 x y coordinates
//get total number of points that exist in polygon
polygonPoints.pointsLength();//returns 10000
polygonPoints.pointsLength;//returns 10000
//set vertexes after creating polygonPoints object
polygonPoints.vertexes = [{x: 0, y: 0}, {x: 0, y: 100}, {x: 100, y: 100}, {x: 100, y: 0}];
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc