Module: Pathby

Defined in:
lib/pathby.rb,
lib/measurements.rb,
lib/transformations.rb

Defined Under Namespace

Modules: Pathy, Shapy, Transformations Classes: Path, Point, Shape

Class Method Summary collapse

Class Method Details

.createCurves(pathdata) ⇒ Object



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 = []
  #puts parsedpath.directions
  parsedpath.toAbsolute
  for sp in parsedpath.subpaths do
    #get first Move direction point

    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

.createPath(pathdata, path = Path.new([])) ⇒ Object



120
121
122
123
# File 'lib/pathby.rb', line 120

def self.createPath(pathdata,path=Path.new([]))
  path.curves = createCurves(pathdata)
  return path
end

.createShape(pathdatalist) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/pathby.rb', line 77

def self.createShape(pathdatalist)
  ret = Shape.new([])
  pathdatalist.each do |pathdata|
    path = self.createPath(pathdata)
    ret.paths <<  path
  end
  return ret
end