class Draught::Line::LineBuilderFromAngles
Attributes
length[R]
radians[R]
start_point[R]
Public Class Methods
new(args)
click to toggle source
# File lib/draught/line.rb, line 138 def initialize(args) @start_point = args.fetch(:start_point, Point::ZERO) @length = args.fetch(:length) @radians = args.fetch(:radians) end
Public Instance Methods
line_args()
click to toggle source
# File lib/draught/line.rb, line 144 def line_args {length: length, radians: radians, start_point: start_point, end_point: end_point} end
Private Instance Methods
end_point()
click to toggle source
# File lib/draught/line.rb, line 150 def end_point end_point_from_zero.translate(Vector.translation_between(Point::ZERO, start_point)) end
end_point_from_zero()
click to toggle source
# File lib/draught/line.rb, line 154 def end_point_from_zero hardwired_end_points.fetch(restricted_radians) { single_quadrant_end_point.transform(Transformations.rotate(remaining_angle)) } end
hardwired_end_points()
click to toggle source
# File lib/draught/line.rb, line 168 def hardwired_end_points { 0 => Point.new(length,0), DEGREES_90 => Point.new(0,length), DEGREES_180 => Point.new(-length,0), DEGREES_270 => Point.new(0,-length), DEGREES_360 => Point.new(length,0) } end
remaining_angle()
click to toggle source
# File lib/draught/line.rb, line 194 def remaining_angle @remaining_angle ||= begin [DEGREES_270, DEGREES_180, DEGREES_90, 0].find { |angle| restricted_radians > angle } || 0 end end
restrict_to_360_degrees(radians)
click to toggle source
# File lib/draught/line.rb, line 164 def restrict_to_360_degrees(radians) radians % DEGREES_360 end
restricted_radians()
click to toggle source
# File lib/draught/line.rb, line 160 def restricted_radians @restricted_radians ||= restrict_to_360_degrees(radians) end
single_quadrant_angle()
click to toggle source
# File lib/draught/line.rb, line 190 def single_quadrant_angle @single_quadrant_angle ||= restricted_radians - remaining_angle end
single_quadrant_end_point()
click to toggle source
# File lib/draught/line.rb, line 178 def single_quadrant_end_point Point.new(x, y) end
x()
click to toggle source
# File lib/draught/line.rb, line 182 def x Math.cos(single_quadrant_angle) * length end
y()
click to toggle source
# File lib/draught/line.rb, line 186 def y Math.sin(single_quadrant_angle) * length end