math2d 1.4 → 1.4.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/math2d/vector2d.rb +15 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 687573d7fe97c2627cea246b39ff246058cd1dce63c4163c6e4c9955db5bf00c
4
- data.tar.gz: 9475dc4a1a0b96f5c6133a171159151469d39d0a8d495c759286530f5880596e
3
+ metadata.gz: 34a1c8daaf45027dc42765be7a12a631038b42bfb3454d68da26eb99e763cacd
4
+ data.tar.gz: 0b3e5533e79a80877806416dffb8c055f6164d5b391eea3ba0764589eb59bbcd
5
5
  SHA512:
6
- metadata.gz: e382704a1edebfb80e669128eaf2838468eb2429435513f2c8af7cf582e5483511c08cc62334f0d24e38eb937610837d4f741f9193145bc5e029869876b4bd6c
7
- data.tar.gz: 625524b71e0d8c4b609cf846b89814bd3364f968b8f7276a3f31823720b6d41f2bc1116177d608cafa1696587736207cd020345236ce995e1e5992676efa71ad
6
+ metadata.gz: fd195200c4e96cac60591821c73fa96b73e3cf3902dfff3f77191c4fd70ecad42c590dd92df7d9b90250647c6a02bf847f6a0b9f951f4def7544fe3bb9d8457e
7
+ data.tar.gz: b578724ee4a68f9951a7fb5d31f0e10dcb9700d3b9b70496f23afc6c4ef11c0cc674a28c54fa83d89fe72745219b3f1b74b9cc685a1bdae5f16d62417eec1415
@@ -269,22 +269,30 @@ module Math2D
269
269
  def set_magnitude(new_mag)
270
270
  mag = magnitude
271
271
  mag = Float::INFINITY if mag.zero?
272
- self * (new_mag / mag)
272
+ times!(new_mag / mag)
273
273
  end
274
274
 
275
275
  alias magnitude! set_magnitude
276
276
 
277
- # Normalizes +self+ (set the magnitude to 1).
277
+ # Normalizes +self+ (set the magnitude to 1) and returns a new vector.
278
278
  # +unit+ is an alias for this method.
279
279
  #
280
- # @return [Vector2D] modified self
280
+ # @return [Vector2D] new vector
281
281
  def normalize
282
+ clone.set_magnitude(1)
283
+ end
284
+
285
+ alias unit normalize
286
+
287
+ # Normalizes +self+ (set the magnitude to 1) *in place*.
288
+ # +unit!+ is an alias for this method.
289
+ #
290
+ # @return [Vector2D] modified self
291
+ def normalize!
282
292
  set_magnitude(1)
283
293
  end
284
294
 
285
- alias normalize! normalize
286
295
  alias unit! normalize!
287
- alias unit normalize!
288
296
 
289
297
  # Returns true if the magnitude of +self+ is equal to 1, false otherwise.
290
298
  # +unit?+ is an alias for this method.
@@ -354,6 +362,7 @@ module Math2D
354
362
  cos_ang = Math.cos(angle)
355
363
  @x = @x * cos_ang - @y * sin_ang
356
364
  @y = @x * sin_ang + @y * cos_ang
365
+ self
357
366
  end
358
367
 
359
368
  # Clockwise rotates +self+ +angle+ radians around a +pivot+ point and returns it as a new Vector2D.
@@ -379,6 +388,7 @@ module Math2D
379
388
  cos_ang = Math.cos(angle)
380
389
  @x = pivot_x + (dx * cos_ang) - (dy * sin_ang)
381
390
  @y = pivot_y + (dx * sin_ang) + (dy * cos_ang)
391
+ self
382
392
  end
383
393
 
384
394
  # Linear interpolate +self+ and +other+ with an amount +amt+.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: math2d
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.4'
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ualace Henrique