math2d 1.3 → 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/utils2d.rb +12 -8
- data/lib/math2d/vector2d.rb +271 -73
- metadata +46 -4
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/utils2d.rb
CHANGED
@@ -13,11 +13,11 @@ module Math2D
|
|
13
13
|
# Twice the mathematical constant PI, also called TAU.
|
14
14
|
TWO_PI = TAU = Math::PI * 2
|
15
15
|
|
16
|
-
# Multiplication constant to convert a value in degrees to radians
|
17
|
-
# @note Can be used as a substitute to +Utils2D.to_deg+.
|
18
|
-
DEG2RAD = Math::PI / 180
|
19
|
-
# Multiplication constant to convert a value in degrees to radians
|
16
|
+
# Multiplication constant to convert a value in degrees to radians.
|
20
17
|
# @note Can be used as a substitute to +Utils2D.to_rad+.
|
18
|
+
DEG2RAD = Math::PI / 180
|
19
|
+
# Multiplication constant to convert a value in radians to degrees.
|
20
|
+
# @note Can be used as a substitute to +Utils2D.to_deg+.
|
21
21
|
RAD2DEG = 180 / Math::PI
|
22
22
|
|
23
23
|
# Returns +angle+ radians in degrees.
|
@@ -25,7 +25,7 @@ module Math2D
|
|
25
25
|
# @param [Numeric] angle
|
26
26
|
# @return [Float]
|
27
27
|
def self.to_deg(angle)
|
28
|
-
angle *
|
28
|
+
angle * RAD2DEG
|
29
29
|
end
|
30
30
|
|
31
31
|
# Returns +angle+ degrees in radians.
|
@@ -33,7 +33,7 @@ module Math2D
|
|
33
33
|
# @param [Numeric] angle
|
34
34
|
# @return [Float]
|
35
35
|
def self.to_rad(angle)
|
36
|
-
angle *
|
36
|
+
angle * DEG2RAD
|
37
37
|
end
|
38
38
|
|
39
39
|
# Returns the distance between two cartesian points.
|
@@ -142,8 +142,8 @@ module Math2D
|
|
142
142
|
lerp(ix0, ix1, sy)
|
143
143
|
end
|
144
144
|
|
145
|
-
# If no argument is passed, randomly generates a
|
146
|
-
# Otherwise, returns a
|
145
|
+
# If no argument is passed, randomly generates a grayscale RGB array.
|
146
|
+
# Otherwise, returns a grayscale array with that argument normalized.
|
147
147
|
#
|
148
148
|
# @param [Numeric] val
|
149
149
|
# @return [Array<Float>]
|
@@ -156,6 +156,10 @@ module Math2D
|
|
156
156
|
[c, c, c, 1.0]
|
157
157
|
end
|
158
158
|
|
159
|
+
class << self
|
160
|
+
alias greyscale grayscale
|
161
|
+
end
|
162
|
+
|
159
163
|
private
|
160
164
|
|
161
165
|
# @private
|
data/lib/math2d/vector2d.rb
CHANGED
@@ -5,8 +5,10 @@ module Math2D
|
|
5
5
|
# - An implementation of various 2-dimensional vector methods.
|
6
6
|
#
|
7
7
|
# @author Ualace Henrique <ualacehenrique@hotmail.com>
|
8
|
-
# @note
|
9
|
-
#
|
8
|
+
# @note ALL ! (bang) methods that return a vector (e.g. #normalize!, #add!) change the vector in place
|
9
|
+
# and return _self_.
|
10
|
+
# @note MOST (but not all) regular methods that return a vector create NEW _Vector2D_. Some however change the
|
11
|
+
# vector in place and return _self_, so be careful.
|
10
12
|
# @attr [Numeric] x The x coordinate of the Vector
|
11
13
|
# @attr [Numeric] y The y coordinate of the Vector
|
12
14
|
class Vector2D
|
@@ -18,8 +20,27 @@ module Math2D
|
|
18
20
|
# @param [Numeric] y
|
19
21
|
# @return [Vector2D]
|
20
22
|
def initialize(x = 0, y = 0)
|
21
|
-
@x = x
|
22
|
-
@y = y
|
23
|
+
@x = x.to_f
|
24
|
+
@y = y.to_f
|
25
|
+
end
|
26
|
+
|
27
|
+
# Creates a copy of the +other+ vector.
|
28
|
+
#
|
29
|
+
# @param [Vector2D] other Vector to copy
|
30
|
+
# @return [Vector2D]
|
31
|
+
def initialize_copy(other)
|
32
|
+
@x = other.x
|
33
|
+
@y = other.y
|
34
|
+
end
|
35
|
+
|
36
|
+
# Replace contents of this vector with contents of +other+ *in place*.
|
37
|
+
#
|
38
|
+
# @param [Vector2D] other
|
39
|
+
# @return [Vector2D] modified vector
|
40
|
+
def replace!(other)
|
41
|
+
@x = other.x
|
42
|
+
@y = other.y
|
43
|
+
self
|
23
44
|
end
|
24
45
|
|
25
46
|
# Sets the +x+ and +y+ components of the vector.
|
@@ -30,8 +51,8 @@ module Math2D
|
|
30
51
|
# @param [Numeric] y
|
31
52
|
# @return [Vector2D] self
|
32
53
|
def set(x = self.x, y = self.y)
|
33
|
-
@x = x
|
34
|
-
@y = y
|
54
|
+
@x = x.to_f
|
55
|
+
@y = y.to_f
|
35
56
|
self
|
36
57
|
end
|
37
58
|
|
@@ -80,53 +101,62 @@ module Math2D
|
|
80
101
|
|
81
102
|
# Negates both x and y values of +self+ and returns a new Vector2D.
|
82
103
|
#
|
83
|
-
# @return [Vector2D]
|
104
|
+
# @return [Vector2D] new vector
|
84
105
|
def -@
|
85
106
|
Vector2D.new(-@x, -@y)
|
86
107
|
end
|
87
108
|
|
88
109
|
alias negate -@
|
110
|
+
alias reverse -@
|
89
111
|
|
90
|
-
# Adds +self+ to another vector or to a scalar.
|
91
112
|
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
|
95
|
-
|
113
|
+
# Negate this vector, modifying it in place
|
114
|
+
#
|
115
|
+
# @return [Vector2D] modified self
|
116
|
+
def reverse!
|
117
|
+
@x = -@x
|
118
|
+
@y = -@y
|
119
|
+
self
|
120
|
+
end
|
121
|
+
|
122
|
+
alias negate! reverse!
|
96
123
|
|
97
|
-
|
124
|
+
# Adds +self+ to another vector, scalar, or array of two scalars
|
125
|
+
#
|
126
|
+
# @param [Numeric, Vector2D, Array] other
|
127
|
+
# @return [Vector2D] new vector
|
128
|
+
def +(other)
|
129
|
+
clone.plus!(other)
|
98
130
|
end
|
99
131
|
|
100
|
-
# Subtracts +self+
|
132
|
+
# Subtracts +self+ from another vector, scalar, or array of two scalars
|
101
133
|
#
|
102
|
-
# @param [Numeric, Vector2D] other
|
103
|
-
# @return [Vector2D]
|
134
|
+
# @param [Numeric, Vector2D, Array] other
|
135
|
+
# @return [Vector2D] new vector
|
104
136
|
def -(other)
|
105
|
-
|
106
|
-
|
107
|
-
Vector2D.new(@x - other, @y - other)
|
137
|
+
clone.minus!(other)
|
108
138
|
end
|
109
139
|
|
110
|
-
# Multiplies +self+ by another vector or
|
140
|
+
# Multiplies +self+ by another vector, scalar, or array of two scalars
|
111
141
|
#
|
112
|
-
# @param [Numeric, Vector2D] other
|
113
|
-
# @return [Vector2D]
|
142
|
+
# @param [Numeric, Vector2D, Array] other
|
143
|
+
# @return [Vector2D] new vector
|
114
144
|
def *(other)
|
115
|
-
|
116
|
-
|
117
|
-
Vector2D.new(@x * other, @y * other)
|
145
|
+
clone.times!(other)
|
118
146
|
end
|
119
147
|
|
120
|
-
# Divides +self+ by another vector or
|
148
|
+
# Divides +self+ by another vector, scalar, or array of two scalars
|
121
149
|
#
|
122
|
-
# @param [Numeric, Vector2D] other
|
123
|
-
# @return [Vector2D]
|
150
|
+
# @param [Numeric, Vector2D, Array] other
|
151
|
+
# @return [Vector2D] new vector
|
124
152
|
def /(other)
|
125
|
-
|
126
|
-
|
127
|
-
Vector2D.new(@x / other, @y / other)
|
153
|
+
clone.divide_by!(other)
|
128
154
|
end
|
129
155
|
|
156
|
+
# Compares +self+ and +other+ according to their components.
|
157
|
+
#
|
158
|
+
# @param [Vector2D] other
|
159
|
+
# @return [Boolean]
|
130
160
|
def ==(other)
|
131
161
|
(@x == other.x) && (@y == other.y)
|
132
162
|
end
|
@@ -162,6 +192,8 @@ module Math2D
|
|
162
192
|
(@x**2) + (@y**2)
|
163
193
|
end
|
164
194
|
|
195
|
+
alias magnitude2 squared
|
196
|
+
|
165
197
|
# Returns the magnitude of +self+.
|
166
198
|
#
|
167
199
|
# @return [Float]
|
@@ -171,6 +203,16 @@ module Math2D
|
|
171
203
|
|
172
204
|
alias length magnitude
|
173
205
|
|
206
|
+
# Returns the squared Euclidean distance between +self+ and +other+. When comparing
|
207
|
+
# distances, comparing the squared distance yields the same result without the
|
208
|
+
# overhead of a square-root operation.
|
209
|
+
#
|
210
|
+
# @param [Vector2D] other
|
211
|
+
# @return [Float]
|
212
|
+
def distance2(other)
|
213
|
+
(other.x - @x)**2 + (other.y - @y)**2
|
214
|
+
end
|
215
|
+
|
174
216
|
# Returns the Euclidean distance between +self+ and +other+.
|
175
217
|
#
|
176
218
|
# @param [Vector2D] other
|
@@ -189,32 +231,32 @@ module Math2D
|
|
189
231
|
# Limit the magnitude of +self+ to +max+ and returns a new vector.
|
190
232
|
#
|
191
233
|
# @param [Numeric] max
|
192
|
-
# @return [Vector2D]
|
234
|
+
# @return [Vector2D] new vector
|
193
235
|
def limit(max)
|
194
236
|
msq = squared
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
vec *= max
|
199
|
-
end
|
200
|
-
vec
|
237
|
+
return self if msq <= (max**2)
|
238
|
+
|
239
|
+
self * (max / Math.sqrt(msq))
|
201
240
|
end
|
202
241
|
|
203
|
-
# Constrains the magnitude of +self+ between a minimum value +
|
242
|
+
# Constrains the magnitude of +self+ between a minimum value +min+ and maximum value +max+, returns a new
|
243
|
+
# vector or itself.
|
204
244
|
#
|
205
245
|
# @note I haven't experienced this with other methods (yet), so I'm only going to document this
|
206
246
|
# here: you may end up with a broken magnitude (1.99999999 instead of 2, for example),
|
207
247
|
# so always remember to check and round according to your need.
|
208
|
-
# @param [Numeric]
|
209
|
-
# @param [Numeric]
|
210
|
-
# @return [Vector2D]
|
211
|
-
def constrain(
|
212
|
-
|
213
|
-
|
214
|
-
if
|
215
|
-
|
216
|
-
elsif
|
217
|
-
|
248
|
+
# @param [Numeric] min
|
249
|
+
# @param [Numeric] max
|
250
|
+
# @return [Vector2D] new vector, or self
|
251
|
+
def constrain(min, max)
|
252
|
+
min, max = max, min if min > max # swap
|
253
|
+
mag2 = magnitude2
|
254
|
+
if mag2 > max.abs2
|
255
|
+
Vector2D.one.set_magnitude(max)
|
256
|
+
elsif mag2 < min.abs2
|
257
|
+
Vector2D.one.set_magnitude(min)
|
258
|
+
else
|
259
|
+
self
|
218
260
|
end
|
219
261
|
end
|
220
262
|
|
@@ -223,23 +265,35 @@ module Math2D
|
|
223
265
|
# Sets the magnitude of +self+ to +new_mag+.
|
224
266
|
#
|
225
267
|
# @param [Numeric] new_mag
|
226
|
-
# @return [Vector2D]
|
268
|
+
# @return [Vector2D] modified self
|
227
269
|
def set_magnitude(new_mag)
|
228
270
|
mag = magnitude
|
229
|
-
mag =
|
230
|
-
|
271
|
+
mag = Float::INFINITY if mag.zero?
|
272
|
+
times!(new_mag / mag)
|
231
273
|
end
|
232
274
|
|
233
|
-
|
275
|
+
alias magnitude! set_magnitude
|
276
|
+
|
277
|
+
# Normalizes +self+ (set the magnitude to 1) and returns a new vector.
|
234
278
|
# +unit+ is an alias for this method.
|
235
279
|
#
|
236
|
-
# @return [Vector2D]
|
280
|
+
# @return [Vector2D] new vector
|
237
281
|
def normalize
|
238
|
-
set_magnitude(1)
|
282
|
+
clone.set_magnitude(1)
|
239
283
|
end
|
240
284
|
|
241
285
|
alias unit normalize
|
242
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!
|
292
|
+
set_magnitude(1)
|
293
|
+
end
|
294
|
+
|
295
|
+
alias unit! normalize!
|
296
|
+
|
243
297
|
# Returns true if the magnitude of +self+ is equal to 1, false otherwise.
|
244
298
|
# +unit?+ is an alias for this method.
|
245
299
|
#
|
@@ -288,39 +342,64 @@ module Math2D
|
|
288
342
|
# @param [Vector2D] other
|
289
343
|
# @return [Boolean]
|
290
344
|
def opposite?(other)
|
291
|
-
dot(other)
|
345
|
+
dot(other).negative?
|
292
346
|
end
|
293
347
|
|
294
348
|
# Clockwise rotates +self+ +angle+ radians and returns it as a new Vector2D.
|
295
349
|
#
|
296
350
|
# @param [Numeric] angle
|
297
|
-
# @return [Vector2D]
|
351
|
+
# @return [Vector2D] new vector
|
298
352
|
def rotate(angle)
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
353
|
+
clone.rotate!(angle)
|
354
|
+
end
|
355
|
+
|
356
|
+
# Clockwise rotates +self+ by +angle+ radians *in place*
|
357
|
+
#
|
358
|
+
# @param [Numeric] angle
|
359
|
+
# @return [Vector2D] modified self
|
360
|
+
def rotate!(angle)
|
361
|
+
sin_ang = Math.sin(angle)
|
362
|
+
cos_ang = Math.cos(angle)
|
363
|
+
@x = @x * cos_ang - @y * sin_ang
|
364
|
+
@y = @x * sin_ang + @y * cos_ang
|
365
|
+
self
|
303
366
|
end
|
304
367
|
|
305
368
|
# Clockwise rotates +self+ +angle+ radians around a +pivot+ point and returns it as a new Vector2D.
|
306
369
|
#
|
307
370
|
# @param [Vector2D] pivot
|
308
371
|
# @param [Numeric] angle
|
309
|
-
# @return [Vector2D]
|
372
|
+
# @return [Vector2D] new vector
|
310
373
|
def rotate_around(pivot, angle)
|
311
|
-
|
312
|
-
|
374
|
+
clone.rotate_around!(pivot, angle)
|
375
|
+
end
|
313
376
|
|
314
|
-
|
377
|
+
# Clockwise rotates +self+ by +angle+ radians around a +pivot+ point *in place*
|
378
|
+
#
|
379
|
+
# @param [Vector2D] pivot
|
380
|
+
# @param [Numeric] angle
|
381
|
+
# @return [Vector2D] modified self
|
382
|
+
def rotate_around!(pivot, angle)
|
383
|
+
pivot_x = pivot.x
|
384
|
+
pivot_y = pivot.y
|
385
|
+
dx = (@x - pivot_x)
|
386
|
+
dy = (@y - pivot_y)
|
387
|
+
sin_ang = Math.sin(angle)
|
388
|
+
cos_ang = Math.cos(angle)
|
389
|
+
@x = pivot_x + (dx * cos_ang) - (dy * sin_ang)
|
390
|
+
@y = pivot_y + (dx * sin_ang) + (dy * cos_ang)
|
391
|
+
self
|
315
392
|
end
|
316
393
|
|
317
394
|
# Linear interpolate +self+ and +other+ with an amount +amt+.
|
318
395
|
#
|
319
396
|
# @param [Numeric, Vector2D] other
|
320
397
|
# @param [Numeric] amt
|
321
|
-
# @return [Vector2D]
|
398
|
+
# @return [Vector2D] new vector
|
322
399
|
def lerp(other, amt)
|
323
|
-
|
400
|
+
Vector2D.new @x + (other.x - @x) * amt,
|
401
|
+
@y + (other.y - @y) * amt
|
402
|
+
# self + (other - self) * amt
|
324
403
|
end
|
325
404
|
|
326
405
|
# Calculates the parameter t of the +#lerp+ method between +self+ and +other+ given an interpolant +value+.
|
@@ -340,26 +419,27 @@ module Math2D
|
|
340
419
|
def reflect(other)
|
341
420
|
other = other.normalize
|
342
421
|
dot_prod = other.dot(self)
|
343
|
-
|
344
|
-
|
345
|
-
Vector2D.new(x, y)
|
422
|
+
Vector2D.new @x - dot_prod * other.x * 2,
|
423
|
+
@y - dot_prod * other.y * 2
|
346
424
|
end
|
347
425
|
|
348
426
|
# Refracts +self+ and returns it as a new Vector2D.
|
349
427
|
# +other+ is the normal of the plane where +self+ is refracted.
|
350
428
|
#
|
351
429
|
# @see https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.1.20.pdf GLS Language Specification (page 66)
|
430
|
+
# @see https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/refract.xhtml
|
352
431
|
#
|
353
432
|
# @param [Vector2D] other
|
354
433
|
# @param [Numeric] refractive_index
|
355
434
|
# @return [Vector2D]
|
356
435
|
def refract(other, refractive_index)
|
357
436
|
dot_prod = other.dot(self)
|
358
|
-
k = 1.0 - refractive_index *
|
437
|
+
k = 1.0 - refractive_index.abs2 * (1.0 - dot_prod.abs2)
|
359
438
|
return Vector2D.zero if k.negative?
|
360
439
|
|
361
|
-
|
362
|
-
|
440
|
+
other_refraction = (refractive_index * dot_prod * Math.sqrt(k))
|
441
|
+
x = refractive_index * @x - other_refraction * other.x
|
442
|
+
y = refractive_index * @y - other_refraction * other.y
|
363
443
|
Vector2D.new(x, y)
|
364
444
|
end
|
365
445
|
|
@@ -385,6 +465,26 @@ module Math2D
|
|
385
465
|
to_a.to_s
|
386
466
|
end
|
387
467
|
|
468
|
+
# Returns a *new vector* of the clockwise perpendicular to this vector.
|
469
|
+
#
|
470
|
+
# @return [Vector2D]
|
471
|
+
#
|
472
|
+
def vector_cross_product
|
473
|
+
Vector2D.new @y, -@x
|
474
|
+
end
|
475
|
+
|
476
|
+
alias perp vector_cross_product
|
477
|
+
|
478
|
+
# Replace this vector with it's clockwise perpendicular
|
479
|
+
#
|
480
|
+
# @return [Vector2D] modified self
|
481
|
+
def vector_cross_product!
|
482
|
+
@x, @y = @y, -@x
|
483
|
+
self
|
484
|
+
end
|
485
|
+
|
486
|
+
alias perp! vector_cross_product!
|
487
|
+
|
388
488
|
# Returns a new Vector2D from an array +arr+.
|
389
489
|
# If the array is bigger than 2 elements, only the first 2 will be considered.
|
390
490
|
#
|
@@ -395,5 +495,103 @@ module Math2D
|
|
395
495
|
|
396
496
|
Vector2D.new(arr[0], arr[1])
|
397
497
|
end
|
498
|
+
|
499
|
+
# Multiplies +self+ by +delta+ in place.
|
500
|
+
#
|
501
|
+
# @param [Numeric, Vector2D, Array] delta
|
502
|
+
# @return [Vector2D] modified self
|
503
|
+
def times!(delta)
|
504
|
+
case delta
|
505
|
+
when Vector2D
|
506
|
+
@x *= delta.x
|
507
|
+
@y *= delta.y
|
508
|
+
when Array
|
509
|
+
@x *= delta[0]
|
510
|
+
@y *= delta[1]
|
511
|
+
else
|
512
|
+
@x *= delta
|
513
|
+
@y *= delta
|
514
|
+
end
|
515
|
+
self
|
516
|
+
end
|
517
|
+
|
518
|
+
# Subtracts +delta+ from +self+ in place.
|
519
|
+
#
|
520
|
+
# @param [Numeric, Vector2D, Array] delta
|
521
|
+
# @return [Vector2D] modified self
|
522
|
+
def minus!(delta)
|
523
|
+
case delta
|
524
|
+
when Vector2D
|
525
|
+
@x -= delta.x
|
526
|
+
@y -= delta.y
|
527
|
+
when Array
|
528
|
+
@x -= delta[0]
|
529
|
+
@y -= delta[1]
|
530
|
+
else
|
531
|
+
@x -= delta
|
532
|
+
@y -= delta
|
533
|
+
end
|
534
|
+
self
|
535
|
+
end
|
536
|
+
|
537
|
+
# Adds +delta+ to +self+ in place.
|
538
|
+
#
|
539
|
+
# @param [Numeric, Vector2D, Array] delta
|
540
|
+
# @return [Vector2D] modified self
|
541
|
+
def plus!(delta)
|
542
|
+
case delta
|
543
|
+
when Vector2D
|
544
|
+
@x += delta.x
|
545
|
+
@y += delta.y
|
546
|
+
when Array
|
547
|
+
@x += delta[0]
|
548
|
+
@y += delta[1]
|
549
|
+
else
|
550
|
+
@x += delta
|
551
|
+
@y += delta
|
552
|
+
end
|
553
|
+
self
|
554
|
+
end
|
555
|
+
|
556
|
+
# Divides +self+ by +delta+ in place.
|
557
|
+
#
|
558
|
+
# @param [Numeric, Vector2D, Array] delta
|
559
|
+
# @return [Vector2D] modified self
|
560
|
+
def divide_by!(delta)
|
561
|
+
case delta
|
562
|
+
when Vector2D
|
563
|
+
@x /= delta.x
|
564
|
+
@y /= delta.y
|
565
|
+
when Array
|
566
|
+
@x /= delta[0]
|
567
|
+
@y /= delta[1]
|
568
|
+
else
|
569
|
+
@x /= delta
|
570
|
+
@y /= delta
|
571
|
+
end
|
572
|
+
self
|
573
|
+
end
|
574
|
+
|
575
|
+
# Add +dx+ and +dy+ to the current vector's components, respectively
|
576
|
+
#
|
577
|
+
# @param [Numeric] dx
|
578
|
+
# @param [Numeric] dy
|
579
|
+
# @return [Vector2d] modified self
|
580
|
+
def add!(dx, dy)
|
581
|
+
@x += dx
|
582
|
+
@y += dy
|
583
|
+
self
|
584
|
+
end
|
585
|
+
|
586
|
+
# Subtract +dx+ and +dy+ _from_ the current vector's components, respectively
|
587
|
+
#
|
588
|
+
# @param [Numeric] dx
|
589
|
+
# @param [Numeric] dy
|
590
|
+
# @return [Vector2d] modified self
|
591
|
+
def subtract!(dx, dy)
|
592
|
+
@x -= dx
|
593
|
+
@y -= dy
|
594
|
+
self
|
595
|
+
end
|
398
596
|
end
|
399
597
|
end
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: math2d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ualace Henrique
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
12
|
-
dependencies:
|
11
|
+
date: 2022-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
13
55
|
description: A collection of useful Mathematical and Vector tools in 2D space
|
14
56
|
email:
|
15
57
|
executables: []
|
@@ -38,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
80
|
- !ruby/object:Gem::Version
|
39
81
|
version: '0'
|
40
82
|
requirements: []
|
41
|
-
rubygems_version: 3.3.
|
83
|
+
rubygems_version: 3.3.9
|
42
84
|
signing_key:
|
43
85
|
specification_version: 4
|
44
86
|
summary: Math2D
|