Class: TwistyPuzzles::SkewbCoordinate

Inherits:
Object
  • Object
show all
Includes:
Comparable, CubeConstants
Defined in:
lib/twisty_puzzles/coordinate.rb

Overview

Coordinate of a sticker on the Skewb.

Constant Summary

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 collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CubeConstants

#chirality_canonical_face_symbol, #opposite_face_symbol, #valid_chirality?

Methods included from Utils::ArrayHelper

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

Constructor Details

#initialize(face, coordinate, native) ⇒ SkewbCoordinate

Returns a new instance of SkewbCoordinate.

Raises:

  • (ArgumentError)


305
306
307
308
309
310
311
312
313
# File 'lib/twisty_puzzles/coordinate.rb', line 305

def initialize(face, coordinate, native)
  raise ArgumentError, "Unsuitable face #{face.inspect}." unless face.is_a?(Face)
  unless coordinate.is_a?(Integer) && coordinate >= 0 && coordinate < SKEWB_STICKERS
    raise ArgumentError
  end

  @coordinate = coordinate
  @native = native
end

Instance Attribute Details

#coordinateObject (readonly)

Returns the value of attribute coordinate.



315
316
317
# File 'lib/twisty_puzzles/coordinate.rb', line 315

def coordinate
  @coordinate
end

#nativeObject (readonly)

Returns the value of attribute native.



315
316
317
# File 'lib/twisty_puzzles/coordinate.rb', line 315

def native
  @native
end

Class Method Details

.corners_on_face(face) ⇒ Object



324
325
326
# File 'lib/twisty_puzzles/coordinate.rb', line 324

def self.corners_on_face(face)
  face.clockwise_corners.map { |c| for_corner(c) }
end

.for_center(face) ⇒ Object



319
320
321
322
# File 'lib/twisty_puzzles/coordinate.rb', line 319

def self.for_center(face)
  native = Native::SkewbCoordinate.for_center(face.face_symbol)
  new(face, 0, native)
end

.for_corner(corner) ⇒ Object



328
329
330
331
# File 'lib/twisty_puzzles/coordinate.rb', line 328

def self.for_corner(corner)
  native = Native::SkewbCoordinate.for_corner(corner.face_symbols)
  new(Face.for_face_symbol(corner.face_symbols.first), 1 + (corner.piece_index % 4), native)
end

Instance Method Details

#<=>(other) ⇒ Object



343
344
345
# File 'lib/twisty_puzzles/coordinate.rb', line 343

def <=>(other)
  @native <=> other.native
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


337
338
339
# File 'lib/twisty_puzzles/coordinate.rb', line 337

def eql?(other)
  @native.eql?(other.native)
end

#faceObject



347
348
349
# File 'lib/twisty_puzzles/coordinate.rb', line 347

def face
  @face ||= Face.for_face_symbol(@native.face)
end

#hashObject



333
334
335
# File 'lib/twisty_puzzles/coordinate.rb', line 333

def hash
  @hash ||= [self.class, @native].hash
end