gosling 2.0.0 → 2.0.1

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
  SHA1:
3
- metadata.gz: ea892a020a95cbff0d56b2410eed22dcdffa0816
4
- data.tar.gz: 9ad565fa00e58440ad245ec0ceae7479ab6c3900
3
+ metadata.gz: 9e6f0f8aedff9ad18db82e215fb3228fd59b79be
4
+ data.tar.gz: 13b4208f4759774469e045e5cdfaa6d4697343b0
5
5
  SHA512:
6
- metadata.gz: c45e93330e44318c58d2a76456d836366d7a9dc77ecd2c70ab08c1762ac6d92ca5cd20f257c367212759c03703e0387d7809ba08e88f48a3e3f7ecf8fa0ad500
7
- data.tar.gz: 4711c9d648c83e8d26b5dfdf7b2bd7266db076500ad21c85ad8b1669fe26785efaf7294a48f6865609ee2f5d4f6b93e8256f7ac926686990cfdde2db41d308ea
6
+ metadata.gz: 143ae71d33d54592e6a45624c96f7083f419970110dd09a4763fd7f20f3d55abb1cc0c28b0226a36c55ad2775a1ac846118f57f05580d693a96b0e7a4bf83c85
7
+ data.tar.gz: e542b0689382e52d4a2e430ba9a389cd99f12a37f261fec7468fbad3afc927b2743301cd820da451ac93635bfd3e0ec74e06384aa2f04477f0709adda717ca89
data/lib/gosling/actor.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'transform.rb'
1
+ require_relative 'transformable.rb'
2
2
 
3
3
  require 'gosu'
4
4
 
@@ -26,7 +26,9 @@ module Gosling
26
26
  # The behavior of inheritance can modified by setting various properties. Read on for more details.
27
27
  #
28
28
  class Actor
29
- attr_reader :transform, :parent, :children, :window
29
+ include Transformable
30
+
31
+ attr_reader :parent, :children, :window
30
32
 
31
33
  ##
32
34
  # If set to true, this Actor will be drawn to screen. If false, it will be skipped. The default is true.
@@ -68,8 +70,8 @@ module Gosling
68
70
  # a Gosu::Window to be used when rendering.
69
71
  #
70
72
  def initialize(window)
73
+ super()
71
74
  @window = window
72
- @transform = Transform.new
73
75
  @parent = nil
74
76
  @children = []
75
77
  @is_visible = true
@@ -126,118 +128,6 @@ module Gosling
126
128
  @children.include?(child)
127
129
  end
128
130
 
129
- ##
130
- # Wrapper method. Returns this Actor's x position in relative space. See Transform#translation.
131
- #
132
- def x
133
- @transform.translation.x
134
- end
135
-
136
- ##
137
- # Wrapper method. Sets this Actor's x position in relative space. See Transform#translation.
138
- #
139
- def x=(val)
140
- @transform.translation = val, @transform.translation.y
141
- end
142
-
143
- ##
144
- # Wrapper method. Returns this Actor's y position in relative space. See Transform#translation.
145
- #
146
- def y
147
- @transform.translation.y
148
- end
149
-
150
- ##
151
- # Wrapper method. Sets this Actor's y position in relative space. See Transform#translation.
152
- #
153
- def y=(val)
154
- @transform.translation = @transform.translation.x, val
155
- end
156
-
157
- ##
158
- # Wrapper method. Returns this Actor's position in relative space as a Snow::Vec3. See Transform#translation.
159
- #
160
- def pos
161
- @transform.translation
162
- end
163
-
164
- ##
165
- # Wrapper method. Sets this Actor's position in relative space. See Transform#translation.
166
- #
167
- def pos=(val)
168
- @transform.translation = val
169
- end
170
-
171
- ##
172
- # Wrapper method. Returns the x component of the centerpoint of this Actor. See Transform#center.
173
- #
174
- def center_x
175
- @transform.center.x
176
- end
177
-
178
- ##
179
- # Wrapper method. Sets the x component of the centerpoint of this Actor. See Transform#center.
180
- #
181
- def center_x=(val)
182
- @transform.center = val, @transform.center.y
183
- end
184
-
185
- ##
186
- # Wrapper method. Returns the y component of the centerpoint of this Actor. See Transform#center.
187
- #
188
- def center_y
189
- @transform.center.y
190
- end
191
-
192
- ##
193
- # Wrapper method. Sets the y component of the centerpoint of this Actor. See Transform#center.
194
- #
195
- def center_y=(val)
196
- @transform.center = @transform.center.x, val
197
- end
198
-
199
- ##
200
- # Wrapper method. Returns the x component of the scaling of this Actor. See Transform#scale.
201
- #
202
- def scale_x
203
- @transform.scale.x
204
- end
205
-
206
- ##
207
- # Wrapper method. Sets the x component of the scaling of this Actor. See Transform#scale.
208
- #
209
- def scale_x=(val)
210
- @transform.scale = val, @transform.scale.y
211
- end
212
-
213
- ##
214
- # Wrapper method. Returns the y component of the scaling of this Actor. See Transform#scale.
215
- #
216
- def scale_y
217
- @transform.scale.y
218
- end
219
-
220
- ##
221
- # Wrapper method. Sets the y component of the scaling of this Actor. See Transform#scale.
222
- #
223
- def scale_y=(val)
224
- @transform.scale = @transform.scale.x, val
225
- end
226
-
227
- ##
228
- # Wrapper method. Returns this Actor's rotation in radians. See Transform#rotation.
229
- #
230
- def rotation
231
- @transform.rotation
232
- end
233
-
234
- ##
235
- # Wrapper method. Sets this Actor's rotation in radians. See Transform#rotation.
236
- #
237
- def rotation=(val)
238
- @transform.rotation = val
239
- end
240
-
241
131
  ##
242
132
  # Calls #render on this Actor, drawing it to the screen if #is_visible is set to true (the default).
243
133
  #
@@ -250,7 +140,7 @@ module Gosling
250
140
  #
251
141
  def draw(matrix = nil)
252
142
  matrix ||= Snow::Mat3.new
253
- transform = matrix * @transform.to_matrix
143
+ transform = to_matrix * matrix
254
144
  render(transform) if @is_visible
255
145
  if @are_children_visible
256
146
  @children.each { |child| child.draw(transform) }
@@ -321,20 +211,20 @@ module Gosling
321
211
  def get_global_transform(out = nil)
322
212
  if parent
323
213
  out ||= Snow::Mat3.new
324
- @transform.to_matrix.multiply(parent.get_global_transform, out)
214
+ to_matrix.multiply(parent.get_global_transform, out)
325
215
  out
326
216
  else
327
- @transform.to_matrix
217
+ to_matrix
328
218
  end
329
219
  end
330
220
 
331
221
  ##
332
222
  # Returns the global x/y position of this actor (where it is relative to its root ancestor). This value is calculated
333
- # using the Actor's center (see Transform#center).
223
+ # using the Actor's center (see Transformable#center).
334
224
  #
335
225
  def get_global_position
336
226
  tf = get_global_transform
337
- Transform.transform_point(tf, @transform.center)
227
+ Transformable.transform_point(tf, center)
338
228
  end
339
229
 
340
230
  ##
@@ -4,7 +4,7 @@ require_relative 'collision.rb'
4
4
  module Gosling
5
5
  ##
6
6
  # Represents an Actor with a circular shape, defined by a mutable radius. The circle is rendered relative to the
7
- # Circle's center (see Transform#center).
7
+ # Circle's center (see Transformable#center).
8
8
  #
9
9
  class Circle < Actor
10
10
  ##
@@ -52,7 +52,7 @@ module Gosling
52
52
  local_vertices = (0...RENDER_VERTEX_COUNT).map do |i|
53
53
  get_point_at_angle(Math::PI * 2 * i / RENDER_VERTEX_COUNT)
54
54
  end
55
- global_vertices = local_vertices.map { |v| Transform.transform_point(matrix, v) }
55
+ global_vertices = local_vertices.map { |v| Transformable.transform_point(matrix, v) }
56
56
  i = 2
57
57
  while i < global_vertices.length
58
58
  v0 = global_vertices[0]
@@ -137,7 +137,7 @@ module Gosling
137
137
  global_tf = shape.get_global_transform
138
138
  local_axis = global_tf.inverse * Snow::Vec3[axis[0], axis[1], 0]
139
139
  v = shape.get_point_at_angle(Math.atan2(local_axis[1], local_axis[0]))
140
- [v, v * -1].map { |vertex| Transform.transform_point(global_tf, vertex) }
140
+ [v, v * -1].map { |vertex| Transformable.transform_point(global_tf, vertex) }
141
141
  else
142
142
  shape.get_global_vertices
143
143
  end
@@ -48,7 +48,7 @@ module Gosling
48
48
  #
49
49
  def get_global_vertices
50
50
  tf = get_global_transform
51
- @vertices.map { |v| Transform.transform_point(tf, v) }
51
+ @vertices.map { |v| Transformable.transform_point(tf, v) }
52
52
  end
53
53
 
54
54
  ##
@@ -62,7 +62,7 @@ module Gosling
62
62
 
63
63
  def render(matrix)
64
64
  type_check(matrix, Snow::Mat3)
65
- global_vertices = @vertices.map { |v| Transform.transform_point(matrix, v) }
65
+ global_vertices = @vertices.map { |v| Transformable.transform_point(matrix, v) }
66
66
  i = 2
67
67
  while i < global_vertices.length
68
68
  v0 = global_vertices[0]
@@ -34,7 +34,7 @@ module Gosling
34
34
  private
35
35
 
36
36
  def render(matrix)
37
- global_vertices = @vertices.map { |v| Transform.transform_point(matrix, v) }
37
+ global_vertices = @vertices.map { |v| Transformable.transform_point(matrix, v) }
38
38
  @image.draw_as_quad(
39
39
  global_vertices[0][0].to_f, global_vertices[0][1].to_f, @color,
40
40
  global_vertices[1][0].to_f, global_vertices[1][1].to_f, @color,
@@ -8,7 +8,7 @@ module Gosling
8
8
  # A helper class for performing vector transforms in 2D space. Relies heavily on the Vec3 and Mat3 classes of the
9
9
  # SnowMath gem to remain performant.
10
10
  #
11
- class Transform
11
+ module Transformable
12
12
  ##
13
13
  # Wraps Math.sin to produce rationals instead of floats. Common values are returned quickly from a lookup table.
14
14
  #
@@ -54,7 +54,8 @@ module Gosling
54
54
  attr_reader :rotation
55
55
 
56
56
  ##
57
- # Creates a new transform object with no transformations (identity matrix).
57
+ # Initializes this Transformable to have no transformations (identity matrix).
58
+ #
58
59
  def initialize
59
60
  @center = Snow::Vec3[0.to_r, 0.to_r, 1.to_r]
60
61
  @scale = Snow::Vec2[1.to_r, 1.to_r]
@@ -77,21 +78,64 @@ module Gosling
77
78
  # Returns a duplicate of the center Vec3 (@center is read-only).
78
79
  #
79
80
  def center
80
- @center.dup
81
+ @center.dup.freeze
82
+ end
83
+
84
+ ##
85
+ # Returns the x component of the centerpoint of this Transformable. See Transformable#center.
86
+ #
87
+ def center_x
88
+ @center.x
89
+ end
90
+
91
+ ##
92
+ # Returns the y component of the centerpoint of this Transformable. See Transformable#center.
93
+ #
94
+ def center_y
95
+ @center.y
81
96
  end
82
97
 
83
98
  ##
84
99
  # Returns a duplicate of the scale Vec2 (@scale is read-only).
85
100
  #
86
101
  def scale
87
- @scale.dup
102
+ @scale.dup.freeze
103
+ end
104
+
105
+ ##
106
+ # Returns the x component of the scaling of this Transformable. See Transformable#scale.
107
+ #
108
+ def scale_x
109
+ @scale.x
110
+ end
111
+
112
+ ##
113
+ # Returns the y component of the scaling of this Transformable. See Transformable#scale.
114
+ #
115
+ def scale_y
116
+ @scale.y
88
117
  end
89
118
 
90
119
  ##
91
120
  # Returns a duplicate of the translation Vec3 (@translation is read-only).
92
121
  #
93
122
  def translation
94
- @translation.dup
123
+ @translation.dup.freeze
124
+ end
125
+ alias :pos :translation
126
+
127
+ ##
128
+ # Returns this Transformable's x position in relative space. See Transformable#translation.
129
+ #
130
+ def x
131
+ @translation.x
132
+ end
133
+
134
+ ##
135
+ # Returns this Transformable's y position in relative space. See Transformable#translation.
136
+ #
137
+ def y
138
+ @translation.y
95
139
  end
96
140
 
97
141
  ##
@@ -137,6 +181,24 @@ module Gosling
137
181
  end
138
182
  alias :set_center :center=
139
183
 
184
+ ##
185
+ # Sets the x component of the centerpoint of this Transformable. See Transformable#center.
186
+ #
187
+ def center_x=(val)
188
+ type_check(val, Numeric)
189
+ @center.x = val
190
+ @center_is_dirty = @is_dirty = true
191
+ end
192
+
193
+ ##
194
+ # Sets the y component of the centerpoint of this Transformable. See Transformable#center.
195
+ #
196
+ def center_y=(val)
197
+ type_check(val, Numeric)
198
+ @center.y = val
199
+ @center_is_dirty = @is_dirty = true
200
+ end
201
+
140
202
  ##
141
203
  # Sets this transform's x/y scaling. A scale value of [1, 1] results in no scaling. Larger values make a shape bigger,
142
204
  # while smaller values will make it smaller. Great for shrinking/growing animations, or to zoom the camera in/out.
@@ -169,6 +231,24 @@ module Gosling
169
231
  end
170
232
  alias :set_scale :scale=
171
233
 
234
+ ##
235
+ # Wrapper method. Sets the x component of the scaling of this Actor. See Transformable#scale.
236
+ #
237
+ def scale_x=(val)
238
+ type_check(val, Numeric)
239
+ @scale.x = val
240
+ @scale_is_dirty = @is_dirty = true
241
+ end
242
+
243
+ ##
244
+ # Wrapper method. Sets the y component of the scaling of this Actor. See Transformable#scale.
245
+ #
246
+ def scale_y=(val)
247
+ type_check(val, Numeric)
248
+ @scale.y = val
249
+ @scale_is_dirty = @is_dirty = true
250
+ end
251
+
172
252
  ##
173
253
  # Sets this transform's rotation in radians. A value of 0 results in no rotation. Great for spinning animations, or
174
254
  # rotating the player's camera view.
@@ -214,6 +294,25 @@ module Gosling
214
294
  @translate_is_dirty = @is_dirty = true
215
295
  end
216
296
  alias :set_translation :translation=
297
+ alias :pos= :translation=
298
+
299
+ ##
300
+ # Sets this Transformable's x position in relative space. See Transformable#translation.
301
+ #
302
+ def x=(val)
303
+ type_check(val, Numeric)
304
+ @translation.x = val
305
+ @translate_is_dirty = @is_dirty = true
306
+ end
307
+
308
+ ##
309
+ # Sets this Transformable's y position in relative space. See Transformable#translation.
310
+ #
311
+ def y=(val)
312
+ type_check(val, Numeric)
313
+ @translation.y = val
314
+ @translate_is_dirty = @is_dirty = true
315
+ end
217
316
 
218
317
  ##
219
318
  # Returns a Snow::Mat3 which combines our current center, scale, rotation, and translation into a single transform
@@ -243,7 +342,7 @@ module Gosling
243
342
 
244
343
  ##
245
344
  # Transforms a Vec3 using the provided Mat3 transform and returns the result as a new Vec3. This is the
246
- # opposite of Transform.untransform_point.
345
+ # opposite of Transformable.untransform_point.
247
346
  #
248
347
  def self.transform_point(mat, v)
249
348
  type_check(mat, Snow::Mat3)
@@ -255,15 +354,15 @@ module Gosling
255
354
 
256
355
  ##
257
356
  # Applies all of our transformations to the point, returning the resulting point as a new Vec3. This is the opposite
258
- # of Transform#untransform_point.
357
+ # of Transformable#untransform_point.
259
358
  #
260
359
  def transform_point(v)
261
- Transform.transform_point(to_matrix, v)
360
+ Transformable.transform_point(to_matrix, v)
262
361
  end
263
362
 
264
363
  ##
265
364
  # Transforms a Vec3 using the inverse of the provided Mat3 transform and returns the result as a new Vec3. This
266
- # is the opposite of Transform.transform_point.
365
+ # is the opposite of Transformable.transform_point.
267
366
  #
268
367
  def self.untransform_point(mat, v)
269
368
  type_check(mat, Snow::Mat3)
@@ -279,10 +378,10 @@ module Gosling
279
378
 
280
379
  ##
281
380
  # Applies the inverse of all of our transformations to the point, returning the resulting point as a new Vec3. This
282
- # is the opposite of Transform#transform_point.
381
+ # is the opposite of Transformable#transform_point.
283
382
  #
284
383
  def untransform_point(v)
285
- Transform.untransform_point(to_matrix, v)
384
+ Transformable.untransform_point(to_matrix, v)
286
385
  end
287
386
 
288
387
  private
@@ -306,10 +405,10 @@ module Gosling
306
405
  def update_rotate_matrix
307
406
  return unless @rotate_is_dirty || @rotate_mat.nil?
308
407
  @rotate_mat ||= Snow::Mat3.new
309
- @rotate_mat[0] = Transform.rational_cos(@rotation)
310
- @rotate_mat[1] = Transform.rational_sin(@rotation)
311
- @rotate_mat[3] = -Transform.rational_sin(@rotation)
312
- @rotate_mat[4] = Transform.rational_cos(@rotation)
408
+ @rotate_mat[0] = Transformable.rational_cos(@rotation)
409
+ @rotate_mat[1] = Transformable.rational_sin(@rotation)
410
+ @rotate_mat[3] = -Transformable.rational_sin(@rotation)
411
+ @rotate_mat[4] = Transformable.rational_cos(@rotation)
313
412
  @rotate_is_dirty = false
314
413
  end
315
414
 
@@ -3,5 +3,5 @@
3
3
  # MINOR version when you add functionality in a backwards-compatible manner, and
4
4
  # PATCH version when you make backwards-compatible bug fixes.
5
5
  module Gosling
6
- VERSION = '2.0.0'
6
+ VERSION = '2.0.1'
7
7
  end
data/spec/actor_spec.rb CHANGED
@@ -20,7 +20,7 @@ describe Gosling::Actor do
20
20
  end
21
21
 
22
22
  it 'has a transform' do
23
- expect(@read_only_actor.transform).to be_instance_of(Gosling::Transform)
23
+ expect(@read_only_actor).to be_kind_of(Gosling::Transformable)
24
24
  end
25
25
 
26
26
  it 'can have a parent' do
@@ -105,51 +105,6 @@ describe Gosling::Actor do
105
105
  end
106
106
  end
107
107
 
108
- it 'has shortcut methods for getting its x/y position' do
109
- expect(@read_only_actor.x).to be_kind_of(Numeric)
110
- expect(@read_only_actor.y).to be_kind_of(Numeric)
111
- end
112
-
113
- it 'has shortcut methods for setting its x/y position' do
114
- @read_only_actor.x = 13
115
- @read_only_actor.y = -7
116
- expect(@read_only_actor.x).to be == 13
117
- expect(@read_only_actor.y).to be == -7
118
- end
119
-
120
- it 'has shortcut methods for getting its x/y centerpoint' do
121
- expect(@read_only_actor.center_x).to be_kind_of(Numeric)
122
- expect(@read_only_actor.center_y).to be_kind_of(Numeric)
123
- end
124
-
125
- it 'has shortcut methods for setting its x/y centerpoint' do
126
- @read_only_actor.center_x = 5
127
- @read_only_actor.center_y = 15
128
- expect(@read_only_actor.center_x).to be == 5
129
- expect(@read_only_actor.center_y).to be == 15
130
- end
131
-
132
- it 'has shortcut methods for getting its x/y scaling' do
133
- expect(@read_only_actor.scale_x).to be_kind_of(Numeric)
134
- expect(@read_only_actor.scale_y).to be_kind_of(Numeric)
135
- end
136
-
137
- it 'has shortcut methods for setting its x/y scaling' do
138
- @read_only_actor.scale_x = 2
139
- @read_only_actor.scale_y = 3
140
- expect(@read_only_actor.scale_x).to be == 2
141
- expect(@read_only_actor.scale_y).to be == 3
142
- end
143
-
144
- it 'has a shortcut method for getting its rotation' do
145
- expect(@read_only_actor.rotation).to be_kind_of(Numeric)
146
- end
147
-
148
- it 'has a shortcut method for setting its rotation' do
149
- @read_only_actor.rotation = Math::PI
150
- expect(@read_only_actor.rotation).to be == Math::PI
151
- end
152
-
153
108
  it 'has a visibility flag' do
154
109
  actor = Gosling::Actor.new(@window)
155
110
  actor.is_visible = true
@@ -253,9 +208,9 @@ describe Gosling::Actor do
253
208
  0, 3, 0,
254
209
  0, 0, 1
255
210
  ]
256
- result_mat = parameter_mat * self_mat
211
+ result_mat = self_mat * parameter_mat
257
212
 
258
- allow(@draw_actor.transform).to receive(:to_matrix).and_return(self_mat)
213
+ allow(@draw_actor).to receive(:to_matrix).and_return(self_mat)
259
214
 
260
215
  expect(@child1).to receive(:draw).with(result_mat).once
261
216
  expect(@child2).to receive(:draw).with(result_mat).once
@@ -502,7 +457,7 @@ describe Gosling::Actor do
502
457
  rotated_view.add_child(translated_view)
503
458
  translated_view.add_child(@parent)
504
459
 
505
- expected = @parent.transform.to_matrix * translated_view.transform.to_matrix * rotated_view.transform.to_matrix * scaled_view.transform.to_matrix * centered_view.transform.to_matrix
460
+ expected = @parent.to_matrix * translated_view.to_matrix * rotated_view.to_matrix * scaled_view.to_matrix * centered_view.to_matrix
506
461
 
507
462
  result = @parent.get_global_transform
508
463
  expect(result).to be == expected
@@ -1,6 +1,10 @@
1
1
  describe Gosling::ImageLibrary do
2
+ before(:all) do
3
+ @test_image_path = File.join(File.dirname(__FILE__), "images/key.png")
4
+ end
5
+
2
6
  it "returns a Gosu:Image reference when given a filename" do
3
- expect(Gosling::ImageLibrary.get("C:/Users/Ben/Pictures/icons/me_64.png")).to be_instance_of(Gosu::Image)
7
+ expect(Gosling::ImageLibrary.get(@test_image_path)).to be_instance_of(Gosu::Image)
4
8
  end
5
9
 
6
10
  it "raises an argument error if the file does not exist" do
@@ -8,8 +12,8 @@ describe Gosling::ImageLibrary do
8
12
  end
9
13
 
10
14
  it "does not create a new Gosu:Image if it already has one cached" do
11
- image_a = Gosling::ImageLibrary.get("C:/Users/Ben/Pictures/icons/me_64.png")
12
- image_b = Gosling::ImageLibrary.get("C:/Users/Ben/Pictures/icons/me_64.png")
15
+ image_a = Gosling::ImageLibrary.get(@test_image_path)
16
+ image_b = Gosling::ImageLibrary.get(@test_image_path)
13
17
  expect(image_a).to be == image_b
14
18
  end
15
19
  end
data/spec/sprite_spec.rb CHANGED
@@ -33,6 +33,8 @@ describe Gosling::Sprite do
33
33
  it 'automatically updates our width and height' do
34
34
  expect(@image_sprite.width).to be == @image.width
35
35
  expect(@image_sprite.height).to be == @image.height
36
+ expect(@image_sprite.width).to be_kind_of(Numeric)
37
+ expect(@image_sprite.height).to be_kind_of(Numeric)
36
38
  end
37
39
  end
38
40
 
@@ -1,6 +1,10 @@
1
- describe Gosling::Transform do
1
+ class TransformableThing
2
+ include Gosling::Transformable
3
+ end
4
+
5
+ describe Gosling::Transformable do
2
6
  before(:all) do
3
- @read_only_tf = Gosling::Transform.new
7
+ @read_only_tf = TransformableThing.new
4
8
  end
5
9
 
6
10
  it 'has a center' do
@@ -19,9 +23,54 @@ describe Gosling::Transform do
19
23
  expect(@read_only_tf.translation).to be_instance_of(Snow::Vec3)
20
24
  end
21
25
 
26
+ it 'has methods for getting its x/y position' do
27
+ expect(@read_only_tf.x).to be_kind_of(Numeric)
28
+ expect(@read_only_tf.y).to be_kind_of(Numeric)
29
+ end
30
+
31
+ it 'has methods for setting its x/y position' do
32
+ @read_only_tf.x = 13
33
+ @read_only_tf.y = -7
34
+ expect(@read_only_tf.x).to be == 13
35
+ expect(@read_only_tf.y).to be == -7
36
+ end
37
+
38
+ it 'has methods for getting its x/y centerpoint' do
39
+ expect(@read_only_tf.center_x).to be_kind_of(Numeric)
40
+ expect(@read_only_tf.center_y).to be_kind_of(Numeric)
41
+ end
42
+
43
+ it 'has methods for setting its x/y centerpoint' do
44
+ @read_only_tf.center_x = 5
45
+ @read_only_tf.center_y = 15
46
+ expect(@read_only_tf.center_x).to be == 5
47
+ expect(@read_only_tf.center_y).to be == 15
48
+ end
49
+
50
+ it 'has methods for getting its x/y scaling' do
51
+ expect(@read_only_tf.scale_x).to be_kind_of(Numeric)
52
+ expect(@read_only_tf.scale_y).to be_kind_of(Numeric)
53
+ end
54
+
55
+ it 'has methods for setting its x/y scaling' do
56
+ @read_only_tf.scale_x = 2
57
+ @read_only_tf.scale_y = 3
58
+ expect(@read_only_tf.scale_x).to be == 2
59
+ expect(@read_only_tf.scale_y).to be == 3
60
+ end
61
+
62
+ it 'has a method for getting its rotation' do
63
+ expect(@read_only_tf.rotation).to be_kind_of(Numeric)
64
+ end
65
+
66
+ it 'has a method for setting its rotation' do
67
+ @read_only_tf.rotation = Math::PI
68
+ expect(@read_only_tf.rotation).to be == Math::PI
69
+ end
70
+
22
71
  describe '#center=' do
23
72
  it 'accepts a size 3 vector' do
24
- tf = Gosling::Transform.new
73
+ tf = TransformableThing.new
25
74
  expect { tf.center = Snow::Vec3[0, 0, 0] }.not_to raise_error
26
75
  expect { tf.center = [0, 0, 0] }.not_to raise_error
27
76
  expect { tf.center = :foo }.to raise_error(ArgumentError)
@@ -29,13 +78,13 @@ describe Gosling::Transform do
29
78
 
30
79
  it 'sets the center transform' do
31
80
  v = Snow::Vec3[10.to_r, 20.to_r, 1.to_r]
32
- tf = Gosling::Transform.new
81
+ tf = TransformableThing.new
33
82
  tf.center = v
34
83
  expect(tf.center).to be == v
35
84
  end
36
85
 
37
86
  it 'does not alter the z value, which should always be 1' do
38
- tf = Gosling::Transform.new
87
+ tf = TransformableThing.new
39
88
  [
40
89
  Snow::Vec3[1, 1, 1],
41
90
  Snow::Vec3[1, 1, 13],
@@ -53,14 +102,14 @@ describe Gosling::Transform do
53
102
 
54
103
  describe '#set_scale' do
55
104
  it 'accepts a size 2 vector' do
56
- tf = Gosling::Transform.new
105
+ tf = TransformableThing.new
57
106
  expect { tf.scale = Snow::Vec2[1, 1] }.not_to raise_error
58
107
  expect { tf.scale = :foo }.to raise_error(ArgumentError)
59
108
  end
60
109
 
61
110
  it 'sets the scale transform' do
62
111
  v = Snow::Vec2[2.to_r, 0.5.to_r]
63
- tf = Gosling::Transform.new
112
+ tf = TransformableThing.new
64
113
  tf.scale = v
65
114
  expect(tf.scale).to be == v
66
115
  end
@@ -69,7 +118,7 @@ describe Gosling::Transform do
69
118
  describe '#set_rotation' do
70
119
  it 'sets the rotation transform' do
71
120
  r = Math::PI / 2
72
- tf = Gosling::Transform.new
121
+ tf = TransformableThing.new
73
122
  tf.rotation = r
74
123
  expect(tf.rotation).to be == r
75
124
  end
@@ -77,20 +126,20 @@ describe Gosling::Transform do
77
126
 
78
127
  describe '#set_translation' do
79
128
  it 'accepts a size 3 vector' do
80
- tf = Gosling::Transform.new
129
+ tf = TransformableThing.new
81
130
  expect { tf.translation = Snow::Vec3[0, 0, 0] }.not_to raise_error
82
131
  expect { tf.translation = :foo }.to raise_error(ArgumentError)
83
132
  end
84
133
 
85
134
  it 'sets the translation transform' do
86
135
  v = Snow::Vec3[1024.to_r, 768.to_r, 1.to_r]
87
- tf = Gosling::Transform.new
136
+ tf = TransformableThing.new
88
137
  tf.translation = v
89
138
  expect(tf.translation).to be == v
90
139
  end
91
140
 
92
141
  it 'does not alter the z value, which should always be 1' do
93
- tf = Gosling::Transform.new
142
+ tf = TransformableThing.new
94
143
  [
95
144
  Snow::Vec3[1, 1, 1],
96
145
  Snow::Vec3[1, 1, 13],
@@ -113,7 +162,7 @@ describe Gosling::Transform do
113
162
  end
114
163
 
115
164
  it 'centers correctly' do
116
- tf = Gosling::Transform.new
165
+ tf = TransformableThing.new
117
166
  tf.center = Snow::Vec3[10.to_r, 20.to_r, 0.to_r]
118
167
  expected_matrix = Snow::Mat3[
119
168
  1, 0, -10,
@@ -124,7 +173,7 @@ describe Gosling::Transform do
124
173
  end
125
174
 
126
175
  it 'scales correctly' do
127
- tf = Gosling::Transform.new
176
+ tf = TransformableThing.new
128
177
  tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
129
178
  expected_matrix = Snow::Mat3[
130
179
  2, 0, 0,
@@ -135,7 +184,7 @@ describe Gosling::Transform do
135
184
  end
136
185
 
137
186
  it 'rotates correctly' do
138
- tf = Gosling::Transform.new
187
+ tf = TransformableThing.new
139
188
  tf.rotation = Math::PI / 2
140
189
  expected_matrix = Snow::Mat3[
141
190
  0, 1, 0,
@@ -146,7 +195,7 @@ describe Gosling::Transform do
146
195
  end
147
196
 
148
197
  it 'translates correctly' do
149
- tf = Gosling::Transform.new
198
+ tf = TransformableThing.new
150
199
  tf.translation = Snow::Vec3[1024.to_r, 768.to_r, 0.to_r]
151
200
  expected_matrix = Snow::Mat3[
152
201
  1, 0, 1024,
@@ -157,7 +206,7 @@ describe Gosling::Transform do
157
206
  end
158
207
 
159
208
  it 'applies all transforms in the correct order' do
160
- tf = Gosling::Transform.new
209
+ tf = TransformableThing.new
161
210
  tf.center = Snow::Vec3[10.to_r, 20.to_r, 0.to_r]
162
211
  tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
163
212
  tf.rotation = Math::PI / 2
@@ -219,7 +268,7 @@ describe Gosling::Transform do
219
268
  end
220
269
 
221
270
  it 'transforms the point correctly' do
222
- tf = Gosling::Transform.new
271
+ tf = TransformableThing.new
223
272
  tf.center = Snow::Vec3[5.to_r, 20.to_r, 0.to_r]
224
273
  tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
225
274
  tf.rotation = Math::PI / 2
@@ -270,7 +319,7 @@ describe Gosling::Transform do
270
319
  end
271
320
 
272
321
  it 'untransforms the point correctly' do
273
- tf = Gosling::Transform.new
322
+ tf = TransformableThing.new
274
323
  tf.center = Snow::Vec3[5.to_r, 20.to_r, 0.to_r]
275
324
  tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
276
325
  tf.rotation = Math::PI / 2
@@ -289,7 +338,7 @@ describe Gosling::Transform do
289
338
  end
290
339
 
291
340
  it 'undoes the results of transform_point' do
292
- tf = Gosling::Transform.new
341
+ tf = TransformableThing.new
293
342
  tf.center = Snow::Vec3[5.to_r, 20.to_r, 0.to_r]
294
343
  tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
295
344
  tf.rotation = Math::PI / 2
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosling
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Amos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-25 00:00:00.000000000 Z
11
+ date: 2018-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -69,7 +69,7 @@ files:
69
69
  - "./lib/gosling/polygon.rb"
70
70
  - "./lib/gosling/rect.rb"
71
71
  - "./lib/gosling/sprite.rb"
72
- - "./lib/gosling/transform.rb"
72
+ - "./lib/gosling/transformable.rb"
73
73
  - "./lib/gosling/utils.rb"
74
74
  - "./lib/gosling/version.rb"
75
75
  - "./spec/actor_spec.rb"
@@ -86,7 +86,7 @@ files:
86
86
  - "./spec/rect_spec.rb"
87
87
  - "./spec/spec_helper.rb"
88
88
  - "./spec/sprite_spec.rb"
89
- - "./spec/transform_spec.rb"
89
+ - "./spec/transformable_spec.rb"
90
90
  homepage: https://github.com/flashguardian13/gosling
91
91
  licenses:
92
92
  - CC-BY-4.0