Sha256: db259484b486b7ac9f157420d4886b8b30894e3a46b59932007773c4d00ef5ce
Contents?: true
Size: 797 Bytes
Versions: 4
Compression:
Stored size: 797 Bytes
Contents
module GridGenerator class Rotator def initialize(angle:, rotation_point:) @angle = angle @matrix = Matrix[ [Math.cos(angle), -1*Math.sin(angle)], [Math.sin(angle), Math.cos(angle)] ] @rotation_point = rotation_point end attr_reader :angle, :matrix, :rotation_point # subtract rotation point to move point towards 0,0, rotate, then add to move back def rotate(obj) return obj if angle == 0 case obj when Matrix (matrix * (obj - rotation_point)) + rotation_point when GridGenerator::Line new_a = rotate(obj.a) new_b = rotate(obj.b) GridGenerator::Line.new(a: new_a, b: new_b) else raise ArgumentError, "Object must be Matrix or Line" end end end end
Version data entries
4 entries across 4 versions & 1 rubygems