Class: Vedeu::Area
- Inherits:
-
Object
- Object
- Vedeu::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
- .from_dimensions(y_yn:, x_xn:) ⇒ Vedeu::Area
- .from_height_and_width(height:, width:) ⇒ Vedeu::Area
- .from_points(y:, yn:, x:, xn:) ⇒ Vedeu::Area
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::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::Area
Returns a new instance of Vedeu::Area.
53 54 55 56 57 58 |
# File 'lib/vedeu/geometry/area.rb', line 53 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.
18 19 20 |
# File 'lib/vedeu/geometry/area.rb', line 18 def x @x end |
#xn ⇒ Fixnum (readonly) Also known as: right
Returns the right coordinate of the interface.
23 24 25 |
# File 'lib/vedeu/geometry/area.rb', line 23 def xn @xn end |
#y ⇒ Fixnum (readonly) Also known as: top
Returns the top coordinate of the interface.
8 9 10 |
# File 'lib/vedeu/geometry/area.rb', line 8 def y @y end |
#yn ⇒ Fixnum (readonly) Also known as: bottom
Returns the bottom coordinate of the interface.
13 14 15 |
# File 'lib/vedeu/geometry/area.rb', line 13 def yn @yn end |
Class Method Details
.from_dimensions(y_yn:, x_xn:) ⇒ Vedeu::Area
29 30 31 |
# File 'lib/vedeu/geometry/area.rb', line 29 def self.from_dimensions(y_yn:, x_xn:) new(y: y_yn.first, yn: y_yn.last, x: x_xn.first, xn: x_xn.last) end |
.from_height_and_width(height:, width:) ⇒ Vedeu::Area
36 37 38 |
# File 'lib/vedeu/geometry/area.rb', line 36 def self.from_height_and_width(height:, width:) new(y: 1, yn: height, x: 1, xn: width) end |
.from_points(y:, yn:, x:, xn:) ⇒ Vedeu::Area
42 43 44 |
# File 'lib/vedeu/geometry/area.rb', line 42 def self.from_points(y:, yn:, x:, xn:) new(y: y, yn: yn, x: x, xn: xn) end |
Instance Method Details
#centre ⇒ Array<Fixnum>
71 72 73 |
# File 'lib/vedeu/geometry/area.rb', line 71 def centre [centre_y, centre_x] end |
#centre_x ⇒ Fixnum
81 82 83 |
# File 'lib/vedeu/geometry/area.rb', line 81 def centre_x (width / 2) + x end |
#centre_y ⇒ Fixnum
76 77 78 |
# File 'lib/vedeu/geometry/area.rb', line 76 def centre_y (height / 2) + y end |
#east(offset = 1) ⇒ Fixnum
Returns the column after right by default.
121 122 123 |
# File 'lib/vedeu/geometry/area.rb', line 121 def east(offset = 1) xn + offset end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
64 65 66 67 |
# File 'lib/vedeu/geometry/area.rb', line 64 def eql?(other) self.class == other.class && y == other.y && yn == other.yn && x == other.x && xn == other.xn end |
#height ⇒ Fixnum
86 87 88 |
# File 'lib/vedeu/geometry/area.rb', line 86 def height (y..yn).size end |
#north(offset = 1) ⇒ Fixnum
Returns the row above the top by default.
106 107 108 |
# File 'lib/vedeu/geometry/area.rb', line 106 def north(offset = 1) y - offset end |
#south(offset = 1) ⇒ Fixnum
Returns the row below the bottom by default.
136 137 138 |
# File 'lib/vedeu/geometry/area.rb', line 136 def south(offset = 1) yn + offset end |
#west(offset = 1) ⇒ Fixnum
Returns the column before left by default.
151 152 153 |
# File 'lib/vedeu/geometry/area.rb', line 151 def west(offset = 1) x - offset end |
#width ⇒ Fixnum
91 92 93 |
# File 'lib/vedeu/geometry/area.rb', line 91 def width (x..xn).size end |