Class: TwistyPuzzles::AlgorithmTransformation

Inherits:
Object
  • Object
show all
Defined in:
lib/twisty_puzzles/algorithm_transformation.rb

Overview

A transformation consisting of mirroring and rotating that can be applied to an algorithm.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rotation, mirror, mirror_normal_face) ⇒ AlgorithmTransformation

Returns a new instance of AlgorithmTransformation.



9
10
11
12
13
# File 'lib/twisty_puzzles/algorithm_transformation.rb', line 9

def initialize(rotation, mirror, mirror_normal_face)
  @rotation = rotation
  @mirror = mirror
  @mirror_normal_face = mirror_normal_face
end

Instance Attribute Details

#mirrorObject (readonly)

Returns the value of attribute mirror.



15
16
17
# File 'lib/twisty_puzzles/algorithm_transformation.rb', line 15

def mirror
  @mirror
end

#mirror_normal_faceObject (readonly)

Returns the value of attribute mirror_normal_face.



15
16
17
# File 'lib/twisty_puzzles/algorithm_transformation.rb', line 15

def mirror_normal_face
  @mirror_normal_face
end

#rotationObject (readonly)

Returns the value of attribute rotation.



15
16
17
# File 'lib/twisty_puzzles/algorithm_transformation.rb', line 15

def rotation
  @rotation
end

Class Method Details

.around_face(face) ⇒ Object

Returns algorithm transformations that mirror an algorithm and rotate it around a face.



27
28
29
30
31
32
33
# File 'lib/twisty_puzzles/algorithm_transformation.rb', line 27

def self.around_face(face)
  around_face_rotations = CubeDirection::ALL_DIRECTIONS.map { |d| Rotation.new(face, d) }
  mirror_normal_face = face.neighbors.first
  around_face_rotations.product([true, false]).map do |r, m|
    AlgorithmTransformation.new(r, m, mirror_normal_face)
  end
end

.around_face_without_identity(face) ⇒ Object



35
36
37
# File 'lib/twisty_puzzles/algorithm_transformation.rb', line 35

def self.around_face_without_identity(face)
  around_face(face).reject(&:identity?)
end

Instance Method Details

#identity?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/twisty_puzzles/algorithm_transformation.rb', line 22

def identity?
  rotation.identity? && !mirror
end

#transformed(algorithm) ⇒ Object



17
18
19
20
# File 'lib/twisty_puzzles/algorithm_transformation.rb', line 17

def transformed(algorithm)
  algorithm = algorithm.mirror(mirror_normal_face) if mirror
  algorithm.rotate_by(rotation)
end