Class: TwistyPuzzles::StickerCycles
- Inherits:
-
Object
- Object
- TwistyPuzzles::StickerCycles
- Includes:
- ReversibleApplyable
- Defined in:
- lib/twisty_puzzles/sticker_cycle.rb
Overview
A set of disjoint sticker cycles that can be applied to a cube state together TODO: Deprecate
Instance Attribute Summary collapse
-
#cube_size ⇒ Object
readonly
Returns the value of attribute cube_size.
-
#sticker_cycles ⇒ Object
readonly
Returns the value of attribute sticker_cycles.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #apply_to(cube_state) ⇒ Object
-
#initialize(cube_size, sticker_cycles) ⇒ StickerCycles
constructor
A new instance of StickerCycles.
- #inverse ⇒ Object
Methods included from ReversibleApplyable
#apply_temporarily_to, #apply_to_dupped
Constructor Details
#initialize(cube_size, sticker_cycles) ⇒ StickerCycles
Returns a new instance of StickerCycles.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/twisty_puzzles/sticker_cycle.rb', line 63 def initialize(cube_size, sticker_cycles) affected_set = Set[] sticker_cycles.each do |c| raise TypeError unless c.is_a?(StickerCycle) c.native.coordinates.each do |s| unless affected_set.add?(s) raise ArgumentError, 'There is an intersection between part cycles' end end end @cube_size = cube_size @sticker_cycles = sticker_cycles end |
Instance Attribute Details
#cube_size ⇒ Object (readonly)
Returns the value of attribute cube_size.
79 80 81 |
# File 'lib/twisty_puzzles/sticker_cycle.rb', line 79 def cube_size @cube_size end |
#sticker_cycles ⇒ Object (readonly)
Returns the value of attribute sticker_cycles.
79 80 81 |
# File 'lib/twisty_puzzles/sticker_cycle.rb', line 79 def sticker_cycles @sticker_cycles end |
Instance Method Details
#+(other) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/twisty_puzzles/sticker_cycle.rb', line 88 def +(other) raise TypeError unless other.is_a?(StickerCycles) raise ArgumentError unless @cube_size == other.cube_size StickerCycles.new(@cube_size, @sticker_cycles + other.sticker_cycles) end |
#apply_to(cube_state) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/twisty_puzzles/sticker_cycle.rb', line 81 def apply_to(cube_state) raise TypeError unless cube_state.is_a?(CubeState) raise ArgumentError unless cube_state.n == @cube_size @sticker_cycles.each { |c| c.apply_to(cube_state) } end |
#inverse ⇒ Object
95 96 97 |
# File 'lib/twisty_puzzles/sticker_cycle.rb', line 95 def inverse StickerCycles.new(@cube_size, @sticker_cycles.map(&:inverse)) end |