Class: McBlocky::Rect
- Inherits:
-
Struct
- Object
- Struct
- McBlocky::Rect
- Defined in:
- lib/mcblocky/location.rb
Instance Attribute Summary collapse
-
#x1 ⇒ Object
Returns the value of attribute x1.
-
#x2 ⇒ Object
Returns the value of attribute x2.
-
#y1 ⇒ Object
Returns the value of attribute y1.
-
#y2 ⇒ Object
Returns the value of attribute y2.
-
#z1 ⇒ Object
Returns the value of attribute z1.
-
#z2 ⇒ Object
Returns the value of attribute z2.
Instance Method Summary collapse
- #d ⇒ Object
- #h ⇒ Object
-
#initialize(*args) ⇒ Rect
constructor
A new instance of Rect.
- #p1 ⇒ Object
- #p2 ⇒ Object
- #w ⇒ Object
Constructor Details
#initialize(*args) ⇒ Rect
Returns a new instance of Rect.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mcblocky/location.rb', line 47 def initialize(*args) if args.length == 6 super elsif args.length == 2 super(args[0].x, args[0].y, args[0].z, args[1].x, args[1].y, args[1].z) elsif args.length == 4 if args[0].respond_to? :x super(args[0].x, args[0].y, args[0].z, args[1], args[2], args[3]) elsif args[3].respond_to? :x super(args[0], args[1], args[2], args[3].x, args[3].y, args[3].z) else raise ArgumentError end else raise ArgumentError end if x1 > x2 self.x1, self.x2 = self.x2, self.x1 end if y1 > y2 self.y1, self.y2 = self.y2, self.y1 end if z1 > z2 self.z1, self.z2 = self.z2, self.z1 end end |
Instance Attribute Details
#x1 ⇒ Object
Returns the value of attribute x1
46 47 48 |
# File 'lib/mcblocky/location.rb', line 46 def x1 @x1 end |
#x2 ⇒ Object
Returns the value of attribute x2
46 47 48 |
# File 'lib/mcblocky/location.rb', line 46 def x2 @x2 end |
#y1 ⇒ Object
Returns the value of attribute y1
46 47 48 |
# File 'lib/mcblocky/location.rb', line 46 def y1 @y1 end |
#y2 ⇒ Object
Returns the value of attribute y2
46 47 48 |
# File 'lib/mcblocky/location.rb', line 46 def y2 @y2 end |
#z1 ⇒ Object
Returns the value of attribute z1
46 47 48 |
# File 'lib/mcblocky/location.rb', line 46 def z1 @z1 end |
#z2 ⇒ Object
Returns the value of attribute z2
46 47 48 |
# File 'lib/mcblocky/location.rb', line 46 def z2 @z2 end |
Instance Method Details
#d ⇒ Object
91 92 93 |
# File 'lib/mcblocky/location.rb', line 91 def d z2 - z1 end |
#h ⇒ Object
87 88 89 |
# File 'lib/mcblocky/location.rb', line 87 def h y2 - y1 end |
#p1 ⇒ Object
75 76 77 |
# File 'lib/mcblocky/location.rb', line 75 def p1 @p1 ||= Location.new(x1, y1, z1) end |
#p2 ⇒ Object
79 80 81 |
# File 'lib/mcblocky/location.rb', line 79 def p2 @p2 ||= Location.new(x2, y2, z2) end |
#w ⇒ Object
83 84 85 |
# File 'lib/mcblocky/location.rb', line 83 def w x2 - x1 end |