svg-polygon-decorator
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "svg-polygon-decorator", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Svg polygon decorator (cloud)", | ||
@@ -21,6 +21,18 @@ "main": "src/decorator.js", | ||
"serve": "serve -p 3002", | ||
"lint": "eslint ./src/ && eslint ./demo/index.js" | ||
"lint": "eslint ./src/ && eslint ./demo/index.js", | ||
"prebuild": "npm run lint", | ||
"build": "browserify -v -t [ babelify --presets [ es2015 ] ] -s svgCloud src/decorator.js -o lib/index.js", | ||
"prepublish": "npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com:rumax/svg-polygon-decorator.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/rumax/svg-polygon-decorator/issues" | ||
}, | ||
"homepage": "https://github.com/rumax/svg-polygon-decorator#readme", | ||
"keywords": [ | ||
"svg", | ||
"decorator", | ||
"cloud" | ||
@@ -27,0 +39,0 @@ ], |
@@ -5,3 +5,3 @@ | ||
* | ||
* @param {Polygon} poligon | ||
* @param {Polygon} polygon | ||
* | ||
@@ -91,13 +91,15 @@ * @return {SVG Path} | ||
const cloudALine = (line, radius) => { | ||
let intersection = getIntersection(line, radius * 2); | ||
const cloudALine = (line, radius, inward) => { | ||
let point = getIntersection(line, radius * 2); | ||
let remainingLine = line; | ||
let arc; | ||
const cloud = [`M ${line[0][0]}, ${line[0][1]}`]; | ||
const cloud = [`M${line[0][X]}, ${line[0][Y]}`]; | ||
const sweep = true === inward ? 0 : 1; | ||
const lArc = true === inward ? 0 : 1; | ||
while (intersection) { | ||
arc = ` A ${radius} ${radius} 0 1 1 ${intersection[0]} ${intersection[1]}`; | ||
while (point) { | ||
arc = ` A ${radius} ${radius} 0 ${lArc} ${sweep} ${point[X]} ${point[Y]}`; | ||
cloud.push(arc); | ||
remainingLine = [intersection, remainingLine[1]]; | ||
intersection = getIntersection(remainingLine, radius * 2); | ||
remainingLine = [point, remainingLine[1]]; | ||
point = getIntersection(remainingLine, radius * 2); | ||
} | ||
@@ -113,22 +115,28 @@ | ||
return length / segments / 2; | ||
return 0 < length ? length / segments / 2 : radius; | ||
}; | ||
const svgCloud = (poligon, radius) => { | ||
let cloud = `M ${poligon[0][0]}, ${poligon[0][1]}`; | ||
const svgCloud = (polyline, radius, closed, inward) => { | ||
let cloud = ''; | ||
let ind = 1; | ||
let line; | ||
const cnt = poligon.length; | ||
const cnt = polyline.length; | ||
for (; ind < cnt; ++ind) { | ||
line = [poligon[ind - 1], poligon[ind]]; | ||
cloud += cloudALine(line, fixRadiusToFitLine(line, radius)); | ||
if (0 >= ind) { | ||
cloud += ' '; | ||
} | ||
line = [polyline[ind - 1], polyline[ind]]; | ||
cloud += cloudALine(line, fixRadiusToFitLine(line, radius), inward); | ||
} | ||
// Last line (last point to first point) | ||
line = [poligon[ind - 1], poligon[0]]; | ||
cloud += cloudALine(line, fixRadiusToFitLine(line, radius)); | ||
// close to get polygon | ||
if (true === closed) { | ||
line = [polyline[ind - 1], polyline[0]]; | ||
cloud += ' ' + cloudALine(line, fixRadiusToFitLine(line, radius), inward); | ||
} | ||
return cloud; | ||
// SVG complains about empty path strings | ||
return cloud || 'M0 0'; | ||
}; | ||
@@ -135,0 +143,0 @@ |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
30217
8
241
1
0
2