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
470 471 472 |
# File 'lib/cem/cruzzles.rb', line 470 def x @x end |
#y ⇒ Object
Returns the value of attribute y
470 471 472 |
# File 'lib/cem/cruzzles.rb', line 470 def y @y end |
#z ⇒ Object
Returns the value of attribute z
470 471 472 |
# File 'lib/cem/cruzzles.rb', line 470 def z @z end |
Instance Method Details
#+(other) ⇒ Object
481 |
# File 'lib/cem/cruzzles.rb', line 481 def +(other) Point3D.new(x + other.x, y + other.y, z + other.z) end |
#-(other) ⇒ Object
479 |
# File 'lib/cem/cruzzles.rb', line 479 def -(other) Point3D.new(x - other.x, y - other.y, z - other.z) end |
#[](i) ⇒ Object
500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/cem/cruzzles.rb', line 500 def [](i) case i when 0 x when 1 y when 2 z else raise end end |
#[]=(i, v) ⇒ Object
487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/cem/cruzzles.rb', line 487 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
472 473 474 475 476 477 |
# File 'lib/cem/cruzzles.rb', line 472 def manhattan(other=nil) if other != nil return (self - other).manhattan end return x.abs + y.abs + z.abs end |
#to_s ⇒ Object
483 484 485 |
# File 'lib/cem/cruzzles.rb', line 483 def to_s "#{x}, #{y}, #{z}" end |