Class: TwistyPuzzles::Wing

Inherits:
Part
  • Object
show all
Extended by:
EdgeLike
Defined in:
lib/twisty_puzzles/cube.rb

Overview

Represents one wing or the position of one wing on the cube.

Constant Summary collapse

FACES =
2
ELEMENTS =
generate_parts

Constants included from CubeConstants

CubeConstants::ALPHABET_SIZE, CubeConstants::CHIRALITY_FACE_SYMBOLS, CubeConstants::FACE_NAMES, CubeConstants::FACE_SYMBOLS, CubeConstants::OPPOSITE_FACE_SYMBOLS, CubeConstants::SKEWB_STICKERS

Instance Attribute Summary

Attributes inherited from Part

#face_symbols, #piece_index

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EdgeLike

valid?

Methods inherited from Part

#<=>, #base_index_on_face, #eql?, exists_on_cube_size?, exists_on_even_cube_sizes?, exists_on_odd_cube_sizes?, #faces, for_face_symbols_internal, for_index, generate_parts, #hash, #initialize, #inspect, max_cube_size, min_parseable_face_symbols, parse, #rotate_by_rotation, #rotate_face_symbol_up, #rotate_face_up, #solved_coordinate, #solved_face, #to_s, #turned_equals?, valid?

Methods included from Utils::ArrayHelper

#apply_permutation, #check_types, #find_only, #only, #replace_once, #rotate_out_nils, #turned_equals?

Methods included from CubeConstants

#chirality_canonical_face_symbol, #opposite_face_symbol, #valid_chirality?

Constructor Details

This class inherits a constructor from TwistyPuzzles::Part

Class Method Details

.for_face_symbols(face_symbols) ⇒ Object



517
518
519
520
521
522
523
524
525
526
# File 'lib/twisty_puzzles/cube.rb', line 517

def self.for_face_symbols(face_symbols)
  # One additional face symbol is usually mentioned for wings.
  raise unless face_symbols.length == FACES || face_symbols.length == FACES + 1

  if face_symbols.length == FACES + 1
    for_corner_face_symbols(face_symbols)
  else
    for_face_symbols_internal(face_symbols)
  end
end

.max_parseable_face_symbolsObject



513
514
515
# File 'lib/twisty_puzzles/cube.rb', line 513

def self.max_parseable_face_symbols
  FACES + 1
end

.min_cube_sizeObject



509
510
511
# File 'lib/twisty_puzzles/cube.rb', line 509

def self.min_cube_size
  4
end

Instance Method Details

#base_index_on_other_face(face, _cube_size, incarnation_index) ⇒ Object

One index of such a piece on a on a NxN face.



579
580
581
582
583
# File 'lib/twisty_puzzles/cube.rb', line 579

def base_index_on_other_face(face, _cube_size, incarnation_index)
  inverse = face.piece_index.even?
  coordinates = [0, 1 + incarnation_index]
  inverse ? coordinates.reverse : coordinates
end

#corresponding_partObject



555
556
557
558
559
560
561
562
563
564
# File 'lib/twisty_puzzles/cube.rb', line 555

def corresponding_part
  @corresponding_part ||=
    begin
      face_symbol =
        find_only(FACE_SYMBOLS) do |c|
          !@face_symbols.include?(c) && Corner.valid?(@face_symbols + [c])
        end
      Corner.for_face_symbols(@face_symbols + [face_symbol])
    end
end

#mirror(normal_face) ⇒ Object

Wings are weird to mirror because the main sticker changes.



547
548
549
550
551
# File 'lib/twisty_puzzles/cube.rb', line 547

def mirror(normal_face)
  mirrored_face_symbols = corresponding_part.faces.map { |f| f.mirror(normal_face) }
  transformed_face_symbols = mirrored_face_symbols[..-2].reverse + [mirrored_face_symbols[-1]]
  self.class.for_face_symbols(transformed_face_symbols.map(&:face_symbol))
end

#num_incarnations(cube_size) ⇒ Object



574
575
576
# File 'lib/twisty_puzzles/cube.rb', line 574

def num_incarnations(cube_size)
  cube_size > 3 ? (cube_size / 2) - 1 : 0
end

#rotate_by(_number) ⇒ Object



570
571
572
# File 'lib/twisty_puzzles/cube.rb', line 570

def rotate_by(_number)
  self
end

#rotationsObject



566
567
568
# File 'lib/twisty_puzzles/cube.rb', line 566

def rotations
  [self]
end