Class: TwistyPuzzles::Corner
- Inherits:
-
Part
- Object
- Part
- TwistyPuzzles::Corner
show all
- Defined in:
- lib/twisty_puzzles/cube.rb
Overview
Represents one corner or the position of one corner on the cube.
Constant Summary
collapse
- FACES =
3
- ELEMENTS =
generate_parts
TwistyPuzzles::CubeConstants::ALPHABET_SIZE, TwistyPuzzles::CubeConstants::CHIRALITY_FACE_SYMBOLS, TwistyPuzzles::CubeConstants::FACE_NAMES, TwistyPuzzles::CubeConstants::FACE_SYMBOLS, TwistyPuzzles::CubeConstants::OPPOSITE_FACE_SYMBOLS, TwistyPuzzles::CubeConstants::SKEWB_STICKERS
Instance Attribute Summary
Attributes inherited from Part
#face_symbols, #piece_index
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Part
#<=>, #base_index_on_face, #corresponding_part, #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, max_parseable_face_symbols, min_cube_size, min_parseable_face_symbols, #mirror, parse, #rotate_by, #rotate_by_rotation, #rotate_face_symbol_up, #rotate_face_up, #rotations, #solved_coordinate, #solved_face, #to_s, #turned_equals?
#apply_permutation, #check_types, #find_only, #only, #replace_once, #rotate_out_nils, #turned_equals?
#chirality_canonical_face_symbol, #opposite_face_symbol, #valid_chirality?
Class Method Details
.between_faces(faces) ⇒ Object
606
607
608
|
# File 'lib/twisty_puzzles/cube.rb', line 606
def self.between_faces(faces)
for_face_symbols(faces.map(&:face_symbol))
end
|
.for_face_symbols(face_symbols) ⇒ Object
590
591
592
593
594
595
596
597
598
599
600
|
# File 'lib/twisty_puzzles/cube.rb', line 590
def self.for_face_symbols(face_symbols)
unless face_symbols.length == FACES
raise "Invalid number of face_symbols to create a corner: #{face_symbols.inspect}"
end
if valid?(face_symbols)
for_face_symbols_internal(face_symbols)
else
for_face_symbols_internal([face_symbols[0], face_symbols[2], face_symbols[1]])
end
end
|
.valid?(face_symbols) ⇒ Boolean
610
611
612
|
# File 'lib/twisty_puzzles/cube.rb', line 610
def self.valid?(face_symbols)
face_symbols.combination(2).all? { |e| Edge.valid?(e) } && valid_chirality?(face_symbols)
end
|
.valid_between_faces?(faces) ⇒ Boolean
602
603
604
|
# File 'lib/twisty_puzzles/cube.rb', line 602
def self.valid_between_faces?(faces)
valid?(faces.map(&:face_symbol))
end
|
Instance Method Details
#adjacent_edges ⇒ Object
649
650
651
|
# File 'lib/twisty_puzzles/cube.rb', line 649
def adjacent_edges
@adjacent_edges ||= @face_symbols.combination(2).map { |e| Edge.for_face_symbols(e) }
end
|
#adjacent_faces ⇒ Object
653
654
655
|
# File 'lib/twisty_puzzles/cube.rb', line 653
def adjacent_faces
@adjacent_faces ||= @face_symbols.map { |f| Face.for_face_symbol(f) }
end
|
#base_index_on_other_face(_face, _cube_size, _incarnation_index) ⇒ Object
One index of such a piece on a on a NxN face.
662
663
664
|
# File 'lib/twisty_puzzles/cube.rb', line 662
def base_index_on_other_face(_face, _cube_size, _incarnation_index)
[0, 0]
end
|
#common_edge_with?(other) ⇒ Boolean
639
640
641
|
# File 'lib/twisty_puzzles/cube.rb', line 639
def common_edge_with?(other)
common_faces(other) == 2
end
|
#common_faces(other) ⇒ Object
643
644
645
646
647
|
# File 'lib/twisty_puzzles/cube.rb', line 643
def common_faces(other)
raise TypeError unless other.is_a?(Corner)
(@face_symbols & other.face_symbols).length
end
|
#diagonal_opposite ⇒ Object
630
631
632
633
|
# File 'lib/twisty_puzzles/cube.rb', line 630
def diagonal_opposite
@diagonal_opposite ||=
Corner.for_face_symbols(face_symbols.map { |f| opposite_face_symbol(f) })
end
|
#num_incarnations(cube_size) ⇒ Object
657
658
659
|
# File 'lib/twisty_puzzles/cube.rb', line 657
def num_incarnations(cube_size)
cube_size >= 2 ? 1 : 0
end
|
#rotate_other_face_symbol_up(face_symbol) ⇒ Object
Rotate such that neither the current face symbol nor the given face symbol are at the position of the letter.
618
619
620
621
622
623
624
625
626
627
628
|
# File 'lib/twisty_puzzles/cube.rb', line 618
def rotate_other_face_symbol_up(face_symbol)
index = @face_symbols.index(face_symbol)
raise ArgumentError, "Part #{self} doesn't have face symbol #{face_symbol}." unless index
if index.zero?
raise ArgumentError, "Part #{self} already has face symbol #{face_symbol} up, so " \
"`rotate_other_face_symbol_up(#{face_symbol}) is invalid."
end
rotate_by(3 - index)
end
|
#rotate_other_face_up(face) ⇒ Object
635
636
637
|
# File 'lib/twisty_puzzles/cube.rb', line 635
def rotate_other_face_up(face)
rotate_other_face_symbol_up(face.face_symbol)
end
|