d3-polygon
Advanced tools
Comparing version 0.0.5 to 0.1.0
@@ -1,1 +0,1 @@ | ||
var version = "0.0.5"; export * from "../index"; export {version}; | ||
var version = "0.1.0"; export * from "../index"; export {version}; |
@@ -141,3 +141,3 @@ (function (global, factory) { | ||
var version = "0.0.5"; | ||
var version = "0.1.0"; | ||
@@ -144,0 +144,0 @@ exports.version = version; |
@@ -1,1 +0,1 @@ | ||
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("d3-polygon",["exports"],r):r(n.d3_polygon={})}(this,function(n){"use strict";function r(n){for(var r,e=-1,t=n.length,o=n[t-1],f=0;++e<t;)r=o,o=n[e],f+=r[1]*o[0]-r[0]*o[1];return f/2}function e(n){for(var r,e,t=-1,o=n.length,f=0,u=0,i=n[o-1],l=0;++t<o;)r=i,i=n[t],l+=e=r[0]*i[1]-i[0]*r[1],f+=(r[0]+i[0])*e,u+=(r[1]+i[1])*e;return l*=3,[f/l,u/l]}function t(n,r,e){return(r[0]-n[0])*(e[1]-n[1])-(r[1]-n[1])*(e[0]-n[0])}function o(n,r){return n[0]-r[0]||n[1]-r[1]}function f(n){for(var r=n.length,e=[0,1],o=2,f=2;r>f;++f){for(;o>1&&t(n[e[o-2]],n[e[o-1]],n[f])<=0;)--o;e[o++]=f}return e.slice(0,o)}function u(n){if((e=n.length)<3)return null;var r,e,t=new Array(e),u=new Array(e);for(r=0;e>r;++r)t[r]=[+n[r][0],+n[r][1],r];for(t.sort(o),r=0;e>r;++r)u[r]=[t[r][0],-t[r][1]];var i=f(t),l=f(u),c=l[0]===i[0],h=l[l.length-1]===i[i.length-1],a=[];for(r=i.length-1;r>=0;--r)a.push(n[t[i[r]][2]]);for(r=+c;r<l.length-h;++r)a.push(n[t[l[r]][2]]);return a}function i(n,r){for(var e,t,o=n.length,f=n[o-1],u=r[0],i=r[1],l=f[0],c=f[1],h=!1,a=0;o>a;++a)f=n[a],e=f[0],t=f[1],t>i!=c>i&&(l-e)*(i-t)/(c-t)+e>u&&(h=!h),l=e,c=t;return h}function l(n){for(var r,e,t=-1,o=n.length,f=n[o-1],u=f[0],i=f[1],l=0;++t<o;)r=u,e=i,f=n[t],u=f[0],i=f[1],r-=u,e-=i,l+=Math.sqrt(r*r+e*e);return l}var c="0.0.5";n.version=c,n.area=r,n.centroid=e,n.hull=u,n.inside=i,n.perimeter=l}); | ||
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("d3-polygon",["exports"],r):r(n.d3_polygon={})}(this,function(n){"use strict";function r(n){for(var r,e=-1,t=n.length,o=n[t-1],f=0;++e<t;)r=o,o=n[e],f+=r[1]*o[0]-r[0]*o[1];return f/2}function e(n){for(var r,e,t=-1,o=n.length,f=0,u=0,i=n[o-1],l=0;++t<o;)r=i,i=n[t],l+=e=r[0]*i[1]-i[0]*r[1],f+=(r[0]+i[0])*e,u+=(r[1]+i[1])*e;return l*=3,[f/l,u/l]}function t(n,r,e){return(r[0]-n[0])*(e[1]-n[1])-(r[1]-n[1])*(e[0]-n[0])}function o(n,r){return n[0]-r[0]||n[1]-r[1]}function f(n){for(var r=n.length,e=[0,1],o=2,f=2;r>f;++f){for(;o>1&&t(n[e[o-2]],n[e[o-1]],n[f])<=0;)--o;e[o++]=f}return e.slice(0,o)}function u(n){if((e=n.length)<3)return null;var r,e,t=new Array(e),u=new Array(e);for(r=0;e>r;++r)t[r]=[+n[r][0],+n[r][1],r];for(t.sort(o),r=0;e>r;++r)u[r]=[t[r][0],-t[r][1]];var i=f(t),l=f(u),c=l[0]===i[0],h=l[l.length-1]===i[i.length-1],a=[];for(r=i.length-1;r>=0;--r)a.push(n[t[i[r]][2]]);for(r=+c;r<l.length-h;++r)a.push(n[t[l[r]][2]]);return a}function i(n,r){for(var e,t,o=n.length,f=n[o-1],u=r[0],i=r[1],l=f[0],c=f[1],h=!1,a=0;o>a;++a)f=n[a],e=f[0],t=f[1],t>i!=c>i&&(l-e)*(i-t)/(c-t)+e>u&&(h=!h),l=e,c=t;return h}function l(n){for(var r,e,t=-1,o=n.length,f=n[o-1],u=f[0],i=f[1],l=0;++t<o;)r=u,e=i,f=n[t],u=f[0],i=f[1],r-=u,e-=i,l+=Math.sqrt(r*r+e*e);return l}var c="0.1.0";n.version=c,n.area=r,n.centroid=e,n.hull=u,n.inside=i,n.perimeter=l}); |
{ | ||
"name": "d3-polygon", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "Operations for two-dimensional polygons.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -7,15 +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). | ||
If you use NPM, `npm install d3-polygon`. Otherwise, download the [latest release](https://github.com/d3/d3-polygon/releases/latest). The released bundle supports AMD, CommonJS, and vanilla environments. Create a custom build using [Rollup](https://github.com/rollup/rollup) or your preferred bundler. You can also load directly from [d3js.org](https://d3js.org): | ||
```html | ||
<script src="https://d3js.org/d3-polygon.v0.1.min.js"></script> | ||
``` | ||
In a vanilla environment, a `d3_polygon` global is exported. [Try d3-polygon in your browser.](https://tonicdev.com/npm/d3-polygon) | ||
## API Reference | ||
<a href="#area" name="area">#</a> <b>area</b>(<i>polygon</i>) | ||
<a href="#area" name="area">#</a> d3_polygon.<b>area</b>(<i>polygon</i>) | ||
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="#centroid" name="centroid">#</a> <b>centroid</b>(<i>polygon</i>) | ||
<a href="#centroid" name="centroid">#</a> d3_polygon.<b>centroid</b>(<i>polygon</i>) | ||
Returns the [centroid](https://en.wikipedia.org/wiki/Centroid) of the specified *polygon*. | ||
<a href="#hull" name="hull">#</a> <b>hull</b>(<i>points</i>) | ||
<a href="#hull" name="hull">#</a> d3_polygon.<b>hull</b>(<i>points</i>) | ||
@@ -26,14 +32,8 @@ <a href="http://bl.ocks.org/mbostock/6f14f7b7f267a85f7cdc"><img src="https://raw.githubusercontent.com/d3/d3-polygon/master/img/hull.png" width="250" height="250"></a> | ||
<a href="#inside" name="inside">#</a> <b>inside</b>(<i>polygon</i>, <i>point</i>) | ||
<a href="#inside" name="inside">#</a> d3_polygon.<b>inside</b>(<i>polygon</i>, <i>point</i>) | ||
Returns true if and only if the specified *point* is [inside the specified *polygon*](https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html). | ||
<a href="#perimeter" name="perimeter">#</a> <b>perimeter</b>(<i>polygon</i>) | ||
<a href="#perimeter" name="perimeter">#</a> d3_polygon.<b>perimeter</b>(<i>polygon</i>) | ||
Returns the perimeter of the specified *polygon*. | ||
## Changes from D3 3.x: | ||
* The d3.geom.polygon API is replaced with standalone [area](#area) and [centroid](#centroid) functions. | ||
* The polygon.clip method has been removed. Do you need it? Let me know. | ||
Returns the length of the perimeter of the specified *polygon*. |
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
25961