Class: Point3D
- Inherits:
-
Struct
- Object
- Struct
- Point3D
- Defined in:
- lib/cem/cruzzles.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #[](i) ⇒ Object
- #[]=(i, v) ⇒ Object
- #manhattan(other = nil) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x
604 605 606 |
# File 'lib/cem/cruzzles.rb', line 604 def x @x end |
#y ⇒ Object
Returns the value of attribute y
604 605 606 |
# File 'lib/cem/cruzzles.rb', line 604 def y @y end |
#z ⇒ Object
Returns the value of attribute 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_s ⇒ Object
617 618 619 |
# File 'lib/cem/cruzzles.rb', line 617 def to_s "#{x}, #{y}, #{z}" end |