Class: McBlocky::Rect

Inherits:
Struct
  • Object
show all
Defined in:
lib/mcblocky/location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#x1Object

Returns the value of attribute x1

Returns:

  • (Object)

    the current value of x1



46
47
48
# File 'lib/mcblocky/location.rb', line 46

def x1
  @x1
end

#x2Object

Returns the value of attribute x2

Returns:

  • (Object)

    the current value of x2



46
47
48
# File 'lib/mcblocky/location.rb', line 46

def x2
  @x2
end

#y1Object

Returns the value of attribute y1

Returns:

  • (Object)

    the current value of y1



46
47
48
# File 'lib/mcblocky/location.rb', line 46

def y1
  @y1
end

#y2Object

Returns the value of attribute y2

Returns:

  • (Object)

    the current value of y2



46
47
48
# File 'lib/mcblocky/location.rb', line 46

def y2
  @y2
end

#z1Object

Returns the value of attribute z1

Returns:

  • (Object)

    the current value of z1



46
47
48
# File 'lib/mcblocky/location.rb', line 46

def z1
  @z1
end

#z2Object

Returns the value of attribute z2

Returns:

  • (Object)

    the current value of z2



46
47
48
# File 'lib/mcblocky/location.rb', line 46

def z2
  @z2
end

Instance Method Details

#dObject



91
92
93
# File 'lib/mcblocky/location.rb', line 91

def d
  z2 - z1
end

#hObject



87
88
89
# File 'lib/mcblocky/location.rb', line 87

def h
  y2 - y1
end

#p1Object



75
76
77
# File 'lib/mcblocky/location.rb', line 75

def p1
  @p1 ||= Location.new(x1, y1, z1)
end

#p2Object



79
80
81
# File 'lib/mcblocky/location.rb', line 79

def p2
  @p2 ||= Location.new(x2, y2, z2)
end

#wObject



83
84
85
# File 'lib/mcblocky/location.rb', line 83

def w
  x2 - x1
end