Class: Rectangle

Inherits:
Object
  • Object
show all
Defined in:
app/models/rectangle.rb

Overview

This class describes a rectangle.

Direct Known Subclasses

FortressCreator::Area

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) x1

Returns the value of attribute x1



3
4
5
# File 'app/models/rectangle.rb', line 3

def x1
  @x1
end

- (Object) x2

Returns the value of attribute x2



3
4
5
# File 'app/models/rectangle.rb', line 3

def x2
  @x2
end

- (Object) y1

Returns the value of attribute y1



3
4
5
# File 'app/models/rectangle.rb', line 3

def y1
  @y1
end

- (Object) y2

Returns the value of attribute y2



3
4
5
# File 'app/models/rectangle.rb', line 3

def y2
  @y2
end

Instance Method Details

- (Integer) x_center

Return center coordinate of x.

Returns:

  • (Integer)

    x_center x coordinate



7
8
9
# File 'app/models/rectangle.rb', line 7

def x_center
  (@x1 + (@x2 - @x1) / 2).round
end

- (Integer) y_center

Return center coordinate of y.

Returns:

  • (Integer)

    x_center y coordinate



13
14
15
# File 'app/models/rectangle.rb', line 13

def y_center
  (@y1 + (@y2 - @y1) / 2).round
end