math2d 1.1.0 → 1.2.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 +5 -5
- data/lib/math2d/vector2d.rb +17 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fa9e7785755d0911beda7ece84a14f4b0234d9103ae593b556237be3403973e
|
4
|
+
data.tar.gz: ba748b29f8499d5ef2504942b4ee7c7dc3c9bad9d6fb5393f9aa78fd6d303cab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c494f9101b180ec9d2072630d48bbb9e0b99b404dec093ccaf35b4856cd75a8a11d4eed8478449a51f5bc3a37a239d37ab6899c35c558b24ff439490a64b88ff
|
7
|
+
data.tar.gz: 4f79cd577b4c2686e07fe8b36b30cf28f8b1e4aac13e48e51df3d9e0a64b80454ca10076dbe06734d36b511cacb044a0101a5e614cebb766bb5a7dce880df84d
|
data/lib/math2d/utils2d.rb
CHANGED
@@ -7,11 +7,11 @@ module Math2D
|
|
7
7
|
# @see https://p5js.org/
|
8
8
|
module Utils2D
|
9
9
|
# Half the mathematical constant PI.
|
10
|
-
HALF_PI
|
10
|
+
HALF_PI = Math::PI / 2
|
11
11
|
# A quarter of the mathematical constant PI.
|
12
|
-
QUARTER_PI
|
13
|
-
# Twice the mathematical constant PI.
|
14
|
-
TWO_PI
|
12
|
+
QUARTER_PI = Math::PI / 4
|
13
|
+
# Twice the mathematical constant PI, also called TAU.
|
14
|
+
TWO_PI = TAU = Math::PI * 2
|
15
15
|
|
16
16
|
# Returns +angle+ radians in degrees.
|
17
17
|
#
|
@@ -155,4 +155,4 @@ module Math2D
|
|
155
155
|
(dx * gradient[0]) + (dy * gradient[1])
|
156
156
|
end
|
157
157
|
end
|
158
|
-
end
|
158
|
+
end
|
data/lib/math2d/vector2d.rb
CHANGED
@@ -273,13 +273,27 @@ module Math2D
|
|
273
273
|
Math.acos((@x * other.x + @y * other.y) / (magnitude * other.magnitude))
|
274
274
|
end
|
275
275
|
|
276
|
-
#
|
276
|
+
# Clockwise rotates +self+ +angle+ radians and returns it as a new Vector2D.
|
277
277
|
#
|
278
278
|
# @param [Numeric] angle
|
279
279
|
# @return [Vector2D]
|
280
280
|
def rotate(angle)
|
281
|
-
Vector2D.new(
|
282
|
-
|
281
|
+
Vector2D.new(
|
282
|
+
@x * Math.cos(angle) - @y * Math.sin(angle),
|
283
|
+
@x * Math.sin(angle) + @y * Math.cos(angle)
|
284
|
+
)
|
285
|
+
end
|
286
|
+
|
287
|
+
# Clockwise rotates +self+ +angle+ radians around a +pivot+ point and returns it as a new Vector2D.
|
288
|
+
#
|
289
|
+
# @param [Vector2D] pivot
|
290
|
+
# @param [Numeric] angle
|
291
|
+
# @return [Vector2D]
|
292
|
+
def rotate_around(pivot, angle)
|
293
|
+
x_rotated = pivot.x + ((@x - pivot.x) * Math.cos(angle)) - ((@y - pivot.y) * Math.sin(angle))
|
294
|
+
y_rotated = pivot.y + ((@x - pivot.x) * Math.sin(angle)) + ((@y - pivot.y) * Math.cos(angle))
|
295
|
+
|
296
|
+
Vector2D.new(x_rotated, y_rotated)
|
283
297
|
end
|
284
298
|
|
285
299
|
# Linear interpolate +self+ and +other+ with an amount +amt+.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: math2d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.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: 2021-
|
11
|
+
date: 2021-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A collection of useful Mathematical and Vector tools in 2D space
|
14
14
|
email:
|
@@ -19,7 +19,7 @@ files:
|
|
19
19
|
- lib/math2d.rb
|
20
20
|
- lib/math2d/utils2d.rb
|
21
21
|
- lib/math2d/vector2d.rb
|
22
|
-
homepage: https://
|
22
|
+
homepage: https://github.com/UalaceCafe/math2d
|
23
23
|
licenses:
|
24
24
|
- MIT
|
25
25
|
metadata: {}
|