twisty_puzzles 0.0.31 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b1fabe0cc087fdf90da3e0288758f9573378371b0b3158d6a905e0830da21a1
4
- data.tar.gz: 04f15c1397971f33565c89f852571110e13aeff1548d748874a0dc6ca364d64f
3
+ metadata.gz: 66e7a9b86d8d381b95a5f8f81736ce6df3bf121742c5b802dc1197f587ff064b
4
+ data.tar.gz: 21d10876ef99087df6e243a9b405c5272e74a13601fd71a3389a11a2c225905c
5
5
  SHA512:
6
- metadata.gz: b13427c376bc2c583e02860e5834140b9d648ee97f9983906732597ad9a5d57256364231a7c759b775478b7474cf21e1188045a4ecb564e942e0b4e991f7246e
7
- data.tar.gz: 48a547963b89c1c6a56688fdab4c094aec6934954b8555c319ddfde7a1518b787cabd62cf4b39fee37c7de19366fabbcb6debfe6b8ef00c2ee578c48fd4aeb63
6
+ metadata.gz: fa1def58113526fa40421e30650da8fcd5f136947405697fa04e2c62278a618f9efdb7ce7b1a22979e3794aa8e59a9f2b1e2d723627e09567d16adb58fe6c3dd
7
+ data.tar.gz: 95af3315c8fa3036780b9fe70abd2dd1b7afabe42a04c2373a791f3da401f7be1d7dde5ba3201c68b69b25ba7904955496c07855faee617c67367781b4f4b2db
@@ -122,7 +122,7 @@ module TwistyPuzzles
122
122
  end
123
123
 
124
124
  def inspect
125
- "#{self.class}(#{@face_symbols.map(&:to_s).join(', ')})"
125
+ @inspect ||= "#{self.class.name.split('::').last}(#{@face_symbols.map(&:to_s).join(', ')})"
126
126
  end
127
127
 
128
128
  def to_s
@@ -390,7 +390,8 @@ module TwistyPuzzles
390
390
  attr_reader :corresponding_part
391
391
 
392
392
  def inspect
393
- "#{self.class}(#{face_symbol}, #{@corresponding_part.inspect})"
393
+ @inspect ||=
394
+ "#{self.class.name.split('::').last}(#{face_symbol}, #{@corresponding_part.inspect})"
394
395
  end
395
396
 
396
397
  def rotate_by(_number)
@@ -21,6 +21,7 @@ module TwistyPuzzles
21
21
  raise ArgumentError if parts.empty?
22
22
  raise TypeError unless twist.is_a?(Integer)
23
23
  raise ArgumentError if twist.negative?
24
+ raise ArgumentError if twist >= parts.first.rotations.length
24
25
 
25
26
  check_types(parts, Part)
26
27
  check_type_consistency(parts)
@@ -32,13 +33,18 @@ module TwistyPuzzles
32
33
  attr_reader :parts, :twist
33
34
 
34
35
  def eql?(other)
35
- self.class.equal?(other.class) && @parts == other.parts
36
+ self.class.equal?(other.class) && @parts == other.parts && @twist == other.twist
36
37
  end
37
38
 
38
39
  alias == eql?
39
40
 
41
+ def inspect
42
+ @inspect ||=
43
+ "#{self.class.name.split('::').last}(#{@parts.map(&:inspect).join(', ')}#{twist_suffix})"
44
+ end
45
+
40
46
  def hash
41
- @hash ||= ([self.class] + @parts).hash
47
+ @hash ||= [self.class, @parts, @twist].hash
42
48
  end
43
49
 
44
50
  def part_type
@@ -46,15 +52,16 @@ module TwistyPuzzles
46
52
  end
47
53
 
48
54
  def contains_any_part?(parts)
49
- !(@parts & parts).empty?
55
+ parts.any? { |p| contains?(p) }
50
56
  end
51
57
 
52
58
  def to_s
53
- @parts.join(' ')
59
+ @to_s ||= @parts.join(' ')
54
60
  end
55
61
 
56
62
  def to_raw_data
57
- "#{simple_class_name(part_type)}(#{self})"
63
+ @to_raw_data ||=
64
+ "#{simple_class_name(part_type)}(#{self}#{twist_suffix})"
58
65
  end
59
66
 
60
67
  def length
@@ -62,15 +69,15 @@ module TwistyPuzzles
62
69
  end
63
70
 
64
71
  def rotate_by(number)
65
- self.class.new(@parts.rotate(number))
72
+ self.class.new(@parts.rotate(number), @twist)
66
73
  end
67
74
 
68
75
  def map_rotate_by(number)
69
- self.class.new(@parts.map { |p| p.rotate_by(number) })
76
+ self.class.new(@parts.map { |p| p.rotate_by(number) }, @twist)
70
77
  end
71
78
 
72
79
  def <=>(other)
73
- @parts <=> other.parts
80
+ [part_type.name, @parts, @twist] <=> [other.part_type.name, other.parts, other.twist]
74
81
  end
75
82
 
76
83
  def canonicalize
@@ -102,14 +109,22 @@ module TwistyPuzzles
102
109
  end
103
110
 
104
111
  def inverse
105
- self.class.new([@parts[0]] + @parts[1..].reverse)
112
+ inverse_twist = @twist.zero? ? @twist : parts.first.rotations.length - @twist
113
+ self.class.new([@parts[0]] + @parts[1..].reverse, inverse_twist)
106
114
  end
107
115
 
108
116
  def self.from_raw_data(data)
109
- raw_part_type, raw_parts = data.match(/(.*)\((.*)\)/).captures
117
+ raw_part_type, raw_parts, raw_twist = data.match(/^(.*)\((.*?)(?:, (.+))?\)$/).captures
110
118
  part_type = PART_TYPES.find { |p| simple_class_name(p) == raw_part_type }
119
+ twist = raw_twist ? Integer(raw_twist) : 0
111
120
  parts = raw_parts.split.map { |r| part_type.parse(r) }
112
- new(parts)
121
+ new(parts, twist)
122
+ end
123
+
124
+ private
125
+
126
+ def twist_suffix
127
+ @twist.positive? ? ", #{@twist}" : ''
113
128
  end
114
129
 
115
130
  def check_type_consistency(parts)
@@ -7,6 +7,7 @@ require 'twisty_puzzles/reversible_applyable'
7
7
 
8
8
  module TwistyPuzzles
9
9
  # A sticker cycle that can be applied to a cube state.
10
+ # TODO: Deprecate
10
11
  class StickerCycle
11
12
  include ReversibleApplyable
12
13
 
@@ -55,6 +56,7 @@ module TwistyPuzzles
55
56
  end
56
57
 
57
58
  # A set of disjoint sticker cycles that can be applied to a cube state together
59
+ # TODO: Deprecate
58
60
  class StickerCycles
59
61
  include ReversibleApplyable
60
62
 
@@ -64,7 +66,10 @@ module TwistyPuzzles
64
66
  raise TypeError unless c.is_a?(StickerCycle)
65
67
 
66
68
  c.native.coordinates.each do |s|
67
- raise ArgumentError unless affected_set.add?(s)
69
+ unless affected_set.add?(s)
70
+ raise ArgumentError,
71
+ 'There is an intersection between part cycles'
72
+ end
68
73
  end
69
74
  end
70
75
  @cube_size = cube_size
@@ -6,6 +6,7 @@ require 'twisty_puzzles/cube'
6
6
 
7
7
  module TwistyPuzzles
8
8
  # Factory for sticker cycles given part cycles.
9
+ # TODO: Deprecate
9
10
  class StickerCycleFactory
10
11
  include Utils::ArrayHelper
11
12
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwistyPuzzles
4
- VERSION = '0.0.31'
4
+ VERSION = '0.0.35'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twisty_puzzles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.31
4
+ version: 0.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernhard F. Brodowsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-21 00:00:00.000000000 Z
11
+ date: 2021-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize