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



563
564
565
# File 'lib/cem/cruzzles.rb', line 563

def x
  @x
end

#yObject

Returns the value of attribute y



563
564
565
# File 'lib/cem/cruzzles.rb', line 563

def y
  @y
end

#zObject

Returns the value of attribute z



563
564
565
# File 'lib/cem/cruzzles.rb', line 563

def z
  @z
end

Instance Method Details

#+(other) ⇒ Object



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

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

#-(other) ⇒ Object



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

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

#[](i) ⇒ Object



593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/cem/cruzzles.rb', line 593

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

#[]=(i, v) ⇒ Object



580
581
582
583
584
585
586
587
588
589
590
591
# File 'lib/cem/cruzzles.rb', line 580

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



565
566
567
568
569
570
# File 'lib/cem/cruzzles.rb', line 565

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

#to_sObject



576
577
578
# File 'lib/cem/cruzzles.rb', line 576

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