Sha256: 13dcb174eed8ae1820bff87afdfbd892a9942e1456ac14fba2f4d998e004a25a

Contents?: true

Size: 794 Bytes

Versions: 1

Compression:

Stored size: 794 Bytes

Contents

require_relative 'common'
require_relative '../point'

module Draught
  module Transformations
    class Affine
      include Common

      attr_reader :transformation_matrix

      def initialize(transformation_matrix)
        @transformation_matrix = transformation_matrix
      end

      def call(point)
        Point.from_matrix(transformation_matrix * point.to_matrix)
      end

      def affine?
        true
      end

      def ==(other)
        other.respond_to?(:transformation_matrix) && other.transformation_matrix == transformation_matrix
      end

      def coalesce(other)
        raise TypeError, "other must be a matrix-based Affine transform" unless other.affine?
        self.class.new(other.transformation_matrix * self.transformation_matrix)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
draught-0.1.0 lib/draught/transformations/affine.rb