class EpiMath::Point

Public Class Methods

get_in(a, b, p) click to toggle source
# File lib/epimath100/point.class.rb, line 92
def self.get_in(a, b, p)
  MyError::Error.call "Point::get_in : an argument is not a Point" if !a.is_a?Point or !b.is_a?Point

  if a.x != b.x and p.is_a?Float and p >= 0 and p <= 1
    coef = ((b.y-a.y) / (b.x-a.x))
    ordonnee = a.y - coef * a.x
    min = [b.x, a.x].min
    max = [b.x, a.x].max
    mid = (max - min) * p
    return Point.new(min + mid, coef * (mid + min) + ordonnee)
  end
  return nil
end
get_middle(a, b) click to toggle source
# File lib/epimath100/point.class.rb, line 88
def self.get_middle(a, b)
  return Point.get_in(a, b, 0.5)
end
new(x, y, z=nil) click to toggle source
# File lib/epimath100/point.class.rb, line 9
def initialize x, y, z=nil
  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))
  @coord = {:x => x.to_f, :y => y.to_f}
  @coord[:z] = z.to_f if z != nil
end
new_a(p) click to toggle source
# File lib/epimath100/point.class.rb, line 15
def self.new_a p
  MyError::Error.call "Point::new_a : not a valid array of coord" if !p.is_a?Array or p.size < 2
  return Point.new(*p)
end

Public Instance Methods

*(p) click to toggle source
# File lib/epimath100/point.class.rb, line 43
def *(p)
  MyError::Error.call "Point::* : passed argument is invalid" if !p.is_a?Numeric

  @coord[:x] *= p
  @coord[:y] *= p
  @coord[:z] *= p if @coord[:z]
  return self
end
+(p) click to toggle source

TODO : do not modify @

# File lib/epimath100/point.class.rb, line 21
def +(p)
  if p.is_a?Point
    @coord[:x] += p.x
    @coord[:y] += p.y
    @coord[:z] += p.z if p.z or @coord[:z]
  elsif p.is_a?Numeric
    @coord[:x] += p
    @coord[:y] += p
    @coord[:z] += p if @coord[:z]
  else
    MyError::Error.call "Point::+ : passed argument is invalid (#{p.class})"
  end
  return self
end
-(p) click to toggle source
# File lib/epimath100/point.class.rb, line 36
def -(p)
  p_ = Point.new(-self.x, -self.y)
  p_ = Point.new(-self.x, -self.y, -self.z) if self.z
  p_ = p_ + p
  return p_
end
==(p) click to toggle source
# File lib/epimath100/point.class.rb, line 52
def ==(p)
  MyError::Error.call "Point::== : passed argument is invalid" if !p.is_a?Point
  return true if p.x == self.x and p.y == self.y and p.z == self.z
  return false
end
to_s() click to toggle source
# File lib/epimath100/point.class.rb, line 58
def to_s
  str  = "(#{self.x}; #{self.y}"
  str += "; #{self.z}" if self.z
  str += ")"
end
x() click to toggle source
# File lib/epimath100/point.class.rb, line 64
def x
  @coord[:x]
end
x=(v) click to toggle source
# File lib/epimath100/point.class.rb, line 76
def x= v
  @coord[:x] = v
end
y() click to toggle source
# File lib/epimath100/point.class.rb, line 68
def y
  @coord[:y]
end
y=(v) click to toggle source
# File lib/epimath100/point.class.rb, line 80
def y= v
  @coord[:y] = v
end
z() click to toggle source
# File lib/epimath100/point.class.rb, line 72
def z
  @coord[:z]
end
z=(v) click to toggle source
# File lib/epimath100/point.class.rb, line 84
def z= v
  @coord[:z] = v
end