Class: Vedeu::Geometry::Area
- Inherits:
-
Object
- Object
- Vedeu::Geometry::Area
- Defined in:
- lib/vedeu/geometry/area.rb
Overview
Define an area from dimensions or points.
Instance Attribute Summary collapse
-
#x ⇒ Fixnum
(also: #left)
readonly
Returns the left coordinate of the interface.
-
#xn ⇒ Fixnum
(also: #right)
readonly
Returns the right coordinate of the interface.
-
#y ⇒ Fixnum
(also: #top)
readonly
Returns the top coordinate of the interface.
-
#yn ⇒ Fixnum
(also: #bottom)
readonly
Returns the bottom coordinate of the interface.
Class Method Summary collapse
Instance Method Summary collapse
- #centre ⇒ Array<Fixnum>
- #centre_x ⇒ Fixnum
- #centre_y ⇒ Fixnum
-
#east(offset = 1) ⇒ Fixnum
Returns the column after right by default.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
- #height ⇒ Fixnum
-
#initialize(y:, yn:, x:, xn:) ⇒ Vedeu::Geometry::Area
constructor
Returns a new instance of Vedeu::Area.
-
#north(offset = 1) ⇒ Fixnum
Returns the row above the top by default.
-
#south(offset = 1) ⇒ Fixnum
Returns the row below the bottom by default.
-
#west(offset = 1) ⇒ Fixnum
Returns the column before left by default.
- #width ⇒ Fixnum
Constructor Details
#initialize(y:, yn:, x:, xn:) ⇒ Vedeu::Geometry::Area
Returns a new instance of Vedeu::Area.
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
#x ⇒ Fixnum (readonly) Also known as: left
Returns the left coordinate of the interface.
21 22 23 |
# File 'lib/vedeu/geometry/area.rb', line 21 def x @x end |
#xn ⇒ Fixnum (readonly) Also known as: right
Returns the right coordinate of the interface.
26 27 28 |
# File 'lib/vedeu/geometry/area.rb', line 26 def xn @xn end |
#y ⇒ Fixnum (readonly) Also known as: top
Returns the top coordinate of the interface.
11 12 13 |
# File 'lib/vedeu/geometry/area.rb', line 11 def y @y end |
#yn ⇒ Fixnum (readonly) Also known as: bottom
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
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
#centre ⇒ Array<Fixnum>
88 89 90 |
# File 'lib/vedeu/geometry/area.rb', line 88 def centre [centre_y, centre_x] end |
#centre_x ⇒ Fixnum
98 99 100 |
# File 'lib/vedeu/geometry/area.rb', line 98 def centre_x (width / 2) + x end |
#centre_y ⇒ 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.
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.
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 |
#height ⇒ 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.
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.
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.
168 169 170 |
# File 'lib/vedeu/geometry/area.rb', line 168 def west(offset = 1) x - offset end |
#width ⇒ Fixnum
108 109 110 |
# File 'lib/vedeu/geometry/area.rb', line 108 def width (x..xn).size end |