Class: JennCad::Line
- Inherits:
-
Object
- Object
- JennCad::Line
- Defined in:
- lib/jenncad/features/path.rb
Instance Attribute Summary collapse
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#current_angle ⇒ Object
Returns the value of attribute current_angle.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#end_point ⇒ Object
Returns the value of attribute end_point.
-
#l ⇒ Object
Returns the value of attribute l.
-
#start_point ⇒ Object
Returns the value of attribute start_point.
Instance Method Summary collapse
- #ep_margin(margin) ⇒ Object
-
#initialize(args) ⇒ Line
constructor
A new instance of Line.
- #part ⇒ Object
- #shrink_ep(len) ⇒ Object
- #shrink_sp(len) ⇒ Object
- #sp_margin(margin) ⇒ Object
Constructor Details
#initialize(args) ⇒ Line
Returns a new instance of Line.
140 141 142 143 144 145 146 147 148 |
# File 'lib/jenncad/features/path.rb', line 140 def initialize(args) @start_point = args[:start_point] @end_point = args[:end_point] @angle = args[:angle] @current_angle = args[:current_angle] @direction = args[:direction] @l = args[:l] @thing = args[:thing] end |
Instance Attribute Details
#angle ⇒ Object
Returns the value of attribute angle.
139 140 141 |
# File 'lib/jenncad/features/path.rb', line 139 def angle @angle end |
#current_angle ⇒ Object
Returns the value of attribute current_angle.
139 140 141 |
# File 'lib/jenncad/features/path.rb', line 139 def current_angle @current_angle end |
#direction ⇒ Object
Returns the value of attribute direction.
139 140 141 |
# File 'lib/jenncad/features/path.rb', line 139 def direction @direction end |
#end_point ⇒ Object
Returns the value of attribute end_point.
139 140 141 |
# File 'lib/jenncad/features/path.rb', line 139 def end_point @end_point end |
#l ⇒ Object
Returns the value of attribute l.
139 140 141 |
# File 'lib/jenncad/features/path.rb', line 139 def l @l end |
#start_point ⇒ Object
Returns the value of attribute start_point.
139 140 141 |
# File 'lib/jenncad/features/path.rb', line 139 def start_point @start_point end |
Instance Method Details
#ep_margin(margin) ⇒ Object
155 156 157 158 |
# File 'lib/jenncad/features/path.rb', line 155 def ep_margin(margin) @end_point[:x] -= margin[:x] @end_point[:y] -= margin[:y] end |
#part ⇒ Object
184 185 186 187 188 189 |
# File 'lib/jenncad/features/path.rb', line 184 def part hull( Marshal.load(@thing).move(x: @start_point[:x], y: @start_point[:y]), Marshal.load(@thing).move(x: @end_point[:x], y: @end_point[:y]) ) end |
#shrink_ep(len) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/jenncad/features/path.rb', line 160 def shrink_ep(len) sx, sy = @start_point[:x], @start_point[:y] ex, ey = @end_point[:x], @end_point[:y] vx = ex-sx vy = ey-sy l = Math::sqrt(vx**2 + vy**2) factor = len / l @end_point[:x] -= vx * factor @end_point[:y] -= vy * factor #puts "#{sx} x #{sy} => #{ex} x #{ey} , shrink #{factor} " end |
#shrink_sp(len) ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/jenncad/features/path.rb', line 172 def shrink_sp(len) sx, sy = @start_point[:x], @start_point[:y] ex, ey = @end_point[:x], @end_point[:y] vx = ex-sx vy = ey-sy l = Math::sqrt(vx**2 + vy**2) factor = len / l @start_point[:x] -= vx * factor @start_point[:y] -= vy * factor end |
#sp_margin(margin) ⇒ Object
150 151 152 153 |
# File 'lib/jenncad/features/path.rb', line 150 def sp_margin(margin) @start_point[:x] -= margin[:x] @start_point[:y] -= margin[:y] end |