twisty_puzzles 0.0.30 → 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0921468026dd18bfa906d172939b0856c6d98081eff7fe2013e168daa66f090
4
- data.tar.gz: 91ef593d14bc93213d6703d508c392ba0ca24d05cd20bfc6936391f0afb7a2ad
3
+ metadata.gz: d97ccbff9f193fbb7406de38b04d408f48c2cf58c5a55bc6bb731b3585abc277
4
+ data.tar.gz: 987b9331d652a8e8e0637f0382a63ce80eb1378c87853b595ade065f77eb9a76
5
5
  SHA512:
6
- metadata.gz: 5be09b84d72b7c36723fa4003fdb3ec7a8f068ae5c95e6e10956468f74c3730acb22de0e06b388a42b34c2b2af04bf62bf3cdedd5cf5d472fca70750f7735dd6
7
- data.tar.gz: a842caaa9cebd5cdadc38cbf60c22439b49b1d923682fbfdd06a69ea92ccf3916c45bbe4c6c317f9fcc6b37d8d41fe81e9443717cf45c009548f474ad2c00142
6
+ metadata.gz: 00e6a30b9753bc955762a04858bcc88926daaaa6f7485453ae1e90c99011cb6b7b481e79f18947871f6fcdd4f3c2126653238b700c3bc970476e6263a1704e7f
7
+ data.tar.gz: 5d9f333c879419b5a9ec1e4a62dd70fb3c33f4bd1102578ad191113ea1e23a2ba073be4ecc0ce8c4827a4b427885463113b3bb0291b927f9c9bef183d054a6c6
@@ -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, @parts, @twist] <=> [other.part_type, other.parts, other.twist]
74
81
  end
75
82
 
76
83
  def canonicalize
@@ -94,7 +101,7 @@ module TwistyPuzzles
94
101
 
95
102
  index = @parts.find_index { |p| p.turned_equals?(part) }
96
103
  map_rotate_by_number = @parts[index].rotations.index(part)
97
- rotate_by(@parts.length - index).map_rotate_by(map_rotate_by_number)
104
+ rotate_by(index).map_rotate_by(map_rotate_by_number)
98
105
  end
99
106
 
100
107
  def equivalent?(other)
@@ -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.30'
4
+ VERSION = '0.0.34'
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.30
4
+ version: 0.0.34
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-20 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