Skip to content

Commit c3e251c

Browse files
committed
- recycle SVG after path is parsed.
- reduce point sample count for faster path parsing. - bump version
1 parent 9c7631e commit c3e251c

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Logs
22

3+
## v0.0.2
4+
5+
- recycle SVG after path is parsed.
6+
- reduce point sample count for faster path parsing.
7+
8+
39
## v0.0.1
410

511
- initial release

dist/index.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "@loadingio/parse-path",
44
"license": "MIT",
55
"description": "SVG Path Separation and Grouping",
6-
"version": "0.0.1",
6+
"version": "0.0.2",
77
"browser": "dist/index.min.js",
88
"main": "dist/index.min.js",
99
"files": [

src/parse-path.ls

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ parse-path = (path, trianglify = false) ->
22
[shape,hole] = [[],[]]
33
svg = document.createElementNS \http://www.w3.org/2000/svg, \svg
44
svg.style <<< position: \absolute, opacity: 0, z-index: -1, top: 0
5+
# appendChild is required to get correct result from complex shapes.
56
document.body.appendChild svg
67
ds = []
8+
t1 = Date.now!
79
paths = path.replace(/Z/g,'z').split \\z
810
.filter -> it
911
.map ->
@@ -14,7 +16,9 @@ parse-path = (path, trianglify = false) ->
1416
box = path.getBoundingClientRect!
1517
len = path.getTotalLength!
1618
pts = []
17-
for i from 0 to (len + 1) by (if len => (len / 200) else 1) =>
19+
# TODO 50 samples made here. we may want to use sth like bisect with a threshold distance
20+
# so we can have a dynamic point sample count.
21+
for i from 0 to (len + 1) by (if len => (len / 50) else 1) =>
1822
p = path.getPointAtLength i
1923
pts.push p.x * 0.005 - 0.8, 0.1 - p.y * 0.02
2024
sum = 0
@@ -93,9 +97,8 @@ parse-path = (path, trianglify = false) ->
9397
ret.pts ++= pts
9498
for i from 0 til pts.length / 2 => ret.groups.push g
9599
g++
96-
svg.parentNode.removeChild svg
97-
return ret
98100
else
99101
ret = []
100102
for g in gs => ret.push g.members.map((i)->ds[i]).join('z')
101-
return ret
103+
svg.parentNode.removeChild svg
104+
return ret

0 commit comments

Comments
 (0)