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.



70
71
72
73
74
75
# File 'lib/vedeu/geometry/area.rb', line 70

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 of the interface.

Returns:

  • (Fixnum)

    Returns the left coordinate of the interface.



21
22
23
# File 'lib/vedeu/geometry/area.rb', line 21

def x
  @x
end

#xnFixnum (readonly) Also known as: right

Returns the right coordinate of the interface.

Returns:

  • (Fixnum)

    Returns the right coordinate of the interface.



26
27
28
# File 'lib/vedeu/geometry/area.rb', line 26

def xn
  @xn
end

#yFixnum (readonly) Also known as: top

Returns the top coordinate of the interface.

Returns:

  • (Fixnum)

    Returns the top coordinate of the interface.



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

def y
  @y
end

#ynFixnum (readonly) Also known as: bottom

Returns the bottom coordinate of the interface.

Returns:

  • (Fixnum)

    Returns the bottom coordinate of the interface.



16
17
18
# File 'lib/vedeu/geometry/area.rb', line 16

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)
  • options (Hash<Symbol => Boolean>)

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vedeu/geometry/area.rb', line 40

def self.from_attributes(attributes = {})
  y_attributes = {
    d:         attributes[:y],
    dn:        attributes[:yn],
    d_dn:      attributes[:y_yn],
    default:   attributes[:y_default],
    maximised: attributes[:maximised],
    centred:   attributes[:centred],
  }
  x_attributes = {
    d:         attributes[:x],
    dn:        attributes[:xn],
    d_dn:      attributes[:x_xn],
    default:   attributes[:x_default],
    maximised: attributes[:maximised],
    centred:   attributes[:centred],
  }
  y_yn = Vedeu::Geometry::Dimension.pair(y_attributes)
  x_xn = Vedeu::Geometry::Dimension.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:

  • (Array<Fixnum>)


88
89
90
# File 'lib/vedeu/geometry/area.rb', line 88

def centre
  [centre_y, centre_x]
end

#centre_xFixnum

Returns:

  • (Fixnum)


98
99
100
# File 'lib/vedeu/geometry/area.rb', line 98

def centre_x
  (width / 2) + x
end

#centre_yFixnum

Returns:

  • (Fixnum)


93
94
95
# File 'lib/vedeu/geometry/area.rb', line 93

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 east)
east(-4) # => 15 (negative goes west)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


138
139
140
# File 'lib/vedeu/geometry/area.rb', line 138

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)


81
82
83
84
# File 'lib/vedeu/geometry/area.rb', line 81

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

#heightFixnum

Returns:

  • (Fixnum)


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

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 north)
north(-4) # => 8 (negative goes south)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


123
124
125
# File 'lib/vedeu/geometry/area.rb', line 123

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 south)
south(-4) # => 8  (negative goes north)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


153
154
155
# File 'lib/vedeu/geometry/area.rb', line 153

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 west)
west(-4)  # => 12 (negative goes east)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


168
169
170
# File 'lib/vedeu/geometry/area.rb', line 168

def west(offset = 1)
  x - offset
end

#widthFixnum

Returns:

  • (Fixnum)


108
109
110
# File 'lib/vedeu/geometry/area.rb', line 108

def width
  (x..xn).size
end