class Graphdown::Edge::Vector
Public Class Methods
new(x, y)
click to toggle source
# File lib/graphdown/edge.rb, line 90 def initialize(x, y) @v = Matrix[[x, y]] @matrices = [] end
Public Instance Methods
point()
click to toggle source
# File lib/graphdown/edge.rb, line 95 def point @matrices.each { |matrix| @v *= matrix } x, y = @v.row(0).to_a Point.new(x, y) end
rotate(radian)
click to toggle source
# File lib/graphdown/edge.rb, line 110 def rotate(radian) rotation_matrix = Matrix[[Math.cos(radian), Math.sin(radian)], [-Math.sin(radian), Math.cos(radian)]] @matrices << rotation_matrix self end
scale(ratio)
click to toggle source
# File lib/graphdown/edge.rb, line 101 def scale(ratio) unit_vector = @v.row(0).normalize nx, ny = unit_vector.map(&:to_f).to_a scaling_matrix = Matrix[[1 + (ratio - 1) * nx ** 2, (ratio - 1) * nx * ny], [(ratio - 1) * nx * ny, 1 + (ratio - 1) * ny ** 2]] @matrices << scaling_matrix self end