Class: Archimate::Svg::Segment

Inherits:
Struct
  • Object
show all
Defined in:
lib/archimate/svg/segment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aObject

Returns the value of attribute a

Returns:

  • (Object)

    the current value of a



5
6
7
# File 'lib/archimate/svg/segment.rb', line 5

def a
  @a
end

#bObject

Returns the value of attribute b

Returns:

  • (Object)

    the current value of b



5
6
7
# File 'lib/archimate/svg/segment.rb', line 5

def b
  @b
end

Instance Method Details

#from_end(dist) ⇒ Object



10
11
12
13
# File 'lib/archimate/svg/segment.rb', line 10

def from_end(dist)
  length = b - a
  from_start(length - dist)
end

#from_start(dist) ⇒ Object



15
16
17
18
19
20
# File 'lib/archimate/svg/segment.rb', line 15

def from_start(dist)
  length = b - a
  return a if dist.negative?
  return b if length < dist
  point_at_percent(dist / length)
end

#lengthObject



6
7
8
# File 'lib/archimate/svg/segment.rb', line 6

def length
  b - a
end

#point_at_percent(pct) ⇒ Object



22
23
24
25
26
27
# File 'lib/archimate/svg/segment.rb', line 22

def point_at_percent(pct)
  Point.new(
    a.x + ((b.x - a.x) * pct),
    a.y + ((b.y - a.y) * pct)
  )
end