Created
June 2, 2020 08:34
-
-
Save tompng/c573125e59d18413ef7fb08f3677f11c to your computer and use it in GitHub Desktop.
extract xy from svg path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hoge s | |
hoges = s.scan(/[A-Za-z]|-?\d*\.\d*|\d+/).map{|a|a =~ /[\d.]/ ? a.to_f : a} | |
p hoges | |
x=y=0 | |
out=[] | |
while hoges.first | |
begin | |
c = hoges.shift | |
case c | |
when 'M' | |
x, y = hoges.shift(2) | |
out.push p [x, y] | |
when 'C', 'S' | |
hoges.shift(c == 'C' ? 4 : 2) | |
x, y = hoges.shift(2) | |
out.push p [x, y] | |
when 'c', 's' | |
while hoges[0].is_a? Numeric | |
hoges.shift(c == 'c' ? 4 : 2) | |
dx, dy = hoges.shift(2) | |
x += dx | |
y += dy | |
out.push p [x, y] | |
end | |
when 'a' | |
while hoges[0].is_a? Numeric | |
hoges.shift(5) | |
dx, dy = hoges.shift(2) | |
x += dx | |
y += dy | |
out.push p [x, y] | |
end | |
when 'z' | |
else | |
raise c.to_s | |
end | |
rescue => e;binding.irb;end | |
end | |
puts out.map{|a|'L'+a.join(',')}.join.sub('L', 'M') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment