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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3a494b2da989404d96ad8034d4b68f1ee7fa8280ce6f10e673e193fba05dc3b
4
- data.tar.gz: 8f137444c95142d170c666456419ed07a601dd01f5593492ab0131909d3d3195
3
+ metadata.gz: 2fa9e7785755d0911beda7ece84a14f4b0234d9103ae593b556237be3403973e
4
+ data.tar.gz: ba748b29f8499d5ef2504942b4ee7c7dc3c9bad9d6fb5393f9aa78fd6d303cab
5
5
  SHA512:
6
- metadata.gz: d2a54a7a4cdfb1a84553a5fe8ec22c4cfb1680273ce69d98c5979d0eec65cae88bb4072fa69aebf0b44a9d1f6d67c5a291d3207d44ff6e1c926b685007db8a98
7
- data.tar.gz: b0a32b1a0b168ff16e6c8e0aec72e828df677035e031f4870fb2c62994f8b9dfa37d86be0d8738bf6816d6645ab9f6e8a3296600468b61ad4ed852f3abb9e598
6
+ metadata.gz: c494f9101b180ec9d2072630d48bbb9e0b99b404dec093ccaf35b4856cd75a8a11d4eed8478449a51f5bc3a37a239d37ab6899c35c558b24ff439490a64b88ff
7
+ data.tar.gz: 4f79cd577b4c2686e07fe8b36b30cf28f8b1e4aac13e48e51df3d9e0a64b80454ca10076dbe06734d36b511cacb044a0101a5e614cebb766bb5a7dce880df84d
@@ -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 = Math::PI / 2
10
+ HALF_PI = Math::PI / 2
11
11
  # A quarter of the mathematical constant PI.
12
- QUARTER_PI = Math::PI / 4
13
- # Twice the mathematical constant PI.
14
- TWO_PI = Math::PI * 2
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
@@ -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
- # Rotates +self+ +angle+ radians and returns it as a new Vector2D.
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(@x * Math.cos(angle) - @y * Math.sin(angle),
282
- @x * Math.sin(angle) + @y * Math.cos(angle))
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.0
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-07-25 00:00:00.000000000 Z
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://rubygems.org/gems/math2d
22
+ homepage: https://github.com/UalaceCafe/math2d
23
23
  licenses:
24
24
  - MIT
25
25
  metadata: {}