New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@math.gl/polygon

Package Overview
Dependencies
Maintainers
3
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@math.gl/polygon - npm Package Compare versions

Comparing version 3.4.2 to 3.5.0-alpha.1

dist/es5/earcut.js

2

dist/es5/cut-by-mercator-bounds.js

@@ -13,3 +13,3 @@ "use strict";

function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }

@@ -16,0 +16,0 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

@@ -11,3 +11,3 @@ "use strict";

get: function get() {
return _polygon["default"];
return _polygon.default;
}

@@ -18,3 +18,3 @@ });

get: function get() {
return _polygon["default"];
return _polygon.default;
}

@@ -52,2 +52,8 @@ });

});
Object.defineProperty(exports, "earcut", {
enumerable: true,
get: function get() {
return _earcut.earcut;
}
});
Object.defineProperty(exports, "clipPolygon", {

@@ -94,2 +100,4 @@ enumerable: true,

var _earcut = require("./earcut");
var _lineclip = require("./lineclip");

@@ -96,0 +104,0 @@

@@ -43,6 +43,14 @@ "use strict";

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$start = options.start,
start = _options$start === void 0 ? 0 : _options$start,
_options$end = options.end,
end = _options$end === void 0 ? points.length : _options$end;
var dim = options.size || 2;
var area = 0;
forEachSegmentInPolygon(points, function (p1x, p1y, p2x, p2y) {
area += areaCalcCallback(p1x, p1y, p2x, p2y);
}, options);
for (var i = start, j = end - dim; i < end; i += dim) {
area += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
j = i;
}
return area / 2;

@@ -53,6 +61,6 @@ }

var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var _options$start = options.start,
start = _options$start === void 0 ? 0 : _options$start,
_options$end = options.end,
end = _options$end === void 0 ? points.length : _options$end,
var _options$start2 = options.start,
start = _options$start2 === void 0 ? 0 : _options$start2,
_options$end2 = options.end,
end = _options$end2 === void 0 ? points.length : _options$end2,
_options$size = options.size,

@@ -76,6 +84,6 @@ size = _options$size === void 0 ? 2 : _options$size,

function reversePolygon(points, options) {
var _options$start2 = options.start,
start = _options$start2 === void 0 ? 0 : _options$start2,
_options$end2 = options.end,
end = _options$end2 === void 0 ? points.length : _options$end2,
var _options$start3 = options.start,
start = _options$start3 === void 0 ? 0 : _options$start3,
_options$end3 = options.end,
end = _options$end3 === void 0 ? points.length : _options$end3,
_options$size2 = options.size,

@@ -99,4 +107,4 @@ size = _options$size2 === void 0 ? 2 : _options$size2;

function modifyPolygonWindingDirectionPoints(points, direction) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var currentDirection = getPolygonWindingDirectionPoints(points, params);
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var currentDirection = getPolygonWindingDirectionPoints(points, options);

@@ -112,12 +120,19 @@ if (currentDirection !== direction) {

function getPolygonWindingDirectionPoints(points) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return Math.sign(getPolygonSignedAreaPoints(points, params));
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return Math.sign(getPolygonSignedAreaPoints(points, options));
}
function getPolygonSignedAreaPoints(points) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$start4 = options.start,
start = _options$start4 === void 0 ? 0 : _options$start4,
_options$end4 = options.end,
end = _options$end4 === void 0 ? points.length : _options$end4;
var area = 0;
forEachSegmentInPolygonPoints(points, function (p1, p2) {
area += areaCalcCallback(p1[0], p1[1], p2[0], p2[1]);
}, params);
for (var i = start, j = end - 1; i < end; ++i) {
area += (points[i][0] - points[j][0]) * (points[i][1] + points[j][1]);
j = i;
}
return area / 2;

@@ -127,8 +142,8 @@ }

function forEachSegmentInPolygonPoints(points, visitor) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var _params$start = params.start,
start = _params$start === void 0 ? 0 : _params$start,
_params$end = params.end,
end = _params$end === void 0 ? points.length : _params$end,
isClosed = params.isClosed;
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var _options$start5 = options.start,
start = _options$start5 === void 0 ? 0 : _options$start5,
_options$end5 = options.end,
end = _options$end5 === void 0 ? points.length : _options$end5,
isClosed = options.isClosed;

@@ -145,6 +160,2 @@ for (var i = start; i < end - 1; ++i) {

}
function areaCalcCallback(p1x, p1y, p2x, p2y) {
return (p1x + p2x) * (p1y - p2y);
}
//# sourceMappingURL=polygon-utils.js.map

@@ -8,3 +8,3 @@ "use strict";

});
exports["default"] = void 0;
exports.default = void 0;

@@ -22,3 +22,3 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
(0, _classCallCheck2["default"])(this, Polygon);
(0, _classCallCheck2.default)(this, Polygon);
this.points = points;

@@ -35,3 +35,3 @@ this.isFlatArray = !(0, _core.isArray)(points[0]);

(0, _createClass2["default"])(Polygon, [{
(0, _createClass2.default)(Polygon, [{
key: "getSignedArea",

@@ -76,3 +76,3 @@ value: function getSignedArea() {

exports["default"] = Polygon;
exports.default = Polygon;
//# sourceMappingURL=polygon.js.map

@@ -1,2 +0,2 @@

function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }

@@ -3,0 +3,0 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

export { default as Polygon } from './polygon';
export { getPolygonSignedArea, getPolygonWindingDirection, forEachSegmentInPolygon, modifyPolygonWindingDirection, WINDING } from './polygon-utils';
export { earcut } from './earcut';
export { clipPolygon, clipPolyline } from './lineclip';

@@ -4,0 +5,0 @@ export { cutPolygonByGrid, cutPolylineByGrid } from './cut-by-grid';

@@ -23,6 +23,14 @@ import { equals } from '@math.gl/core';

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$start = options.start,
start = _options$start === void 0 ? 0 : _options$start,
_options$end = options.end,
end = _options$end === void 0 ? points.length : _options$end;
var dim = options.size || 2;
var area = 0;
forEachSegmentInPolygon(points, function (p1x, p1y, p2x, p2y) {
area += areaCalcCallback(p1x, p1y, p2x, p2y);
}, options);
for (var i = start, j = end - dim; i < end; i += dim) {
area += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
j = i;
}
return area / 2;

@@ -32,6 +40,6 @@ }

var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var _options$start = options.start,
start = _options$start === void 0 ? 0 : _options$start,
_options$end = options.end,
end = _options$end === void 0 ? points.length : _options$end,
var _options$start2 = options.start,
start = _options$start2 === void 0 ? 0 : _options$start2,
_options$end2 = options.end,
end = _options$end2 === void 0 ? points.length : _options$end2,
_options$size = options.size,

@@ -55,6 +63,6 @@ size = _options$size === void 0 ? 2 : _options$size,

function reversePolygon(points, options) {
var _options$start2 = options.start,
start = _options$start2 === void 0 ? 0 : _options$start2,
_options$end2 = options.end,
end = _options$end2 === void 0 ? points.length : _options$end2,
var _options$start3 = options.start,
start = _options$start3 === void 0 ? 0 : _options$start3,
_options$end3 = options.end,
end = _options$end3 === void 0 ? points.length : _options$end3,
_options$size2 = options.size,

@@ -78,4 +86,4 @@ size = _options$size2 === void 0 ? 2 : _options$size2;

export function modifyPolygonWindingDirectionPoints(points, direction) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var currentDirection = getPolygonWindingDirectionPoints(points, params);
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var currentDirection = getPolygonWindingDirectionPoints(points, options);

@@ -90,20 +98,27 @@ if (currentDirection !== direction) {

export function getPolygonWindingDirectionPoints(points) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return Math.sign(getPolygonSignedAreaPoints(points, params));
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return Math.sign(getPolygonSignedAreaPoints(points, options));
}
export function getPolygonSignedAreaPoints(points) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$start4 = options.start,
start = _options$start4 === void 0 ? 0 : _options$start4,
_options$end4 = options.end,
end = _options$end4 === void 0 ? points.length : _options$end4;
var area = 0;
forEachSegmentInPolygonPoints(points, function (p1, p2) {
area += areaCalcCallback(p1[0], p1[1], p2[0], p2[1]);
}, params);
for (var i = start, j = end - 1; i < end; ++i) {
area += (points[i][0] - points[j][0]) * (points[i][1] + points[j][1]);
j = i;
}
return area / 2;
}
export function forEachSegmentInPolygonPoints(points, visitor) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var _params$start = params.start,
start = _params$start === void 0 ? 0 : _params$start,
_params$end = params.end,
end = _params$end === void 0 ? points.length : _params$end,
isClosed = params.isClosed;
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var _options$start5 = options.start,
start = _options$start5 === void 0 ? 0 : _options$start5,
_options$end5 = options.end,
end = _options$end5 === void 0 ? points.length : _options$end5,
isClosed = options.isClosed;

@@ -120,6 +135,2 @@ for (var i = start; i < end - 1; ++i) {

}
function areaCalcCallback(p1x, p1y, p2x, p2y) {
return (p1x + p2x) * (p1y - p2y);
}
//# sourceMappingURL=polygon-utils.js.map

@@ -8,3 +8,3 @@ {

},
"version": "3.4.2",
"version": "3.5.0-alpha.1",
"keywords": [

@@ -23,3 +23,2 @@ "webgl",

"module": "dist/esm/index.js",
"esnext": "dist/es6/index.js",
"files": [

@@ -30,5 +29,5 @@ "dist",

"dependencies": {
"@math.gl/core": "3.4.2"
"@math.gl/core": "3.5.0-alpha.1"
},
"gitHead": "29b92300bea8fc1b5c3fcca61302324c0bd578c7"
"gitHead": "d40d72a2b16a54129c9608f2ca326b812903d856"
}

@@ -11,2 +11,4 @@ export {default as Polygon} from './polygon';

export {earcut} from './earcut';
export {clipPolygon, clipPolyline} from './lineclip';

@@ -13,0 +15,0 @@

@@ -29,11 +29,9 @@ /* eslint-disable max-statements, max-depth, complexity, no-unused-expressions */

// https://en.wikipedia.org/wiki/Shoelace_formula
const {start = 0, end = points.length} = options;
const dim = options.size || 2;
let area = 0;
forEachSegmentInPolygon(
points,
(p1x, p1y, p2x, p2y) => {
area += areaCalcCallback(p1x, p1y, p2x, p2y);
},
options
);
for (let i = start, j = end - dim; i < end; i += dim) {
area += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
j = i;
}
return area / 2;

@@ -93,4 +91,4 @@ }

/** @type {typeof import('./polygon-utils').modifyPolygonWindingDirectionPoints} */
export function modifyPolygonWindingDirectionPoints(points, direction, params = {}) {
const currentDirection = getPolygonWindingDirectionPoints(points, params);
export function modifyPolygonWindingDirectionPoints(points, direction, options = {}) {
const currentDirection = getPolygonWindingDirectionPoints(points, options);
if (currentDirection !== direction) {

@@ -104,17 +102,15 @@ points.reverse();

/** @type {typeof import('./polygon-utils').getPolygonWindingDirectionPoints} */
export function getPolygonWindingDirectionPoints(points, params = {}) {
return Math.sign(getPolygonSignedAreaPoints(points, params));
export function getPolygonWindingDirectionPoints(points, options = {}) {
return Math.sign(getPolygonSignedAreaPoints(points, options));
}
/** @type {typeof import('./polygon-utils').getPolygonSignedAreaPoints} */
export function getPolygonSignedAreaPoints(points, params = {}) {
export function getPolygonSignedAreaPoints(points, options = {}) {
// https://en.wikipedia.org/wiki/Shoelace_formula
const {start = 0, end = points.length} = options;
let area = 0;
forEachSegmentInPolygonPoints(
points,
(p1, p2) => {
area += areaCalcCallback(p1[0], p1[1], p2[0], p2[1]);
},
params
);
for (let i = start, j = end - 1; i < end; ++i) {
area += (points[i][0] - points[j][0]) * (points[i][1] + points[j][1]);
j = i;
}
return area / 2;

@@ -124,4 +120,4 @@ }

/** @type {typeof import('./polygon-utils').forEachSegmentInPolygonPoints} */
export function forEachSegmentInPolygonPoints(points, visitor, params = {}) {
const {start = 0, end = points.length, isClosed} = params;
export function forEachSegmentInPolygonPoints(points, visitor, options = {}) {
const {start = 0, end = points.length, isClosed} = options;
for (let i = start; i < end - 1; ++i) {

@@ -136,6 +132,1 @@ visitor(points[i], points[i + 1], i, i + 1);

}
function areaCalcCallback(p1x, p1y, p2x, p2y) {
// the "cancelling" cross-products: (p1.x + p2.x) * (p1.y - p2.y)
return (p1x + p2x) * (p1y - p2y);
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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