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.
- checksums.yaml +4 -4
- data/lib/math2d/vector2d.rb +15 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34a1c8daaf45027dc42765be7a12a631038b42bfb3454d68da26eb99e763cacd
|
4
|
+
data.tar.gz: 0b3e5533e79a80877806416dffb8c055f6164d5b391eea3ba0764589eb59bbcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd195200c4e96cac60591821c73fa96b73e3cf3902dfff3f77191c4fd70ecad42c590dd92df7d9b90250647c6a02bf847f6a0b9f951f4def7544fe3bb9d8457e
|
7
|
+
data.tar.gz: b578724ee4a68f9951a7fb5d31f0e10dcb9700d3b9b70496f23afc6c4ef11c0cc674a28c54fa83d89fe72745219b3f1b74b9cc685a1bdae5f16d62417eec1415
|
data/lib/math2d/vector2d.rb
CHANGED
@@ -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
|
-
|
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]
|
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+.
|