maths-units 0.1.0

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 (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/maths-units.rb +32 -0
  3. data/test/test-trig.rb +44 -0
  4. metadata +53 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ec904ceaf639b6f136d0f3fdd44257f6b157721
4
+ data.tar.gz: 1af50e801445d31c1b199743a6081fe230d85f3f
5
+ SHA512:
6
+ metadata.gz: 8be67264cd821109909a0c750ee17fdc3a2f24886ae5218e3d27979ca4c4b45c8ba0e9410bcfd16bea17ba40eeae7e25b9a9a140bbbd86e5813705e2626a16bf
7
+ data.tar.gz: 9b50c46292e01a7e6851ebb5fcab8362ca2ea47beca7251ccd826c692203ca25d8eb30690d6906ddb589457fb6141eed49218ca7a29909664378db50df5cdb1f
@@ -0,0 +1,32 @@
1
+
2
+ class Numeric
3
+
4
+ ##
5
+ # Convert from radians to radians.
6
+ #
7
+ def radians
8
+ self
9
+ end
10
+ alias :rad :radians
11
+
12
+ ##
13
+ # Convert from degrees to radians.
14
+ # Returns a float.
15
+ #
16
+ def degrees
17
+ self * Math::PI / 180.0
18
+ end
19
+ alias :deg :degrees
20
+
21
+ ##
22
+ # Convert from gradians to radians.
23
+ # Returns a float.
24
+ #
25
+ def gradians
26
+ self * Math::PI / 200.0
27
+ end
28
+ alias :grad :gradians
29
+ alias :gon :gradians
30
+
31
+ end
32
+
@@ -0,0 +1,44 @@
1
+ require 'test/unit'
2
+ $VERBOSE = true
3
+
4
+ require_relative '../lib/maths-units'
5
+ class Test_trig < Test::Unit::TestCase
6
+
7
+ def test_radians
8
+ [0, 1, 1.0, 1.624, Rational(5,3)].each do |num|
9
+ assert_equal( num, num.radians, "#{num}.radians != #{num}" )
10
+ assert_equal( num, num.rad, "#{num}.rad != #{num}" )
11
+ end
12
+ end
13
+
14
+ def test_degrees
15
+ arr = [
16
+ [0, 0.0],
17
+ [180, Math::PI],
18
+ [360.0, Math::PI * 2.0],
19
+ [Rational(60,1), Math::PI / 3.0],
20
+ [-90.0, -Math::PI / 2.0],
21
+ ]
22
+ arr.each do |d, x|
23
+ assert_equal( x, d.degrees, "#{d}.degrees != #{x}" )
24
+ assert_equal( x, d.deg, "#{d}.deg != #{x}" )
25
+ end
26
+ end
27
+
28
+ def test_gradians
29
+ arr = [
30
+ [0, 0.0],
31
+ [200, Math::PI],
32
+ [400.0, Math::PI * 2.0],
33
+ [Rational(50,1), Math::PI / 4.0],
34
+ [-100.0, -Math::PI / 2.0],
35
+ ]
36
+ arr.each do |g, x|
37
+ assert_equal( x, g.gradians, "#{g}.gradians != #{x}" )
38
+ assert_equal( x, g.grad, "#{g}.grad != #{x}" )
39
+ assert_equal( x, g.gon, "#{g}.gon != #{x}" )
40
+ end
41
+ end
42
+
43
+ end
44
+
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maths-units
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Kerwin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ == Maths Units
15
+
16
+ Conveniently convert degrees and gradians to radians, for use in
17
+ the trig functions in the `Math` module.
18
+
19
+ See the documentation at <https://github.com/phluid61/maths-units>.
20
+ email:
21
+ - matthew@kerwin.net.au
22
+ executables: []
23
+ extensions: []
24
+ extra_rdoc_files: []
25
+ files:
26
+ - lib/maths-units.rb
27
+ - test/test-trig.rb
28
+ homepage: https://phluid61.github.com/maths-units
29
+ licenses:
30
+ - ISC
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.6.2
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Maths Units
52
+ test_files:
53
+ - test/test-trig.rb