epimath100 2.0.2 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2858403c795608ec9b39cd293c128f4aa9cf38f1
4
- data.tar.gz: f36ad6e002039349af59f7a5054e2d114c206ed3
3
+ metadata.gz: 5491284570b5ab89257d29563128f7a65320a0c4
4
+ data.tar.gz: a1ac48f035dc440e35107f58bd937061bdc63f81
5
5
  SHA512:
6
- metadata.gz: 17c97f882a7535ab1ca039f51ea545f6d991f7637391f4748500826fa3a3d1a9ce110f42505064367474c8e13c191bce5383f25360508df75bcc539301e72ae6
7
- data.tar.gz: dcda0c27dd1baf1de371af4dfc1f59708245a65a9965fbaefacd3a1806c7a3edf4e9abffe898bbf4c51c4341e857bea1cc52a90e2304447d416664ccd3e16606
6
+ metadata.gz: 10bb395846cda35964f85f9c4a27ddbe6cf868257bd6d564968dcd707024874fb10c82a871213bf3f912e22afffdd40ae6c7b3d7da9fa650b1dc2b85f8332fc2
7
+ data.tar.gz: f8a942b99203d52218e3105a829fbdfe25fa7eb91b3bc35200a3153725871b6f4c6e6d455f0535be95754918953ef6f6dd57a304469dd4cb68442842225cd240
@@ -11,15 +11,23 @@ class Line
11
11
  # == Parameters:
12
12
  # point::
13
13
  # Any point on the line. It must be a Point (../point/point.class.rb)
14
- # vector::
14
+ # param2::
15
15
  # Any vector director of the line. It must be a Vector (../vector/vector.class.rb)
16
- def initialize point, vector
17
- Error.call "Line::new : '#{point}' is not a Point" if !point.is_a?Point
18
- Error.call "Line::new : '#{vector}' is not a Vector" if !vector.is_a?Vector
19
- Error.call "Line::new : '#{vector}' can't be Null" if vector.nil?
20
-
16
+ # It also can be a 2sd point of the line
17
+ def initialize point, param2
21
18
  @point = point
22
- @v_dir = vector
19
+ if param2.is_a?Vector
20
+ @v_dir = param2
21
+ elsif param2.is_a?Point
22
+ #coef = (param2.y - point.y) / (param2.x - coef.x)
23
+ #ordo = point.y - coef * point.x
24
+ @v_dir = Vector.new(param2.x - point.x, param2.y - point2.y)
25
+ else
26
+ Error.call "Line::new : '#{@vector}' is neither a Vector or a Point"
27
+ end
28
+ Error.call "Line::new : '#{@point}' is not a Point" if !@point.is_a?Point
29
+ Error.call "Line::new : '#{@vector}' can't be Null" if @vector.nil?
30
+
23
31
  @equ_para = Line::parametric @point, @v_dir
24
32
  end
25
33
 
@@ -1,40 +1,64 @@
1
1
  #encoding: utf-8
2
2
 
3
- gem 'myerror'
3
+ require 'myerror'
4
4
 
5
5
  module EpiMath
6
+ extend MyError
7
+
6
8
  class Point
7
- def initialize x, y, z
8
- if !x.is_a?Numeric or !y.is_a?Numeric or !z.is_a?Numeric
9
- Error.call "Point::new : a passed argument is not a valid number"
10
- end
11
- @coord = {:x => x.to_f, :y => y.to_f, :z => z.to_f}
9
+ def initialize x, y, z=nil
10
+ MyError::Error.call "Point::new : a passed argument is not a valid number" if (!x.is_a?Numeric or !y.is_a?Numeric or (z != nil and !z.is_a?Numeric))
11
+ @coord = {:x => x.to_f, :y => y.to_f}
12
+ @coord[:z] = z.to_f if z != nil
13
+ end
14
+
15
+ def self.new_a p
16
+ MyError::Error.call "Point::new_a : not a valid array of coord" if !p.is_a?Array or p.size < 2
17
+ return Point.new(*p)
12
18
  end
13
19
 
20
+ # TODO : do not modify @
14
21
  def +(p)
15
22
  if p.is_a?Point
16
- @coord.x += p.x
17
- @coord.y += p.y
18
- @coord.z += p.z
23
+ @coord[:x] += p.x
24
+ @coord[:y] += p.y
25
+ @coord[:z] += p.z if p.z or @coord[:z]
19
26
  elsif p.is_a?Numeric
20
- @coord.x += p
21
- @coord.y += p
22
- @coord.z += p
27
+ @coord[:x] += p
28
+ @coord[:y] += p
29
+ @coord[:z] += p if @coord[:z]
23
30
  else
24
- Error.call "Point::+ : passed argument is invalid"
31
+ MyError::Error.call "Point::+ : passed argument is invalid (#{p.class})"
25
32
  end
33
+ return self
34
+ end
35
+
36
+ def -(p)
37
+ p_ = Point.new(-self.x, -self.y)
38
+ p_ = Point.new(-self.x, -self.y, -self.z) if self.z
39
+ p_ = p_ + p
40
+ return p_
26
41
  end
27
42
 
28
43
  def *(p)
29
- Error.call "Point::+ : passed argument is invalid" if !p.is_a?Numeric
44
+ MyError::Error.call "Point::* : passed argument is invalid" if !p.is_a?Numeric
30
45
 
31
- @coord.x *= p
32
- @coord.y *= p
33
- @coord.z *= p
46
+ @coord[:x] *= p
47
+ @coord[:y] *= p
48
+ @coord[:z] *= p if @coord[:z]
49
+ return self
50
+ end
51
+
52
+ def ==(p)
53
+ MyError::Error.call "Point::== : passed argument is invalid" if !p.is_a?Point
54
+ return true if p.x == self.x and p.y == self.y and p.z == self.z
55
+ return false
34
56
  end
35
57
 
36
58
  def to_s
37
- "(#{self.x}; #{self.y}; #{self.z})"
59
+ str = "(#{self.x}; #{self.y}"
60
+ str += "; #{self.z}" if self.z
61
+ str += ")"
38
62
  end
39
63
 
40
64
  def x
@@ -48,5 +72,36 @@ class Point
48
72
  def z
49
73
  @coord[:z]
50
74
  end
75
+
76
+ def x= v
77
+ @coord[:x] = v
78
+ end
79
+
80
+ def y= v
81
+ @coord[:y] = v
82
+ end
83
+
84
+ def z= v
85
+ @coord[:z] = v
86
+ end
87
+
88
+ def self.get_middle(a, b)
89
+ return Point.get_in(a, b, 0.5)
90
+ end
91
+
92
+ def self.get_in(a, b, p)
93
+ MyError::Error.call "Point::get_in : an argument is not a Point" if !a.is_a?Point or !b.is_a?Point
94
+
95
+ if a.x != b.x and p.is_a?Float and p >= 0 and p <= 1
96
+ coef = ((b.y-a.y) / (b.x-a.x))
97
+ ordonnee = a.y - coef * a.x
98
+ min = [b.x, a.x].min
99
+ max = [b.x, a.x].max
100
+ mid = (max - min) * p
101
+ return Point.new(min + mid, coef * (mid + min) + ordonnee)
102
+ end
103
+ return nil
104
+ end
105
+
51
106
  end
52
107
  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: 2.0.2
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a
@@ -79,6 +79,6 @@ rubyforge_project:
79
79
  rubygems_version: 2.2.2
80
80
  signing_key:
81
81
  specification_version: 4
82
- summary: Fix function
82
+ summary: Better point
83
83
  test_files: []
84
84
  has_rdoc: