Class: Treemap::Rectangle

Inherits:
Object
  • Object
show all
Defined in:
lib/treemap/rectangle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x1, y1, x2, y2) {|_self| ... } ⇒ Rectangle

Returns a new instance of Rectangle.

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
21
22
23
24
# File 'lib/treemap/rectangle.rb', line 17

def initialize(x1, y1, x2, y2)
    @x1 = x1
    @y1 = y1
    @x2 = x2
    @y2 = y2

    yield self if block_given?
end

Instance Attribute Details

#x1Object

Returns the value of attribute x1.



15
16
17
# File 'lib/treemap/rectangle.rb', line 15

def x1
  @x1
end

#x2Object

Returns the value of attribute x2.



15
16
17
# File 'lib/treemap/rectangle.rb', line 15

def x2
  @x2
end

#y1Object

Returns the value of attribute y1.



15
16
17
# File 'lib/treemap/rectangle.rb', line 15

def y1
  @y1
end

#y2Object

Returns the value of attribute y2.



15
16
17
# File 'lib/treemap/rectangle.rb', line 15

def y2
  @y2
end

Instance Method Details

#heightObject



34
35
36
# File 'lib/treemap/rectangle.rb', line 34

def height
    @y2 - @y1
end

#to_sObject



26
27
28
# File 'lib/treemap/rectangle.rb', line 26

def to_s
    "[" + [@x1, @y1, @x2, @y2].join(",") + "]"
end

#widthObject



30
31
32
# File 'lib/treemap/rectangle.rb', line 30

def width
    @x2 - @x1
end