Class: DemCurves::Path
Instance Attribute Summary collapse
-
#control_points ⇒ Object
readonly
Returns the value of attribute control_points.
-
#path_elements ⇒ Object
readonly
Returns the value of attribute path_elements.
-
#path_points ⇒ Object
readonly
Returns the value of attribute path_points.
Instance Method Summary collapse
- #add_bezier(start_handle, end_handle, end_point, tangent_lock = true) ⇒ Object
- #add_line(end_point, tangent_lock = true) ⇒ Object
- #each {|@start_point.loc| ... } ⇒ Object
- #get_guides ⇒ Object
-
#initialize(point) ⇒ Path
constructor
A new instance of Path.
- #size ⇒ Object
Constructor Details
#initialize(point) ⇒ Path
Returns a new instance of Path.
8 9 10 11 12 13 14 15 16 |
# File 'lib/core/path.rb', line 8 def initialize(point) @path_elements = [] @start_point = ControlPoint[*point] @end_point = @start_point @path_points = to_a @control_points = [@start_point] end |
Instance Attribute Details
#control_points ⇒ Object (readonly)
Returns the value of attribute control_points.
6 7 8 |
# File 'lib/core/path.rb', line 6 def control_points @control_points end |
#path_elements ⇒ Object (readonly)
Returns the value of attribute path_elements.
6 7 8 |
# File 'lib/core/path.rb', line 6 def path_elements @path_elements end |
#path_points ⇒ Object (readonly)
Returns the value of attribute path_points.
6 7 8 |
# File 'lib/core/path.rb', line 6 def path_points @path_points end |
Instance Method Details
#add_bezier(start_handle, end_handle, end_point, tangent_lock = true) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/core/path.rb', line 18 def add_bezier(start_handle, end_handle, end_point, tangent_lock=true) new_bezier = CubicBezier.new( @end_point, ControlPoint[*start_handle], ControlPoint[*end_handle], ControlPoint[*end_point]) if tangent_lock and @path_elements.last start_length = (new_bezier[:start_handle].loc - @end_point.loc).r last_element = @path_elements.last case last_element when CubicBezier LineUpConstraint.new @end_point, last_element[:end_handle], new_bezier[:start_handle] when Line LineUpConstraint.new @end_point, last_element[:center], new_bezier[:start_handle], morror_distance=false, follow=:p0 end end @end_point = new_bezier[:end] @path_elements << new_bezier @path_points = to_a @control_points += new_bezier.control_points.values[1..-1] end |
#add_line(end_point, tangent_lock = true) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/core/path.rb', line 44 def add_line(end_point, tangent_lock=true) center_point = ControlPoint[*(@end_point.loc + (Vector[*end_point] - @end_point.loc) * 0.5)] new_line = Line.new @end_point, center_point, ControlPoint[*end_point] LineUpConstraint.new center_point, new_line[:end], @end_point if tangent_lock and @path_elements.last last_element = @path_elements.last case last_element when CubicBezier LineUpConstraint.new @end_point, last_element[:end_handle], new_line[:end], morror_distance=false, follow=:p1 when Line @end_point.move_to end_point return end end @end_point = new_line[:end] @path_elements << new_line @path_points = to_a @control_points += new_line.control_points.values[1..-1] end |
#each {|@start_point.loc| ... } ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/core/path.rb', line 68 def each yield @start_point.loc @path_elements.each do |path_element| (1..path_element.path_points.size-1).each do |index| yield path_element.path_points[index] end end end |
#get_guides ⇒ Object
81 82 83 84 85 |
# File 'lib/core/path.rb', line 81 def get_guides @path_elements.inject([]) do |mem, element| mem += element.get_guides end end |
#size ⇒ Object
77 78 79 |
# File 'lib/core/path.rb', line 77 def size return @path_points.size end |