Class: Vedeu::Geometry::Area

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/geometry/area.rb

Overview

Define an area from dimensions or points.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(y:, yn:, x:, xn:) ⇒ Vedeu::Geometry::Area

Returns a new instance of Vedeu::Area.

Parameters:

  • y (Fixnum)

    The starting row/line position.

  • yn (Fixnum)

    The ending row/line position.

  • x (Fixnum)

    The starting column/character position.

  • xn (Fixnum)

    The ending column/character position.



74
75
76
77
78
79
# File 'lib/vedeu/geometry/area.rb', line 74

def initialize(y:, yn:, x:, xn:)
  @y  = y
  @yn = yn
  @x  = x
  @xn = xn
end

Instance Attribute Details

#xFixnum (readonly) Also known as: left

Returns the left coordinate (column/character start position) of the interface.

Returns:

  • (Fixnum)

    Returns the left coordinate (column/character start position) of the interface.



24
25
26
# File 'lib/vedeu/geometry/area.rb', line 24

def x
  @x
end

#xnFixnum (readonly) Also known as: right

Returns the right coordinate (column/ character end position) of the interface.

Returns:

  • (Fixnum)

    Returns the right coordinate (column/ character end position) of the interface.



30
31
32
# File 'lib/vedeu/geometry/area.rb', line 30

def xn
  @xn
end

#yFixnum (readonly) Also known as: top

Returns the top coordinate (row/line start position) of the interface.

Returns:

  • (Fixnum)

    Returns the top coordinate (row/line start position) of the interface.



12
13
14
# File 'lib/vedeu/geometry/area.rb', line 12

def y
  @y
end

#ynFixnum (readonly) Also known as: bottom

Returns the bottom coordinate (row/line end position) of the interface.

Returns:

  • (Fixnum)

    Returns the bottom coordinate (row/line end position) of the interface.



18
19
20
# File 'lib/vedeu/geometry/area.rb', line 18

def yn
  @yn
end

Class Method Details

.from_attributes(attributes = {}) ⇒ Vedeu::Geometry::Area

Parameters:

  • attributes (Hash) (defaults to: {})

Options Hash (attributes):

  • y (Fixnum)
  • yn (Fixnum)
  • y_yn (Fixnum)
  • y_default (Fixnum)
  • x (Fixnum)
  • xn (Fixnum)
  • x_xn (Fixnum)
  • x_default (Fixnum)
  • maximised (Boolean)
  • horizontal_alignment (Symbol)
  • vertical_alignment (Symbol)

Returns:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vedeu/geometry/area.rb', line 46

def self.from_attributes(attributes = {})
  y_attributes = {
    d:         attributes[:y],
    dn:        attributes[:yn],
    d_dn:      attributes[:y_yn],
    maximised: attributes[:maximised],
    alignment: attributes[:vertical_alignment],
  }
  x_attributes = {
    d:         attributes[:x],
    dn:        attributes[:xn],
    d_dn:      attributes[:x_xn],
    maximised: attributes[:maximised],
    alignment: attributes[:horizontal_alignment],
  }
  y_yn = Vedeu::Geometry::YDimension.pair(y_attributes)
  x_xn = Vedeu::Geometry::XDimension.pair(x_attributes)

  new(y: y_yn[0], yn: y_yn[-1], x: x_xn[0], xn: x_xn[-1])
end

Instance Method Details

#centreArray<Fixnum>

Returns an array containing the centred y and x coordinates of the interface.

Returns:

  • (Array<Fixnum>)


95
96
97
# File 'lib/vedeu/geometry/area.rb', line 95

def centre
  [centre_y, centre_x]
end

#centre_xFixnum

Returns the centred x coordinate (the horizontal centre character) of the interface.

Returns:

  • (Fixnum)


111
112
113
# File 'lib/vedeu/geometry/area.rb', line 111

def centre_x
  (width / 2) + x
end

#centre_yFixnum

Returns the centred y coordinate (the vertical centre row) of the interface.

Returns:

  • (Fixnum)


103
104
105
# File 'lib/vedeu/geometry/area.rb', line 103

def centre_y
  (height / 2) + y
end

#east(offset = 1) ⇒ Fixnum

Returns the column after right by default.

Examples:

`right` or `xn` is 19.

east     # => 20
east(2)  # => 21 (positive goes 'more' east)
east(-4) # => 15 (negative goes west)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


155
156
157
# File 'lib/vedeu/geometry/area.rb', line 155

def east(offset = 1)
  xn + offset
end

#eql?(other) ⇒ Boolean Also known as: ==

An object is equal when its values are the same.

Parameters:

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/vedeu/geometry/area.rb', line 85

def eql?(other)
  self.class == other.class && y == other.y && yn == other.yn &&
    x == other.x && xn == other.xn
end

#heightFixnum

Returns the height of the interface.

Returns:

  • (Fixnum)


118
119
120
# File 'lib/vedeu/geometry/area.rb', line 118

def height
  (y..yn).size
end

#north(offset = 1) ⇒ Fixnum

Returns the row above the top by default.

Examples:

`top` or `y` is 4.

north     # => 3
north(2)  # => 2 (positive goes 'more' north)
north(-4) # => 8 (negative goes south)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


140
141
142
# File 'lib/vedeu/geometry/area.rb', line 140

def north(offset = 1)
  y - offset
end

#south(offset = 1) ⇒ Fixnum

Returns the row below the bottom by default.

Examples:

`bottom` or `yn` is 12.

south     # => 13
south(2)  # => 14 (positive goes 'more' south)
south(-4) # => 8  (negative goes north)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


170
171
172
# File 'lib/vedeu/geometry/area.rb', line 170

def south(offset = 1)
  yn + offset
end

#west(offset = 1) ⇒ Fixnum

Returns the column before left by default.

Examples:

`left` or `x` is 8.

west      # => 7
west(2)   # => 6  (positive goes 'more' west)
west(-4)  # => 12 (negative goes east)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


185
186
187
# File 'lib/vedeu/geometry/area.rb', line 185

def west(offset = 1)
  x - offset
end

#widthFixnum

Returns the width of the interface.

Returns:

  • (Fixnum)


125
126
127
# File 'lib/vedeu/geometry/area.rb', line 125

def width
  (x..xn).size
end