Class: Geometry::SizeZero

Inherits:
Object
  • Object
show all
Defined in:
lib/geometry/size_zero.rb

Overview

An object repesenting a zero Size in N-dimensional space

A SizeZero object is a Size that will always compare equal to zero and unequal to everything else, regardless of dimensionality.

Unary operators collapse

Instance Method Summary collapse

Instance Method Details

#*(other) ⇒ Object



56
57
58
# File 'lib/geometry/size_zero.rb', line 56

def *(other)
    self
end

#+(other) ⇒ Object



44
45
46
# File 'lib/geometry/size_zero.rb', line 44

def +(other)
    other
end

#+@Object



35
36
37
# File 'lib/geometry/size_zero.rb', line 35

def +@
    self
end

#-(other) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/geometry/size_zero.rb', line 48

def -(other)
    if other.respond_to? :-@
  -other
    elsif other.respond_to? :map
  other.map {|a| -a }
    end
end

#-@Object



39
40
41
# File 'lib/geometry/size_zero.rb', line 39

def -@
    self
end

#/(other) ⇒ Object



60
61
62
63
64
# File 'lib/geometry/size_zero.rb', line 60

def /(other)
    raise OperationNotDefined unless other.is_a? Numeric
    raise ZeroDivisionError if 0 == other
    self
end

#coerce(other) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/geometry/size_zero.rb', line 20

def coerce(other)
    if other.is_a? Numeric
  [other, 0]
    elsif other.is_a? Array
  [other, Array.new(other.size,0)]
    elsif other.is_a? Vector
  [other, Vector[*Array.new(other.size,0)]]
    else
  [Size[other], Size[Array.new(other.size,0)]]
    end
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# File 'lib/geometry/size_zero.rb', line 11

def eql?(other)
    if other.respond_to? :all?
  other.all? {|e| e.eql? 0}
    else
  other == 0
    end
end