Class: Archimate::Svg::Path
- Inherits:
-
Object
- Object
- Archimate::Svg::Path
- Defined in:
- lib/archimate/svg/path.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#d ⇒ Object
builds the line coordinates for the path rough drawing is the point at center of first element, point of each bendpoint, and center of end element First naive implementation if left/right range of both overlap, use centerpoint of overlap range as x val if top/bottom range of both overlap, use centerpoint of overlap range as y val.
-
#initialize(connection) ⇒ Path
constructor
A new instance of Path.
-
#length ⇒ Object
Float length of this path.
-
#midpoint ⇒ Object
Point mid-point on Path.
-
#point(fraction) ⇒ Object
Point at the given percent along line between start and end.
- #points ⇒ Object
-
#segment_lengths ⇒ Object
Returns the lengths of each segment of the line.
- #segments ⇒ Object
Constructor Details
#initialize(connection) ⇒ Path
Returns a new instance of Path.
8 9 10 |
# File 'lib/archimate/svg/path.rb', line 8 def initialize(connection) @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/archimate/svg/path.rb', line 6 def connection @connection end |
Instance Method Details
#d ⇒ Object
builds the line coordinates for the path rough drawing is the point at center of first element, point of each bendpoint, and center of end element First naive implementation if left/right range of both overlap, use centerpoint of overlap range as x val if top/bottom range of both overlap, use centerpoint of overlap range as y val
46 47 48 |
# File 'lib/archimate/svg/path.rb', line 46 def d [move_to(points.first)].concat(points[1..-1].map { |pt| line_to(pt) }).join(" ") end |
#length ⇒ Object
Returns Float length of this path.
13 14 15 |
# File 'lib/archimate/svg/path.rb', line 13 def length segment_lengths.reduce(0) { |total, length| total + length } end |
#midpoint ⇒ Object
Returns Point mid-point on Path.
18 19 20 |
# File 'lib/archimate/svg/path.rb', line 18 def midpoint point(0.5) end |
#point(fraction) ⇒ Object
Returns Point at the given percent along line between start and end.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/archimate/svg/path.rb', line 24 def point(fraction) length_from_start = length * fraction segments.each do |a, b| seg_length = b - a if seg_length >= length_from_start pct = length_from_start / seg_length return Point.new( a.x + ((b.x - a.x) * pct), a.y + ((b.y - a.y) * pct) ) else length_from_start -= seg_length end end Point.new(0.0, 0.0) end |
#points ⇒ Object
50 51 52 |
# File 'lib/archimate/svg/path.rb', line 50 def points @points ||= calc_points end |
#segment_lengths ⇒ Object
Returns the lengths of each segment of the line
59 60 61 |
# File 'lib/archimate/svg/path.rb', line 59 def segment_lengths segments.map { |a, b| b - a } end |
#segments ⇒ Object
54 55 56 |
# File 'lib/archimate/svg/path.rb', line 54 def segments (0..points.length - 2).map { |i| [points[i], points[i + 1]] } end |