class Draught::Line::LineBuilderFromPoint
Attributes
end_point[R]
start_point[R]
Public Class Methods
new(args)
click to toggle source
# File lib/draught/line.rb, line 207 def initialize(args) @start_point = args.fetch(:start_point, Point::ZERO) @end_point = args.fetch(:end_point) end
Public Instance Methods
line_args()
click to toggle source
# File lib/draught/line.rb, line 212 def line_args {length: length, radians: radians, start_point: start_point, end_point: end_point} end
Private Instance Methods
angle_ignoring_quadrant()
click to toggle source
# File lib/draught/line.rb, line 267 def angle_ignoring_quadrant Math.acos(y_length.to_f/length) end
angle_to_start_of_quadrant()
click to toggle source
# File lib/draught/line.rb, line 251 def angle_to_start_of_quadrant which_side_of_x = end_point_from_zero.x <=> 0 which_side_of_y = end_point_from_zero.y <=> 0 case [which_side_of_x, which_side_of_y] when [1,0], [1, 1] # 0-90º 0 when [0,1], [-1, 1] # 90-180º DEGREES_90 when [-1, 0], [-1, -1] # 180-270º DEGREES_180 when [0, -1], [1, -1] # 270-360º DEGREES_270 end end
end_point_from_zero()
click to toggle source
# File lib/draught/line.rb, line 218 def end_point_from_zero @end_point_from_zero ||= end_point.translate(Vector.translation_between(start_point, Point::ZERO)) end
length()
click to toggle source
# File lib/draught/line.rb, line 223 def length @length ||= begin if x_length == 0 || y_length == 0 x_length + y_length else Math.sqrt(x_length ** 2 + y_length ** 2) end end end
radians()
click to toggle source
# File lib/draught/line.rb, line 233 def radians @radians ||= begin if x_length == 0 || y_length == 0 angle_to_start_of_quadrant else angle_to_start_of_quadrant + angle_ignoring_quadrant end end end
x_length()
click to toggle source
# File lib/draught/line.rb, line 243 def x_length @x_length = end_point_from_zero.x.abs end
y_length()
click to toggle source
# File lib/draught/line.rb, line 247 def y_length @y_length ||= end_point_from_zero.y.abs end