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
563 564 565 |
# File 'lib/cem/cruzzles.rb', line 563 def x @x end |
#y ⇒ Object
Returns the value of attribute y
563 564 565 |
# File 'lib/cem/cruzzles.rb', line 563 def y @y end |
#z ⇒ Object
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_s ⇒ Object
576 577 578 |
# File 'lib/cem/cruzzles.rb', line 576 def to_s "#{x}, #{y}, #{z}" end |