d3-polygon
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -1,7 +0,7 @@ | ||
// https://d3js.org/d3-polygon/ v2.0.0 Copyright 2020 Mike Bostock | ||
// https://d3js.org/d3-polygon/ v3.0.0 Copyright 2021 Mike Bostock | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.d3 = global.d3 || {})); | ||
}(this, function (exports) { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {})); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -150,2 +150,2 @@ function area(polygon) { | ||
})); | ||
}))); |
@@ -1,2 +0,2 @@ | ||
// https://d3js.org/d3-polygon/ v2.0.0 Copyright 2020 Mike Bostock | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n=n||self).d3=n.d3||{})}(this,function(n){"use strict";function e(n,e){return n[0]-e[0]||n[1]-e[1]}function t(n){const e=n.length,t=[0,1];let r,o=2;for(r=2;r<e;++r){for(;o>1&&(f=n[t[o-2]],u=n[t[o-1]],l=n[r],(u[0]-f[0])*(l[1]-f[1])-(u[1]-f[1])*(l[0]-f[0])<=0);)--o;t[o++]=r}var f,u,l;return t.slice(0,o)}n.polygonArea=function(n){for(var e,t=-1,r=n.length,o=n[r-1],f=0;++t<r;)e=o,o=n[t],f+=e[1]*o[0]-e[0]*o[1];return f/2},n.polygonCentroid=function(n){for(var e,t,r=-1,o=n.length,f=0,u=0,l=n[o-1],i=0;++r<o;)e=l,l=n[r],i+=t=e[0]*l[1]-l[0]*e[1],f+=(e[0]+l[0])*t,u+=(e[1]+l[1])*t;return[f/(i*=3),u/i]},n.polygonContains=function(n,e){for(var t,r,o=n.length,f=n[o-1],u=e[0],l=e[1],i=f[0],g=f[1],h=!1,c=0;c<o;++c)t=(f=n[c])[0],(r=f[1])>l!=g>l&&u<(i-t)*(l-r)/(g-r)+t&&(h=!h),i=t,g=r;return h},n.polygonHull=function(n){if((o=n.length)<3)return null;var r,o,f=new Array(o),u=new Array(o);for(r=0;r<o;++r)f[r]=[+n[r][0],+n[r][1],r];for(f.sort(e),r=0;r<o;++r)u[r]=[f[r][0],-f[r][1]];var l=t(f),i=t(u),g=i[0]===l[0],h=i[i.length-1]===l[l.length-1],c=[];for(r=l.length-1;r>=0;--r)c.push(n[f[l[r]][2]]);for(r=+g;r<i.length-h;++r)c.push(n[f[i[r]][2]]);return c},n.polygonLength=function(n){for(var e,t,r=-1,o=n.length,f=n[o-1],u=f[0],l=f[1],i=0;++r<o;)e=u,t=l,e-=u=(f=n[r])[0],t-=l=f[1],i+=Math.hypot(e,t);return i},Object.defineProperty(n,"__esModule",{value:!0})}); | ||
// https://d3js.org/d3-polygon/ v3.0.0 Copyright 2021 Mike Bostock | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).d3=n.d3||{})}(this,(function(n){"use strict";function e(n,e){return n[0]-e[0]||n[1]-e[1]}function t(n){const e=n.length,t=[0,1];let o,r=2;for(o=2;o<e;++o){for(;r>1&&(f=n[t[r-2]],l=n[t[r-1]],u=n[o],(l[0]-f[0])*(u[1]-f[1])-(l[1]-f[1])*(u[0]-f[0])<=0);)--r;t[r++]=o}var f,l,u;return t.slice(0,r)}n.polygonArea=function(n){for(var e,t=-1,o=n.length,r=n[o-1],f=0;++t<o;)e=r,r=n[t],f+=e[1]*r[0]-e[0]*r[1];return f/2},n.polygonCentroid=function(n){for(var e,t,o=-1,r=n.length,f=0,l=0,u=n[r-1],i=0;++o<r;)e=u,u=n[o],i+=t=e[0]*u[1]-u[0]*e[1],f+=(e[0]+u[0])*t,l+=(e[1]+u[1])*t;return[f/(i*=3),l/i]},n.polygonContains=function(n,e){for(var t,o,r=n.length,f=n[r-1],l=e[0],u=e[1],i=f[0],g=f[1],h=!1,a=0;a<r;++a)t=(f=n[a])[0],(o=f[1])>u!=g>u&&l<(i-t)*(u-o)/(g-o)+t&&(h=!h),i=t,g=o;return h},n.polygonHull=function(n){if((r=n.length)<3)return null;var o,r,f=new Array(r),l=new Array(r);for(o=0;o<r;++o)f[o]=[+n[o][0],+n[o][1],o];for(f.sort(e),o=0;o<r;++o)l[o]=[f[o][0],-f[o][1]];var u=t(f),i=t(l),g=i[0]===u[0],h=i[i.length-1]===u[u.length-1],a=[];for(o=u.length-1;o>=0;--o)a.push(n[f[u[o]][2]]);for(o=+g;o<i.length-h;++o)a.push(n[f[i[o]][2]]);return a},n.polygonLength=function(n){for(var e,t,o=-1,r=n.length,f=n[r-1],l=f[0],u=f[1],i=0;++o<r;)e=l,t=u,e-=l=(f=n[o])[0],t-=u=f[1],i+=Math.hypot(e,t);return i},Object.defineProperty(n,"__esModule",{value:!0})})); |
{ | ||
"name": "d3-polygon", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Operations for two-dimensional polygons.", | ||
"homepage": "https://d3js.org/d3-polygon/", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/d3/d3-polygon.git" | ||
}, | ||
"keywords": [ | ||
@@ -13,4 +18,3 @@ "d3", | ||
], | ||
"homepage": "https://d3js.org/d3-polygon/", | ||
"license": "BSD-3-Clause", | ||
"license": "ISC", | ||
"author": { | ||
@@ -20,10 +24,3 @@ "name": "Mike Bostock", | ||
}, | ||
"main": "dist/d3-polygon.js", | ||
"unpkg": "dist/d3-polygon.min.js", | ||
"jsdelivr": "dist/d3-polygon.min.js", | ||
"module": "src/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/d3/d3-polygon.git" | ||
}, | ||
"type": "module", | ||
"files": [ | ||
@@ -33,15 +30,25 @@ "dist/**/*.js", | ||
], | ||
"scripts": { | ||
"pretest": "rollup -c", | ||
"test": "tape 'test/**/*-test.js' && eslint src test", | ||
"prepublishOnly": "rm -rf dist && yarn test", | ||
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd - && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js" | ||
"module": "src/index.js", | ||
"main": "src/index.js", | ||
"jsdelivr": "dist/d3-polygon.min.js", | ||
"unpkg": "dist/d3-polygon.min.js", | ||
"exports": { | ||
"umd": "./dist/d3-polygon.min.js", | ||
"default": "./src/index.js" | ||
}, | ||
"sideEffects": false, | ||
"devDependencies": { | ||
"eslint": "6", | ||
"rollup": "1", | ||
"rollup-plugin-terser": "5", | ||
"tape": "4" | ||
"eslint": "7", | ||
"mocha": "8", | ||
"rollup": "2", | ||
"rollup-plugin-terser": "7" | ||
}, | ||
"scripts": { | ||
"test": "mocha 'test/**/*-test.js' && eslint src test", | ||
"prepublishOnly": "rm -rf dist && yarn test && rollup -c", | ||
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd -" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
} | ||
} |
@@ -7,9 +7,21 @@ # d3-polygon | ||
If you use NPM, `npm install d3-polygon`. Otherwise, download the [latest release](https://github.com/d3/d3-polygon/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-polygon.v1.min.js) or as part of [D3](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: | ||
If you use npm, `npm install d3-polygon`. You can also download the [latest release on GitHub](https://github.com/d3/d3-polygon/releases/latest). For vanilla HTML in modern browsers, import d3-polygon from Skypack: | ||
```html | ||
<script src="https://d3js.org/d3-polygon.v2.min.js"></script> | ||
<script type="module"> | ||
import {polygonHull} from "https://cdn.skypack.dev/d3-polygon@3"; | ||
const hull = polygonHull(points); | ||
</script> | ||
``` | ||
For legacy environments, you can load d3-polygon’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported: | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/d3-polygon@3"></script> | ||
<script> | ||
var hull = d3.polygonHull(points); | ||
const hull = d3.polygonHull(points); | ||
@@ -21,7 +33,7 @@ </script> | ||
<a href="#polygonArea" name="polygonArea">#</a> d3.<b>polygonArea</b>(<i>polygon</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/area.js#L1 "Source Code") | ||
<a href="#polygonArea" name="polygonArea">#</a> d3.<b>polygonArea</b>(<i>polygon</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/area.js "Source Code") | ||
Returns the signed area of the specified *polygon*. If the vertices of the polygon are in counterclockwise order (assuming a coordinate system where the origin ⟨0,0⟩ is in the top-left corner), the returned area is positive; otherwise it is negative, or zero. | ||
<a href="#polygonCentroid" name="polygonCentroid">#</a> d3.<b>polygonCentroid</b>(<i>polygon</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/centroid.js#L1 "Source Code") | ||
<a href="#polygonCentroid" name="polygonCentroid">#</a> d3.<b>polygonCentroid</b>(<i>polygon</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/centroid.js "Source Code") | ||
@@ -36,8 +48,8 @@ Returns the [centroid](https://en.wikipedia.org/wiki/Centroid) of the specified *polygon*. | ||
<a href="#polygonContains" name="polygonContains">#</a> d3.<b>polygonContains</b>(<i>polygon</i>, <i>point</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/contains.js#L1 "Source Code") | ||
<a href="#polygonContains" name="polygonContains">#</a> d3.<b>polygonContains</b>(<i>polygon</i>, <i>point</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/contains.js "Source Code") | ||
Returns true if and only if the specified *point* is inside the specified *polygon*. | ||
<a href="#polygonLength" name="polygonLength">#</a> d3.<b>polygonLength</b>(<i>polygon</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/length.js#L1 "Source Code") | ||
<a href="#polygonLength" name="polygonLength">#</a> d3.<b>polygonLength</b>(<i>polygon</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/length.js "Source Code") | ||
Returns the length of the perimeter of the specified *polygon*. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53
Yes
14817