epimath100 1.7.0 → 2.0.2

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
  SHA1:
3
- metadata.gz: dced7e03f99893cc4fc175ce6450960c870df29d
4
- data.tar.gz: 64f509eb9b8353fec2fc52112331af6a7e60653d
3
+ metadata.gz: 2858403c795608ec9b39cd293c128f4aa9cf38f1
4
+ data.tar.gz: f36ad6e002039349af59f7a5054e2d114c206ed3
5
5
  SHA512:
6
- metadata.gz: c277939219ffa8fbd79eb4b3ce2b78165cf1ea3c65a613185d9d075b802252d993af5a4df4b9b99ba351695f21715c5730d8540c2baa0d1eeeeb19f6d8572306
7
- data.tar.gz: c6347cdd47677cf25fb1840b6826e8d52270859579a2514c946c3e6970b7c33ba52b2adb9baca9a4867e7c62d22b2476d44240032985a6b77d71a405c7d81970
6
+ metadata.gz: 17c97f882a7535ab1ca039f51ea545f6d991f7637391f4748500826fa3a3d1a9ce110f42505064367474c8e13c191bce5383f25360508df75bcc539301e72ae6
7
+ data.tar.gz: dcda0c27dd1baf1de371af4dfc1f59708245a65a9965fbaefacd3a1806c7a3edf4e9abffe898bbf4c51c4341e857bea1cc52a90e2304447d416664ccd3e16606
@@ -0,0 +1,37 @@
1
+ #encoding: utf-8
2
+
3
+ module EpiMath
4
+ EXPOSANT = {"0" => "⁰",
5
+ "1" => "¹",
6
+ "2" => "²",
7
+ "3" => "³",
8
+ "4" => "⁴",
9
+ "5" => "⁵",
10
+ "6" => "⁶",
11
+ "7" => "⁷",
12
+ "8" => "⁸",
13
+ "9" => "⁹"}
14
+
15
+ class Function
16
+ def calc x
17
+ return 0
18
+ end
19
+
20
+ def convert_hash hash
21
+ coef = []
22
+ hash.select{|k,v| k.to_s.match(/[a-z]/)}.each do |k,v|
23
+ key = (k.to_s.ord - "a".ord).to_i
24
+ hash[key] = v if hash[key] == nil
25
+ end
26
+ return coef
27
+ end
28
+
29
+ def get_degree_max
30
+ return @coef.rindex{|x| x != nil}
31
+ end
32
+
33
+ def get_degree x
34
+ return @coef[x]
35
+ end
36
+ end
37
+ end
@@ -1,9 +1,10 @@
1
1
  #encoding: utf-8
2
2
 
3
- require 'myerror'
3
+ gem 'myerror'
4
4
  require_relative 'point.class.rb'
5
5
  require_relative 'vector.class.rb'
6
6
 
7
+ module EpiMath
7
8
  class Line
8
9
  attr_reader :point, :v_dir, :equ_para
9
10
 
@@ -103,3 +104,4 @@ class Line
103
104
  end
104
105
 
105
106
  end
107
+ end
@@ -1,8 +1,9 @@
1
1
  #encoding: utf-8
2
2
 
3
- require 'myerror'
3
+ gem 'myerror'
4
4
  require_relative 'vector.class'
5
5
 
6
+ module EpiMath
6
7
  # TODO : improve the documentation
7
8
  class Matrix
8
9
  attr_reader :columns, :lines, :v
@@ -305,3 +306,4 @@ class Matrix
305
306
  end
306
307
 
307
308
  end
309
+ end
@@ -1,7 +1,8 @@
1
1
  #encoding: utf-8
2
2
 
3
- require 'myerror'
3
+ gem 'myerror'
4
4
 
5
+ module EpiMath
5
6
  class Point
6
7
  def initialize x, y, z
7
8
  if !x.is_a?Numeric or !y.is_a?Numeric or !z.is_a?Numeric
@@ -48,3 +49,4 @@ class Point
48
49
  @coord[:z]
49
50
  end
50
51
  end
52
+ end
@@ -1,96 +1,76 @@
1
1
  #encoding: utf-8
2
2
 
3
- require 'myerror'
4
- require_relative 'vector.class'
5
-
6
- class Polynomial
7
- EXPOSANT = {"0" => "⁰",
8
- "1" => "¹",
9
- "2" => "²",
10
- "3" => "³",
11
- "4" => "⁴",
12
- "5" => "⁵",
13
- "6" => "⁶",
14
- "7" => "⁷",
15
- "8" => "⁸",
16
- "9" => "⁹"}
17
-
18
- attr_accessor :coef
19
-
20
- # Initialize the polynominal function
21
- # Its coeficients are 1, 2, 3, 4 ... with '1'x⁰ + '2'x¹ + '3'x² ... = y
22
- # Each coeficients has an associated value (exemple : 2 => 1 correspond to 1x²)
23
- #
24
- # == Notes:
25
- # The function is compatible with the first version, where coeficients keys are :a, :b, ...
26
- # == Parameters:
27
- # hash::
28
- # hash is a hash which have several keys 1, 2,... which correspond to the coeficients
29
- # verb:: default is false
30
- # verb is true or false, or a integer. It will display more information if turned on when to_s.
31
- # if it's a integer, it must be in the list :
32
- # - 0 : returns ""
33
- # - 1 : "y = equation"
34
- # - 2 : "f(x) = equation" (like true)
35
- def initialize hash={}, verb=false
36
- Error.call "Polynomial::new : You hash is invalid" if !hash.is_a?Hash
37
-
38
- hash.select{|k,v| k.to_s.match(/[a-z]/)}.each do |k,v|
39
- key = (k.to_s.ord - "a".ord)
40
- hash[key] = v if hash[key] == nil
3
+ gem 'myerror'
4
+ require_relative 'function.class'
5
+
6
+ module EpiMath
7
+ class Polynomial < Function
8
+
9
+ attr_accessor :coef, :verb
10
+
11
+ # Initialize the polynominal function
12
+ # Its coeficients are 1, 2, 3, 4 ... with '1'x⁰ + '2'x¹ + '3'x² ... = y
13
+ # Each coeficients has an associated value (exemple : 2 => 1 correspond to 1x²)
14
+ # exemple :
15
+ # a = [] ; a[2] = 1 ; #correspond to 0 + 0x + 2x³
16
+ #
17
+ # == Parameters:
18
+ # coef::
19
+ # coef is an array which have several keys 0, 1, 2,... which correspond to the coeficients
20
+ # verb:: default is false
21
+ # It will display more information if turned on when to_s.
22
+ # It's a integer, it must be in the list :
23
+ # - 0 : returns ""
24
+ # - 1 : "y = equation"
25
+ # - 2 : "f(x) = equation" (default value)
26
+ def initialize coef=[], verb=0
27
+ Error.call "Polynomial::new : Your coef is invalid" if !coef.is_a?Hash and !coef.is_a?Array
28
+ coef = convert_hash(coef) if coef.is_a?Hash
29
+ @coef = coef.select{|v| v.is_a?Numeric}
30
+ @verbose = 2
41
31
  end
42
32
 
43
- @coef = hash.select{|coef,value| coef.is_a?Numeric and coef >= 0 and value.is_a?Numeric}
44
- @verbose = verb
45
- end
33
+ #calculate the derivated function of the current polynomial
34
+ # == Returns:
35
+ # Polynomial (the derivated function)
36
+ def derive
37
+ dérivé = Polynomial.new
46
38
 
47
- #calculate the derivated function of the current polynomial
48
- # == Returns:
49
- # Polynomial (the derivated function)
50
- def derive
51
- dérivé = Polynomial.new
39
+ if @coef.size > 0
40
+ (1..(@coef.size)).times do |coef|
41
+ dérivé.coef[coef - 1] = dérivé[coef] * coef
42
+ end
43
+ end
52
44
 
53
- @coef.select{|coef,value| coef != 0}.each do |coef,value|
54
- dérivé.coef[coef - 1] = value * coef
45
+ return dérivé
55
46
  end
56
47
 
57
- return dérivé
58
- end
48
+ def to_s
49
+ str = ""
50
+ str = "#{@coef[0].to_i}" + str #if @coef[:a]
59
51
 
60
- def to_s
61
- return "" if @verbose == 0
52
+ if @coef.size > 0
53
+ (1..(@coef.size)).each do |coef|
54
+ #sign = "+"
55
+ #sign = "-" if value < 0
56
+ str = "#{@coef[coef]}x^#{coef} + " + str if @coef[coef].to_f != 0
57
+ end
58
+ end
62
59
 
63
- str = ""
64
- str = "#{@coef[0].to_i}" + str #if @coef[:a]
60
+ str = "f(x) = " + str if @verb == 2
61
+ str = "y = " + str if @verb == 1
65
62
 
66
- @coef.select{|coef,value| coef != 0}.each do |coef,value|
67
- #sign = "+"
68
- #sign = "-" if value < 0
69
- str = "#{value}x^#{coef} + " + str if value != 0
63
+ return str
70
64
  end
71
- str = "f(x) = " + str if @verbose == true or @verbose == 2
72
- str = "y = " + str if @verbose == 1
73
65
 
74
- return str
75
- end
76
-
77
- # Calculate the value of f(x) from x
78
- def calc x
79
- Error.call "Polynomial::calc: x is not a Numeric value" if !x.is_a?Numeric
80
-
81
- y = 0
82
- @coef.each do |coef,value|
83
- y += value * x**coef
66
+ # Calculate the value of f(x) from x
67
+ def calc x
68
+ y = 0
69
+ [@coef.size].max.times do |coef|
70
+ y += @coef[coef] * x**coef
71
+ end
72
+ return y
84
73
  end
85
74
 
86
- return y
87
- end
88
-
89
- def get_degree_max
90
- return @coef.keys.max
91
- end
92
-
93
- def get_degree x
94
- return @coef[x]
95
75
  end
96
76
  end
@@ -0,0 +1,62 @@
1
+ #encoding: utf-8
2
+
3
+ gem 'myerror'
4
+ require_relative 'function.class'
5
+ require_relative 'polynomial.class'
6
+
7
+ module EpiMath
8
+ class Rational < Function
9
+ attr_accessor :verbose
10
+
11
+ def initialize poly=Polynomial.new, div=Polynomial.new([1]), verb=2
12
+ #Error.call "Rational::new : Your poly are invalid" if !poly.is_a?Polynomial
13
+ Error.call "Rational::new : Your divider are invalid" if !div.is_a?Polynomial
14
+ @poly = poly #todo : check each element of the array (hash to use select ?)
15
+ @poly.verb = 0
16
+ @div = div
17
+ @div.verb = 0
18
+ @verb = verb
19
+ end
20
+
21
+ def derive
22
+ return nil
23
+ end
24
+
25
+ def to_s
26
+ max_space = [@poly.to_s.size, @div.to_s.size].max
27
+ top_space = (max_space - @poly.to_s.size) / 2
28
+ bot_space = (max_space - @div.to_s.size) / 2
29
+
30
+ string = " #{" " * top_space}#{@poly.to_s}\n"
31
+ string += "f(x) = #{"-" * max_space}"
32
+ string << "\n #{" " * bot_space}#{@div.to_s}"
33
+ return string
34
+ end
35
+
36
+ def calc x
37
+ Error.call "Rational::calc: x is not a Numeric value" if !x.is_a?Numeric
38
+
39
+ p = @poly.calc x
40
+ q = @div.calc x
41
+ return 0 if q == 0
42
+ return p / q
43
+ end
44
+
45
+ #accessors
46
+ def poly= p
47
+ Error.call "Rational::new : Your poly are invalid" if !p.is_a?Polynomial
48
+ @poly = p
49
+ end
50
+ def div= p
51
+ Error.call "Rational::new : Your divider are invalid" if !p.is_a?Polynomial
52
+ @div = p
53
+ end
54
+ def poly
55
+ @poly
56
+ end
57
+ def div
58
+ @div
59
+ end
60
+
61
+ end
62
+ end
@@ -1,374 +1,376 @@
1
1
  #encoding: utf-8
2
2
 
3
- require 'myerror'
3
+ gem 'myerror'
4
4
  require_relative 'matrix.class'
5
5
 
6
- class Vector
7
- attr_accessor :x, :y, :z, :verbose
8
- attr_reader :matrix_op
9
-
10
- # == Parameters:
11
- # par1::
12
- # The first parameter may be a point coordonate x, or a other Vector.
13
- # If it's a Vector, it will be copied. Else if it is anything else, it will be converted as Float and stored as a abcissa.
14
- # par2,par3::
15
- # Theses optionals parameters are used if the first parameter is not a Vector. If it occure, par2 is mandatory (but not par3).
16
- # They will be stored in @y and @z.
17
- # verbose::
18
- # verbose turn on/off the messages with translate, rotate, ...
19
- #
20
- # == Returns:
21
- # himself
22
- #
23
- # == Errors::
24
- # If a parameter is invalid, it may be crash the programm with an ERR_HIGH
25
- def initialize par1, par2=nil, par3=nil, verbose=true
26
- if par1.is_a?Vector #and par2 == nil and par3 == nil
27
- @x = par1.x
28
- @y = par1.y
29
- @z = par1.z
30
-
31
- elsif par1 != nil and par2 != nil
32
- if par3 == nil
33
- par3 = 1.0
34
- end
35
-
36
- if !Error.isnum?par1 or !Error.isnum?par2 or !Error.isnum?par3
37
- Error.call "Vector::new : a passed argument is not a valid number"
6
+ module EpiMath
7
+ class Vector
8
+ attr_accessor :x, :y, :z, :verbose
9
+ attr_reader :matrix_op
10
+
11
+ # == Parameters:
12
+ # par1::
13
+ # The first parameter may be a point coordonate x, or a other Vector.
14
+ # If it's a Vector, it will be copied. Else if it is anything else, it will be converted as Float and stored as a abcissa.
15
+ # par2,par3::
16
+ # Theses optionals parameters are used if the first parameter is not a Vector. If it occure, par2 is mandatory (but not par3).
17
+ # They will be stored in @y and @z.
18
+ # verbose::
19
+ # verbose turn on/off the messages with translate, rotate, ...
20
+ #
21
+ # == Returns:
22
+ # himself
23
+ #
24
+ # == Errors::
25
+ # If a parameter is invalid, it may be crash the programm with an ERR_HIGH
26
+ def initialize par1, par2=nil, par3=nil, verbose=true
27
+ if par1.is_a?Vector #and par2 == nil and par3 == nil
28
+ @x = par1.x
29
+ @y = par1.y
30
+ @z = par1.z
31
+
32
+ elsif par1 != nil and par2 != nil
33
+ if par3 == nil
34
+ par3 = 1.0
35
+ end
36
+
37
+ if !Error.isnum?par1 or !Error.isnum?par2 or !Error.isnum?par3
38
+ Error.call "Vector::new : a passed argument is not a valid number"
39
+ end
40
+
41
+ @x = par1.to_f
42
+ @y = par2.to_f
43
+ @z = par3.to_f
44
+ else
45
+ Error.call "Vector::new : The vector couldn't be initialisze with theses parameters : :par1 => '#{par1}', :par2 => '#{par2}'"
38
46
  end
39
47
 
40
- @x = par1.to_f
41
- @y = par2.to_f
42
- @z = par3.to_f
43
- else
44
- Error.call "Vector::new : The vector couldn't be initialisze with theses parameters : :par1 => '#{par1}', :par2 => '#{par2}'"
48
+ @verbose = verbose
49
+ @matrix_op = init_matrix_op
50
+ return self
45
51
  end
46
52
 
47
- @verbose = verbose
48
- @matrix_op = init_matrix_op
49
- return self
50
- end
51
-
52
- # Return to the norm of the currenet vector
53
- def norm
54
- Math.sqrt(@x**2 + @y**2 + @z**2)
55
- end
53
+ # Return to the norm of the currenet vector
54
+ def norm
55
+ Math.sqrt(@x**2 + @y**2 + @z**2)
56
+ end
56
57
 
57
- # == Returns:
58
- # Matrix.new [[1, 0, 0],[0, 1, 0], [0, 0, 1]]
59
- def init_matrix_op
60
- @matrix_op = Matrix.new [[1, 0, 0],[0, 1, 0], [0, 0, 1]]
61
- end
58
+ # == Returns:
59
+ # Matrix.new [[1, 0, 0],[0, 1, 0], [0, 0, 1]]
60
+ def init_matrix_op
61
+ @matrix_op = Matrix.new [[1, 0, 0],[0, 1, 0], [0, 0, 1]]
62
+ end
62
63
 
63
- # == Parameters:
64
- # par1::
65
- # It may be a point coordonate x, or a other Vector.
66
- # If it's a Vector, it will be used as a couple of coordonates. Else if it is anything else, it will be converted as Float added to @x
67
- #
68
- # == Returns:
69
- # nothing
70
- #
71
- # == Errors::
72
- # If a parameter is invalid, it may be crash the programm with an ERR_HIGH
73
- # If the vectors do not have the same dimensions, it will display a warning
74
- def +(par1)
75
- out = Vector.new(self)
76
-
77
- if par1 != nil and par1.is_a?Vector #and par2 == nil and par3 == nil
78
- out.x += par1.x
79
- out.y += par1.y
80
-
81
- elsif par1 != nil
82
- par1 = par1.to_f
83
- out.x += par1
84
- out.y += par1
85
-
86
- if out.z != nil and par1 == nil
87
- Error.call "The vector #{Vector.new(par1, par1, par1).to_s} do not have the same dimensions than #{out.to_s}", Error::ERR_HIGH
88
- elsif out.z != nil
89
- out.z += par1
64
+ # == Parameters:
65
+ # par1::
66
+ # It may be a point coordonate x, or a other Vector.
67
+ # If it's a Vector, it will be used as a couple of coordonates. Else if it is anything else, it will be converted as Float added to @x
68
+ #
69
+ # == Returns:
70
+ # nothing
71
+ #
72
+ # == Errors::
73
+ # If a parameter is invalid, it may be crash the programm with an ERR_HIGH
74
+ # If the vectors do not have the same dimensions, it will display a warning
75
+ def +(par1)
76
+ out = Vector.new(self)
77
+
78
+ if par1 != nil and par1.is_a?Vector #and par2 == nil and par3 == nil
79
+ out.x += par1.x
80
+ out.y += par1.y
81
+
82
+ elsif par1 != nil
83
+ par1 = par1.to_f
84
+ out.x += par1
85
+ out.y += par1
86
+
87
+ if out.z != nil and par1 == nil
88
+ Error.call "The vector #{Vector.new(par1, par1, par1).to_s} do not have the same dimensions than #{out.to_s}", Error::ERR_HIGH
89
+ elsif out.z != nil
90
+ out.z += par1
91
+ end
92
+ else
93
+ Error.call "The vector couldn't be added with this parameters : #{par1}", Error::ERR_HIGH
90
94
  end
91
- else
92
- Error.call "The vector couldn't be added with this parameters : #{par1}", Error::ERR_HIGH
95
+ return out
93
96
  end
94
- return out
95
- end
96
97
 
97
- # == Usage:
98
- # It is simply like + buf multiply by -1 par1
99
- def -(par1)
100
- if par1 == nil
101
- Error.call "Can't sub nil from vector"
98
+ # == Usage:
99
+ # It is simply like + buf multiply by -1 par1
100
+ def -(par1)
101
+ if par1 == nil
102
+ Error.call "Can't sub nil from vector"
103
+ end
104
+ return (self.+(par1 * -1))
102
105
  end
103
- return (self.+(par1 * -1))
104
- end
105
106
 
106
- # == Parameters:
107
- # par1:
108
- # This parameter may be a Vector or a number. If it's a Number, it will multiply all coponents of the Vector.
109
- # If it's an other vector, we will multiplie their components 2by2
110
- # == Returns:
111
- # Vector
112
- def *(par1)
113
- out = Vector.new(self)
114
- if par1.is_a?Numeric
115
- out.x *= par1
116
- out.y *= par1
117
- if out.z != nil
118
- out.z *= par1
119
- end
120
- elsif par1.is_a?Matrix
107
+ # == Parameters:
108
+ # par1:
109
+ # This parameter may be a Vector or a number. If it's a Number, it will multiply all coponents of the Vector.
110
+ # If it's an other vector, we will multiplie their components 2by2
111
+ # == Returns:
112
+ # Vector
113
+ def *(par1)
114
+ out = Vector.new(self)
115
+ if par1.is_a?Numeric
116
+ out.x *= par1
117
+ out.y *= par1
118
+ if out.z != nil
119
+ out.z *= par1
120
+ end
121
+ elsif par1.is_a?Matrix
121
122
  return (self.to_matrix * par1).to_vector
122
- elsif par1.is_a?Vector
123
- ary1 = [self.x, self.y]
124
- if out.z != nil
125
- ary1 << out.z
123
+ elsif par1.is_a?Vector
124
+ ary1 = [self.x, self.y]
125
+ if out.z != nil
126
+ ary1 << out.z
127
+ end
128
+
129
+ ary2 = [par1.x, par1.y]
130
+ if out.z != nil
131
+ ary2 << par1.z
132
+ end
133
+
134
+ aryr = Matrix.mult_array(ary1, ary2)
135
+ out.x = aryr[0]
136
+ out.y = aryr[1]
137
+ if aryr[2] != nil
138
+ out.z = aryr[2]
139
+ end
140
+ else
141
+ Error.call "Unable to add '#{par1} to this vector", Error::ERR_HIGH
126
142
  end
143
+ return out
144
+ end
127
145
 
128
- ary2 = [par1.x, par1.y]
129
- if out.z != nil
130
- ary2 << par1.z
146
+ # == Parameters:
147
+ # par1, par2::
148
+ # They are the components of the vector to translate.
149
+ # par3::
150
+ # Optional component (z)
151
+ # see +::
152
+ def translate par1, par2, par3=0.0
153
+ if !Error.isnum? par1 or !Error.isnum? par2 or !Error.isnum? par3
154
+ Error.call "A parameter to the translation is not a valid number", Error::ERR_HIGH
131
155
  end
132
156
 
133
- aryr = Matrix.mult_array(ary1, ary2)
134
- out.x = aryr[0]
135
- out.y = aryr[1]
136
- if aryr[2] != nil
137
- out.z = aryr[2]
138
- end
139
- else
140
- Error.call "Unable to add '#{par1} to this vector", Error::ERR_HIGH
141
- end
142
- return out
143
- end
157
+ s = Matrix.new [[1.0, 0.0, par1.to_f], [0.0, 1.0, par2.to_f], [0.0, 0.0, 1.0]]
158
+ @matrix_op = s
159
+ cpy = self
160
+ cpy.z = 1.0
161
+
162
+ puts "translation de vecteur #{Vector.new(par1,par2,par3).to_s}" if @verbose
144
163
 
145
- # == Parameters:
146
- # par1, par2::
147
- # They are the components of the vector to translate.
148
- # par3::
149
- # Optional component (z)
150
- # see +::
151
- def translate par1, par2, par3=0.0
152
- if !Error.isnum? par1 or !Error.isnum? par2 or !Error.isnum? par3
153
- Error.call "A parameter to the translation is not a valid number", Error::ERR_HIGH
164
+ return (s * cpy.to_matrix).to_vector
154
165
  end
155
166
 
156
- s = Matrix.new [[1.0, 0.0, par1.to_f], [0.0, 1.0, par2.to_f], [0.0, 0.0, 1.0]]
157
- @matrix_op = s
158
- cpy = self
159
- cpy.z = 1.0
167
+ # == Parameters:
168
+ # c1,c2,c3::
169
+ # c1 and c2 are the coeficiens of the homothetie. c3 is optional
170
+ def homothétie c1, c2, c3=1.0
171
+ if c1 == nil or c2 == nil
172
+ Error.call "Coefficients are invalids"
173
+ end
160
174
 
161
- puts "translation de vecteur #{Vector.new(par1,par2,par3).to_s}" if @verbose
175
+ s = Matrix.new [[c1.to_f, 0, 0], [0, c2.to_f, 0], [0, 0, c3.to_f]]
176
+ @matrix_op = s
177
+ cpy = self
178
+ cpy.z = 1.0
162
179
 
163
- return (s * cpy.to_matrix).to_vector
164
- end
180
+ puts "homothétie de rapports #{c1.to_f}, #{c2.to_f}" if @verbose
165
181
 
166
- # == Parameters:
167
- # c1,c2,c3::
168
- # c1 and c2 are the coeficiens of the homothetie. c3 is optional
169
- def homothétie c1, c2, c3=1.0
170
- if c1 == nil or c2 == nil
171
- Error.call "Coefficients are invalids"
182
+ return (s * cpy.to_matrix).to_vector
172
183
  end
173
184
 
174
- s = Matrix.new [[c1.to_f, 0, 0], [0, c2.to_f, 0], [0, 0, c3.to_f]]
175
- @matrix_op = s
176
- cpy = self
177
- cpy.z = 1.0
185
+ # == Parameters:
186
+ # a::
187
+ # The angle in degree
188
+ #
189
+ # == Return value:
190
+ # It returns the vector after the translation.
191
+ def rotate a
192
+ if a == nil
193
+ Error.call "Angle is invalid"
194
+ end
178
195
 
179
- puts "homothétie de rapports #{c1.to_f}, #{c2.to_f}" if @verbose
196
+ rad = Math::PI * a.to_f / 180.0
197
+ cpy = self # copy to have the same value in z
198
+ cpy.z = 0.0
199
+ s = Matrix.new [[ Math.cos(rad), -Math.sin(rad), 0], [Math.sin(rad), Math.cos(rad), 0], [0, 0, 1]]
200
+ @matrix_op = s
180
201
 
181
- return (s * cpy.to_matrix).to_vector
182
- end
202
+ puts "rotation d'angle #{a.to_f}" if @verbose
183
203
 
184
- # == Parameters:
185
- # a::
186
- # The angle in degree
187
- #
188
- # == Return value:
189
- # It returns the vector after the translation.
190
- def rotate a
191
- if a == nil
192
- Error.call "Angle is invalid"
204
+ return (s * cpy.to_matrix).to_vector
193
205
  end
194
206
 
195
- rad = Math::PI * a.to_f / 180.0
196
- cpy = self # copy to have the same value in z
197
- cpy.z = 0.0
198
- s = Matrix.new [[ Math.cos(rad), -Math.sin(rad), 0], [Math.sin(rad), Math.cos(rad), 0], [0, 0, 1]]
199
- @matrix_op = s
207
+ # == Parameters :
208
+ # angle::
209
+ # It is the incline of the line.
210
+ #
211
+ # == Return value:
212
+ # It returns the vector after the translation.
213
+ def symetric angle
214
+ Error.call "Variable angle is not a number (#{angle})", Error::ERR_HIGH if !Error.isnum? angle.to_s
200
215
 
201
- puts "rotation d'angle #{a.to_f}" if @verbose
216
+ rad = Math::PI * angle.to_f / 180.0
217
+ s = Matrix.new [[Math.cos(2 * rad), Math.sin(2 * rad), 0], [Math.sin(2 * rad), -Math.cos(2 * rad), 0], [0, 0, 1]]
218
+ @matrix_op = s
219
+ cpy = self.to_matrix
202
220
 
203
- return (s * cpy.to_matrix).to_vector
204
- end
221
+ puts "symétrie par rapport à un axe incliné de #{angle.to_f} degrés" if @verbose
205
222
 
206
- # == Parameters :
207
- # angle::
208
- # It is the incline of the line.
209
- #
210
- # == Return value:
211
- # It returns the vector after the translation.
212
- def symetric angle
213
- Error.call "Variable angle is not a number (#{angle})", Error::ERR_HIGH if !Error.isnum? angle.to_s
223
+ return (s * cpy).to_vector
224
+ end
214
225
 
215
- rad = Math::PI * angle.to_f / 180.0
216
- s = Matrix.new [[Math.cos(2 * rad), Math.sin(2 * rad), 0], [Math.sin(2 * rad), -Math.cos(2 * rad), 0], [0, 0, 1]]
217
- @matrix_op = s
218
- cpy = self.to_matrix
226
+ # == Params:
227
+ # axe::
228
+ # it must be "x" or "y" (case doesn't checked)
229
+ #
230
+ # == Return:
231
+ # The vector after the projection
232
+ def proj_axe axe="x"
233
+ if !axe.match(/[xy]/i)
234
+ Error.call "Vector::proj_axe '#{axe} is not a valid axe", Error::ERR_HIGH
235
+ end
219
236
 
220
- puts "symétrie par rapport à un axe incliné de #{angle.to_f} degrés" if @verbose
237
+ s = nil
238
+ if axe.match(/x/i)
239
+ s = Matrix.new [[1, 0, 0], [0, 0, 0], [0, 0, 1]]
240
+ else
241
+ s = Matrix.new [[0, 0, 0], [0, 1, 0], [0, 0, 1]]
242
+ end
221
243
 
222
- return (s * cpy).to_vector
223
- end
244
+ @matrix_op = s
245
+ cpy = self.to_matrix
224
246
 
225
- # == Params:
226
- # axe::
227
- # it must be "x" or "y" (case doesn't checked)
228
- #
229
- # == Return:
230
- # The vector after the projection
231
- def proj_axe axe="x"
232
- if !axe.match(/[xy]/i)
233
- Error.call "Vector::proj_axe '#{axe} is not a valid axe", Error::ERR_HIGH
234
- end
247
+ puts "projection sur un axe #{axe}." if @verbose
235
248
 
236
- s = nil
237
- if axe.match(/x/i)
238
- s = Matrix.new [[1, 0, 0], [0, 0, 0], [0, 0, 1]]
239
- else
240
- s = Matrix.new [[0, 0, 0], [0, 1, 0], [0, 0, 1]]
249
+ return (s * cpy).to_vector
241
250
  end
242
251
 
243
- @matrix_op = s
244
- cpy = self.to_matrix
245
-
246
- puts "projection sur un axe #{axe}." if @verbose
247
-
248
- return (s * cpy).to_vector
249
- end
252
+ # == Params:
253
+ # nothing
254
+ # == Return:
255
+ # The vector after the translation
256
+ def symetric_pointo
257
+ return homothétie(-1, -1)
258
+ end
250
259
 
251
- # == Params:
252
- # nothing
253
- # == Return:
254
- # The vector after the translation
255
- def symetric_pointo
256
- return homothétie(-1, -1)
257
- end
260
+ # == Parameters:
261
+ # dim::
262
+ # Option option to choose the desired number of dimension of the vector (if is it in 3d, it will be flattened)
263
+ # type::
264
+ # Optional and not used yet. It specify the format of the string. It may only be String yet.
265
+ #
266
+ # == Returns:
267
+ # String
268
+ def to_s dim=3, type=String
269
+ string = ""
270
+ if type == String
271
+ if @y == nil or dim == 1
272
+ string = "(#{@x.to_f.round(3)})"
273
+ elsif @z == nil or dim == 2
274
+ string = "(#{@x.to_f.round(3)}; #{@y.to_f.round(3)})"
275
+ elsif dim == 3
276
+ string = "(#{@x.to_f.round(3)}; #{@y.to_f.round(3)}; #{@z.to_f.round(3)})"
277
+ else
278
+ Error.call "Vector::to_s : Invalid number of dimension specified"
279
+ end
258
280
 
259
- # == Parameters:
260
- # dim::
261
- # Option option to choose the desired number of dimension of the vector (if is it in 3d, it will be flattened)
262
- # type::
263
- # Optional and not used yet. It specify the format of the string. It may only be String yet.
264
- #
265
- # == Returns:
266
- # String
267
- def to_s dim=3, type=String
268
- string = ""
269
- if type == String
270
- if @y == nil or dim == 1
271
- string = "(#{@x.to_f.round(3)})"
272
- elsif @z == nil or dim == 2
273
- string = "(#{@x.to_f.round(3)}; #{@y.to_f.round(3)})"
274
- elsif dim == 3
275
- string = "(#{@x.to_f.round(3)}; #{@y.to_f.round(3)}; #{@z.to_f.round(3)})"
276
281
  else
277
- Error.call "Vector::to_s : Invalid number of dimension specified"
282
+ Error.call "Vector::to_s : Invalid type conversion", ERR_HIGH
278
283
  end
279
284
 
280
- else
281
- Error.call "Vector::to_s : Invalid type conversion", ERR_HIGH
285
+ return string
282
286
  end
283
287
 
284
- return string
285
- end
286
-
287
- # == Parameters:
288
- # type::
289
- # Optionnal. It specify the format of the array returned. It may be "h" (1) or "w" (0).
290
- # * If it's "w" or 0, the Array will be [x,y]
291
- # * If it's "h" or 1, the Array returned will be [[x],[y]]
292
- #
293
- # == Returns:
294
- # Array or an Array of Array
295
- def to_ary type=0
296
- array = []
297
- if type == 0 or type == "w" # everytime true... for the moment
298
- array << @x << @y
299
- if @z != nil
300
- array << @z
301
- end
302
- else
303
- array << [@x] << [@y]
304
- if @z != nil
305
- array << [@z]
288
+ # == Parameters:
289
+ # type::
290
+ # Optionnal. It specify the format of the array returned. It may be "h" (1) or "w" (0).
291
+ # * If it's "w" or 0, the Array will be [x,y]
292
+ # * If it's "h" or 1, the Array returned will be [[x],[y]]
293
+ #
294
+ # == Returns:
295
+ # Array or an Array of Array
296
+ def to_ary type=0
297
+ array = []
298
+ if type == 0 or type == "w" # everytime true... for the moment
299
+ array << @x << @y
300
+ if @z != nil
301
+ array << @z
302
+ end
303
+ else
304
+ array << [@x] << [@y]
305
+ if @z != nil
306
+ array << [@z]
307
+ end
306
308
  end
309
+ return array
307
310
  end
308
- return array
309
- end
310
311
 
311
- # == Parameters::
312
- # Nothing
313
- #
314
- # == Returns:
315
- # Matrix
316
- def to_matrix
317
- return Matrix.new self.to_ary(1)
318
- end
312
+ # == Parameters::
313
+ # Nothing
314
+ #
315
+ # == Returns:
316
+ # Matrix
317
+ def to_matrix
318
+ return Matrix.new self.to_ary(1)
319
+ end
319
320
 
320
- # == Parameters:
321
- # type::
322
- # It specify the return. It may be String or Array.
323
- #
324
- # == Returns:
325
- # String, Array, nil (see type::)
326
- #
327
- # == Errors:
328
- # nil return occures only if the parameter types:: is not supported.
329
- def to_a type=String
330
- if type == String
331
- return self.to_s
332
- elsif type == Array
333
- return self.to_ary
334
- elsif type == Matrix
335
- return self.to_matrix
336
- else
337
- return nil
321
+ # == Parameters:
322
+ # type::
323
+ # It specify the return. It may be String or Array.
324
+ #
325
+ # == Returns:
326
+ # String, Array, nil (see type::)
327
+ #
328
+ # == Errors:
329
+ # nil return occures only if the parameter types:: is not supported.
330
+ def to_a type=String
331
+ if type == String
332
+ return self.to_s
333
+ elsif type == Array
334
+ return self.to_ary
335
+ elsif type == Matrix
336
+ return self.to_matrix
337
+ else
338
+ return nil
339
+ end
338
340
  end
339
- end
340
341
 
341
- def nil?
342
- if @x == 0 and @y == 0 and @z == 0
343
- true
344
- else
345
- false
342
+ def nil?
343
+ if @x == 0 and @y == 0 and @z == 0
344
+ true
345
+ else
346
+ false
347
+ end
346
348
  end
347
- end
348
349
 
349
- # == Parameters
350
- # type::
351
- # Verify if two vectors are collinear
352
- # == Return:
353
- # True if vector u and v are collinear else false
354
- def collinear? v
355
- Vector::colineaire? @self, v
356
- end
350
+ # == Parameters
351
+ # type::
352
+ # Verify if two vectors are collinear
353
+ # == Return:
354
+ # True if vector u and v are collinear else false
355
+ def collinear? v
356
+ Vector::colineaire? @self, v
357
+ end
357
358
 
358
- def self.collinear? u, v
359
- Error.call "Vector::col : invalid parameters" if !u.is_a?Vector or !v.is_a?Vector
360
- Error.call "Vector::col : vector v1 null", Error::ERR_LOW if u.nil?
361
- Error.call "Vector::col : vector v2 null", Error::ERR_LOW if v.nil?
359
+ def self.collinear? u, v
360
+ Error.call "Vector::col : invalid parameters" if !u.is_a?Vector or !v.is_a?Vector
361
+ Error.call "Vector::col : vector v1 null", Error::ERR_LOW if u.nil?
362
+ Error.call "Vector::col : vector v2 null", Error::ERR_LOW if v.nil?
362
363
 
363
- x = u.y * v.z - u.z * v.y
364
- y = u.z * v.x - u.x * v.z
365
- z = u.x * v.y - u.y * v.x
364
+ x = u.y * v.z - u.z * v.y
365
+ y = u.z * v.x - u.x * v.z
366
+ z = u.x * v.y - u.y * v.x
366
367
 
367
- if x == 0 and y == 0 and z == 0
368
- true
369
- else
370
- false
368
+ if x == 0 and y == 0 and z == 0
369
+ true
370
+ else
371
+ false
372
+ end
371
373
  end
372
- end
373
374
 
375
+ end
374
376
  end
data/lib/epimath100.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  #encoding: utf-8
2
2
 
3
- require "myerror"
3
+ gem "myerror"
4
4
  require_relative "epimath100/line.class.rb"
5
5
  require_relative "epimath100/matrix.class.rb"
6
6
  require_relative "epimath100/point.class.rb"
7
+ require_relative "epimath100/function.class.rb"
7
8
  require_relative "epimath100/polynomial.class.rb"
9
+ require_relative "epimath100/rational.class.rb"
8
10
  require_relative "epimath100/vector.class.rb"
9
11
 
10
- class EpiMath100
12
+ module EpiMath
11
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epimath100
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-02-24 00:00:00.000000000 Z
14
+ date: 2014-03-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: myerror
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - "~>"
21
21
  - !ruby/object:Gem::Version
22
- version: 1.0.0
22
+ version: 1.1.0
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: 1.0.0
@@ -29,28 +29,32 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 1.0.0
32
+ version: 1.1.0
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: 1.0.0
36
- description: A simple hello world gem
36
+ description: EpiMath100, a ruby gem lib to use lines, functions, points, ...
37
37
  email:
38
38
  - poulet_a@epitech.eu
39
39
  - - lib/epimath100.rb
40
40
  - lib/epimath100/line.class.rb
41
41
  - lib/epimath100/matrix.class.rb
42
42
  - lib/epimath100/point.class.rb
43
+ - lib/epimath100/function.class.rb
43
44
  - lib/epimath100/polynomial.class.rb
45
+ - lib/epimath100/rational.class.rb
44
46
  - lib/epimath100/vector.class.rb
45
47
  executables: []
46
48
  extensions: []
47
49
  extra_rdoc_files: []
48
50
  files:
49
51
  - lib/epimath100.rb
52
+ - lib/epimath100/function.class.rb
50
53
  - lib/epimath100/line.class.rb
51
54
  - lib/epimath100/matrix.class.rb
52
55
  - lib/epimath100/point.class.rb
53
56
  - lib/epimath100/polynomial.class.rb
57
+ - lib/epimath100/rational.class.rb
54
58
  - lib/epimath100/vector.class.rb
55
59
  homepage: https://github.com/Sophen/epimath100
56
60
  licenses:
@@ -72,9 +76,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
76
  version: '0'
73
77
  requirements: []
74
78
  rubyforge_project:
75
- rubygems_version: 2.2.0.rc.1
79
+ rubygems_version: 2.2.2
76
80
  signing_key:
77
81
  specification_version: 4
78
- summary: EpiMath100, a ruby gem lib to use lines, functions, points, ...
82
+ summary: Fix function
79
83
  test_files: []
80
84
  has_rdoc: