ruby-mext 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +1 -0
- data/lib/mext/{numeric/exceptions.rb → exceptions.rb} +7 -1
- data/lib/mext/math/expon.rb +2 -24
- data/lib/mext/math/function.rb +56 -0
- data/lib/mext/math/line.rb +51 -0
- data/lib/mext/math.rb +2 -0
- data/lib/mext/numeric/ampdb.rb +1 -1
- data/lib/mext/numeric/cpspch.rb +1 -1
- data/lib/mext/numeric/ftom.rb +1 -1
- data/lib/mext/numeric.rb +0 -1
- data/lib/mext.rb +1 -0
- data/lib/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e17fe59684741fe17bcb1115faf090621239cdc7afb3823a3601ae7b8e643449
|
4
|
+
data.tar.gz: 670b6028c1a79e8feaac202c9ddb3da4f07f5d72e93a3a5d862e3a9f9ce58e7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a09e8d92256aadcd2bbfe12fa3ec7caffb4c33c2213f7e1e5843a810cef484c580b39db9c064f0da2a83c562c63e0b51d06e1a391343903777f5bc23192baa6e
|
7
|
+
data.tar.gz: 7e5414a0aa5f5790286825e2acf7c800e3a43b8d315b29df1a35bb8f7d97c8587909dba9d62f256d8431ad63935aa9313c14d488f9ac66bb6581521481245c9e
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/nicb/ruby-mext.svg?branch=master)](https://travis-ci.org/nicb/ruby-mext)
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/53686892aa9ee6a30ebb/maintainability)](https://codeclimate.com/github/nicb/ruby-mext/maintainability)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/ruby-mext.svg)](https://badge.fury.io/rb/ruby-mext)
|
5
6
|
|
6
7
|
These are extensions of usual idiomatic `ruby` objects (i.e. `Numeric`,
|
7
8
|
`Array`, etc.) that make `ruby` a comfortable language for musicians.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
module Mext
|
2
2
|
|
3
3
|
#
|
4
4
|
# +NegativeNumeric+ is raised on certain operations that do not allow
|
@@ -6,4 +6,10 @@ class Numeric
|
|
6
6
|
#
|
7
7
|
class NegativeNumeric < StandardError; end
|
8
8
|
|
9
|
+
#
|
10
|
+
# +PureAbstractMethodCalled+ is raised when an abstract
|
11
|
+
# base class is called
|
12
|
+
#
|
13
|
+
class PureAbstractMethodCalled < StandardError; end
|
14
|
+
|
9
15
|
end
|
data/lib/mext/math/expon.rb
CHANGED
@@ -2,9 +2,9 @@ require 'cmath'
|
|
2
2
|
|
3
3
|
module Math
|
4
4
|
|
5
|
-
class Expon
|
5
|
+
class Expon < Function
|
6
6
|
|
7
|
-
attr_reader :y_start, :y_end, :
|
7
|
+
attr_reader :y_start, :y_end, :tau
|
8
8
|
attr_reader :a, :b, :c
|
9
9
|
|
10
10
|
#
|
@@ -47,28 +47,6 @@ module Math
|
|
47
47
|
(CMath::exp(self.a*x + self.b) + self.c).abs # we want a real number result, no complex please
|
48
48
|
end
|
49
49
|
|
50
|
-
#:doc:
|
51
|
-
#
|
52
|
-
# +xy(step)+
|
53
|
-
#
|
54
|
-
# Returns a full deployment of the function evaluated with a step of
|
55
|
-
# +step+. It is returned in two arrays - one for the +x+ values and the
|
56
|
-
# other for the +y+ values.
|
57
|
-
#
|
58
|
-
# This method is mainly for testing purposes with the dataxy method of +gruff+
|
59
|
-
#
|
60
|
-
#:nodoc:
|
61
|
-
def xy(s)
|
62
|
-
resx = []
|
63
|
-
resy = []
|
64
|
-
self.x_start.step(x_end, s) do
|
65
|
-
|x|
|
66
|
-
resx << x
|
67
|
-
resy << self.y(x)
|
68
|
-
end
|
69
|
-
[resx, resy]
|
70
|
-
end
|
71
|
-
|
72
50
|
private
|
73
51
|
|
74
52
|
def setup
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Math
|
2
|
+
|
3
|
+
class Function
|
4
|
+
|
5
|
+
attr_reader :x_start, :x_end
|
6
|
+
#
|
7
|
+
# +Math::Function.new+:
|
8
|
+
#
|
9
|
+
# abstract base class function
|
10
|
+
#
|
11
|
+
#:nodoc:
|
12
|
+
def initialize
|
13
|
+
setup
|
14
|
+
end
|
15
|
+
|
16
|
+
#:doc:
|
17
|
+
#
|
18
|
+
# +y(x)+:
|
19
|
+
#
|
20
|
+
# Returns a real value given x
|
21
|
+
#
|
22
|
+
#:nodoc:
|
23
|
+
def y(x)
|
24
|
+
end
|
25
|
+
|
26
|
+
#:doc:
|
27
|
+
#
|
28
|
+
# +xy(step)+
|
29
|
+
#
|
30
|
+
# Returns a full deployment of the function evaluated with a step of
|
31
|
+
# +step+. It is returned in two arrays - one for the +x+ values and the
|
32
|
+
# other for the +y+ values.
|
33
|
+
#
|
34
|
+
# This method is mainly for testing purposes with the dataxy method of +gruff+
|
35
|
+
#
|
36
|
+
#:nodoc:
|
37
|
+
def xy(s)
|
38
|
+
resx = []
|
39
|
+
resy = []
|
40
|
+
self.x_start.step(x_end, s) do
|
41
|
+
|x|
|
42
|
+
resx << x
|
43
|
+
resy << self.y(x)
|
44
|
+
end
|
45
|
+
[resx, resy]
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def setup
|
51
|
+
raise Mext::PureAbstractMethodCalled
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Math
|
2
|
+
|
3
|
+
class Line < Function
|
4
|
+
|
5
|
+
attr_reader :y_start, :y_end
|
6
|
+
attr_reader :a, :b
|
7
|
+
|
8
|
+
#
|
9
|
+
# +Math::Line.new(ystart, yend, xstart, xend)+:
|
10
|
+
#
|
11
|
+
# linear interpolation `y = a*x + b` where:
|
12
|
+
#
|
13
|
+
# `a = (yend-ystart)/(xend-xstart)`
|
14
|
+
# `b = ystart - (a*xstart)`
|
15
|
+
#
|
16
|
+
# Arguments are:
|
17
|
+
#
|
18
|
+
# +ystart+, +yend+: start/end y values required
|
19
|
+
# +xstart+, +xend+: start/end x values
|
20
|
+
#
|
21
|
+
#:nodoc:
|
22
|
+
def initialize(ys, ye, xs, xe)
|
23
|
+
@y_start = ys.to_f
|
24
|
+
@y_end = ye.to_f
|
25
|
+
@x_start = xs.to_f
|
26
|
+
@x_end = xe.to_f
|
27
|
+
setup
|
28
|
+
end
|
29
|
+
|
30
|
+
#:doc:
|
31
|
+
#
|
32
|
+
# +y(x)+:
|
33
|
+
#
|
34
|
+
# Returns a real value given x
|
35
|
+
#
|
36
|
+
#:nodoc:
|
37
|
+
def y(x)
|
38
|
+
(self.a*x) + self.b
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def setup
|
44
|
+
@a = (self.y_end - self.y_start)/(self.x_end - self.x_start)
|
45
|
+
@b = (self.y_start - (self.x_start * self.a))
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
data/lib/mext/math.rb
CHANGED
data/lib/mext/numeric/ampdb.rb
CHANGED
data/lib/mext/numeric/cpspch.rb
CHANGED
data/lib/mext/numeric/ftom.rb
CHANGED
data/lib/mext/numeric.rb
CHANGED
data/lib/mext.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicola Bernardini
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,13 +116,15 @@ files:
|
|
116
116
|
- lib/mext.rb
|
117
117
|
- lib/mext/array.rb
|
118
118
|
- lib/mext/array/choose.rb
|
119
|
+
- lib/mext/exceptions.rb
|
119
120
|
- lib/mext/math.rb
|
120
121
|
- lib/mext/math/expon.rb
|
122
|
+
- lib/mext/math/function.rb
|
123
|
+
- lib/mext/math/line.rb
|
121
124
|
- lib/mext/numeric.rb
|
122
125
|
- lib/mext/numeric/ampdb.rb
|
123
126
|
- lib/mext/numeric/cpspch.rb
|
124
127
|
- lib/mext/numeric/dbamp.rb
|
125
|
-
- lib/mext/numeric/exceptions.rb
|
126
128
|
- lib/mext/numeric/ftom.rb
|
127
129
|
- lib/mext/numeric/mtof.rb
|
128
130
|
- lib/mext/numeric/mtopch.rb
|