86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/pathby.rb', line 86
def self.createCurves(pathdata)
parsedpath = Savage::Parser.parse pathdata
curves = []
parsedpath.toAbsolute
for sp in parsedpath.subpaths do
np = sp.directions[0].target.top
curve = [np]
fromp = np
for d in sp.directions[1..-1] do
prevcp = curve[-2]
if Savage::Directions::CubicCurveTo === d && d.control_1 then
curve += [d.control_1.top, d.control_2.top, d.target.top]
elsif Savage::Directions::CubicCurveTo === d && !d.control_1 then
curve += [prevcp.clone.reflect(fromp), d.control_2.top, d.target.top]
elsif Savage::Directions::VerticalTo === d then
curve += [fromp.clone, Point.new(fromp.x,d.target), Point.new(fromp.x,d.target)]
elsif Savage::Directions::HorizontalTo === d then
curve += [fromp.clone, Point.new(d.target,fromp.y), Point.new(d.target,fromp.y)]
elsif Savage::Directions::LineTo === d then
curve += [fromp.clone, d.target.top, d.target.top]
elsif Savage::Directions::ClosePath === d then
curve += [fromp.clone, np.clone , np.clone]
else raise "This class #{d.class} is not supported yet"
end
fromp = curve[-1]
end
curves << curve
end
return curves
end
|