Class: Point3D

Inherits:
Struct
  • Object
show all
Defined in:
lib/cem/cruzzles.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



604
605
606
# File 'lib/cem/cruzzles.rb', line 604

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



604
605
606
# File 'lib/cem/cruzzles.rb', line 604

def y
  @y
end

#zObject

Returns the value of attribute z

Returns:

  • (Object)

    the current value of z



604
605
606
# File 'lib/cem/cruzzles.rb', line 604

def z
  @z
end

Instance Method Details

#+(other) ⇒ Object



615
# File 'lib/cem/cruzzles.rb', line 615

def +(other) Point3D.new(x + other.x, y + other.y, z + other.z) end

#-(other) ⇒ Object



613
# File 'lib/cem/cruzzles.rb', line 613

def -(other) Point3D.new(x - other.x, y - other.y, z - other.z) end

#[](i) ⇒ Object



634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/cem/cruzzles.rb', line 634

def [](i)
  case i
    when 0
      x
    when 1
      y
    when 2
      z
    else 
      raise
  end
end

#[]=(i, v) ⇒ Object



621
622
623
624
625
626
627
628
629
630
631
632
# File 'lib/cem/cruzzles.rb', line 621

def []=(i, v)
  case i
    when 0
      self.x = v
    when 1
      self.y = v
    when 2
      self.z = v
    else 
      raise
  end
end

#manhattan(other = nil) ⇒ Object



606
607
608
609
610
611
# File 'lib/cem/cruzzles.rb', line 606

def manhattan(other=nil)
  if other != nil
    return (self - other).manhattan
  end
  return x.abs + y.abs + z.abs
end

#to_sObject



617
618
619
# File 'lib/cem/cruzzles.rb', line 617

def to_s 
  "#{x}, #{y}, #{z}"   
end