d3-polygon
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -7,2 +7,26 @@ (function (global, factory) { | ||
function perimeter$1(polygon) { | ||
var i = -1, | ||
n = polygon.length, | ||
b = polygon[n - 1], | ||
xa, | ||
ya, | ||
xb = b[0], | ||
yb = b[1], | ||
perimeter = 0; | ||
while (++i < n) { | ||
xa = xb; | ||
ya = yb; | ||
b = polygon[i]; | ||
xb = b[0]; | ||
yb = b[1]; | ||
xa -= xb; | ||
ya -= yb; | ||
perimeter += Math.sqrt(xa * xa + ya * ya); | ||
} | ||
return perimeter; | ||
}; | ||
function centroid(polygon) { | ||
@@ -27,5 +51,5 @@ var i = -1, | ||
return k *= 3, [x / k, y / k]; | ||
} | ||
}; | ||
function area(polygon) { | ||
function area$1(polygon) { | ||
var i = -1, | ||
@@ -43,8 +67,9 @@ n = polygon.length, | ||
return area * .5; | ||
} | ||
return area / 2; | ||
}; | ||
exports.area = area; | ||
exports.area = area$1; | ||
exports.centroid = centroid; | ||
exports.perimeter = perimeter$1; | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.polygon={})}(this,function(e){"use strict";function n(e){for(var n,t,o=-1,f=e.length,r=0,i=0,u=e[f-1],c=0;++o<f;)n=u,u=e[o],c+=t=n[0]*u[1]-u[0]*n[1],r+=(n[0]+u[0])*t,i+=(n[1]+u[1])*t;return c*=3,[r/c,i/c]}function t(e){for(var n,t=-1,o=e.length,f=e[o-1],r=0;++t<o;)n=f,f=e[t],r+=n[1]*f[0]-n[0]*f[1];return.5*r}e.area=t,e.centroid=n}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.polygon={})}(this,function(e){"use strict";function t(e){for(var t,n,r=-1,o=e.length,f=e[o-1],i=f[0],u=f[1],c=0;++r<o;)t=i,n=u,f=e[r],i=f[0],u=f[1],t-=i,n-=u,c+=Math.sqrt(t*t+n*n);return c}function n(e){for(var t,n,r=-1,o=e.length,f=0,i=0,u=e[o-1],c=0;++r<o;)t=u,u=e[r],c+=n=t[0]*u[1]-u[0]*t[1],f+=(t[0]+u[0])*n,i+=(t[1]+u[1])*n;return c*=3,[f/c,i/c]}function r(e){for(var t,n=-1,r=e.length,o=e[r-1],f=0;++n<r;)t=o,o=e[n],f+=t[1]*o[0]-t[0]*o[1];return f/2}e.area=r,e.centroid=n,e.perimeter=t}); |
import area from "./src/area"; | ||
import centroid from "./src/centroid"; | ||
import perimeter from "./src/perimeter"; | ||
export { | ||
area, | ||
centroid | ||
centroid, | ||
perimeter | ||
}; |
{ | ||
"name": "d3-polygon", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Operations for two-dimensional polygons.", | ||
@@ -15,3 +15,3 @@ "keywords": [ | ||
}, | ||
"main": "build/polygon", | ||
"main": "build/polygon.cjs", | ||
"jsnext:main": "index", | ||
@@ -23,8 +23,8 @@ "repository": { | ||
"scripts": { | ||
"pretest": "mkdir -p build && d3-bundler --format=umd --name=polygon -- index.js > build/polygon.js", | ||
"pretest": "mkdir -p build && d3-bundler -x -f cjs -o build/polygon.cjs.js", | ||
"test": "faucet `find test -name '*-test.js'`", | ||
"prepublish": "npm run test && uglifyjs build/polygon.js -c -m -o build/polygon.min.js && rm -f build/polygon.zip && zip -j build/polygon.zip -- LICENSE README.md build/polygon.js build/polygon.min.js" | ||
"prepublish": "npm run test && d3-bundler -n polygon -o build/polygon.js && uglifyjs build/polygon.js -c -m -o build/polygon.min.js && rm -f build/polygon.zip && zip -j build/polygon.zip -- LICENSE README.md build/polygon.js build/polygon.min.js" | ||
}, | ||
"devDependencies": { | ||
"d3-bundler": "~0.2.5", | ||
"d3-bundler": "~0.4.0", | ||
"faucet": "0.0", | ||
@@ -31,0 +31,0 @@ "tape": "4", |
@@ -17,4 +17,8 @@ # d3-polygon | ||
Returns the [centroid](https://en.wikipedia.org/wiki/Centroid) of the specified *polygon*. The optional *k* | ||
Returns the [centroid](https://en.wikipedia.org/wiki/Centroid) of the specified *polygon*. | ||
<a href="#perimeter" name="perimeter">#</a> <b>perimeter</b>(<i>polygon</i>) | ||
Returns the perimeter of the specified *polygon*. | ||
## Changes from D3 3.x: | ||
@@ -21,0 +25,0 @@ |
@@ -14,3 +14,3 @@ export default function(polygon) { | ||
return area * .5; | ||
return area / 2; | ||
}; |
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
8182
11
175
28