Class: Vedeu::Geometry::Coordinate
- Inherits:
-
Object
- Object
- Vedeu::Geometry::Coordinate
- Defined in:
- lib/vedeu/geometry/coordinate.rb
Overview
Crudely corrects out of range values.
Instance Attribute Summary collapse
- #name ⇒ String readonly protected
- #offset ⇒ Fixnum readonly protected
- #type ⇒ Symbol readonly protected
Instance Method Summary collapse
-
#bd ⇒ Fixnum
private
Return the :bx or :by value from the border.
-
#bdn ⇒ Fixnum
private
Return the :bxn or :byn value from the border.
- #border ⇒ Object private
-
#coordinate_type ⇒ Fixnum
private
Ascertain the correct methods to use for determining the coordinates.
-
#d ⇒ Fixnum
private
Return the :x or :y value from the border.
-
#d_dn ⇒ Fixnum
private
Return the :width or :height value from the border.
-
#d_position ⇒ Fixnum
(also: #x, #y)
Returns the coordinate for a given index.
-
#d_range ⇒ Array
private
Returns an array with all coordinates from d to dn.
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#dn_index ⇒ Fixnum
private
Returns the maximum index for an area.
-
#dn_position ⇒ Fixnum
(also: #xn, #yn)
Returns the maximum coordinate for an area.
-
#initialize(attributes = {}) ⇒ Vedeu::Geometry::Coordinate
constructor
Return a new instance of Vedeu::Geometry::Coordinate.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Geometry::Coordinate
Return a new instance of Vedeu::Geometry::Coordinate.
16 17 18 19 20 |
# File 'lib/vedeu/geometry/coordinate.rb', line 16 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#name ⇒ String (readonly, protected)
71 72 73 |
# File 'lib/vedeu/geometry/coordinate.rb', line 71 def name @name end |
#offset ⇒ Fixnum (readonly, protected)
75 76 77 |
# File 'lib/vedeu/geometry/coordinate.rb', line 75 def offset @offset end |
#type ⇒ Symbol (readonly, protected)
79 80 81 |
# File 'lib/vedeu/geometry/coordinate.rb', line 79 def type @type end |
Instance Method Details
#bd ⇒ Fixnum (private)
Return the :bx or :by value from the border.
98 99 100 |
# File 'lib/vedeu/geometry/coordinate.rb', line 98 def bd border.send(coordinate_type[1]) end |
#bdn ⇒ Fixnum (private)
Return the :bxn or :byn value from the border.
105 106 107 |
# File 'lib/vedeu/geometry/coordinate.rb', line 105 def bdn border.send(coordinate_type[2]) end |
#border ⇒ Object (private)
84 85 86 |
# File 'lib/vedeu/geometry/coordinate.rb', line 84 def border @border ||= Vedeu.borders.by_name(name) end |
#coordinate_type ⇒ Fixnum (private)
Ascertain the correct methods to use for determining the coordinates.
122 123 124 125 126 127 128 129 130 |
# File 'lib/vedeu/geometry/coordinate.rb', line 122 def coordinate_type @_type ||= case type when :x then [:x, :bx, :bxn, :width] when :y then [:y, :by, :byn, :height] else fail Vedeu::Error::InvalidSyntax, 'Coordinate type not given, cannot continue.'.freeze end end |
#d ⇒ Fixnum (private)
Return the :x or :y value from the border.
91 92 93 |
# File 'lib/vedeu/geometry/coordinate.rb', line 91 def d border.send(coordinate_type[0]) end |
#d_dn ⇒ Fixnum (private)
Return the :width or :height value from the border.
112 113 114 |
# File 'lib/vedeu/geometry/coordinate.rb', line 112 def d_dn border.send(coordinate_type[3]) end |
#d_position ⇒ Fixnum Also known as: x, y
Returns the coordinate for a given index.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vedeu/geometry/coordinate.rb', line 48 def d_position pos = if offset <= 0 d elsif offset > dn_index dn_position else d_range[offset] end pos = pos < bd ? bd : pos pos = pos > bdn ? bdn : pos pos end |
#d_range ⇒ Array (private)
Returns an array with all coordinates from d to dn.
154 155 156 |
# File 'lib/vedeu/geometry/coordinate.rb', line 154 def d_range (d...dn_position).to_a end |
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
161 162 163 164 165 166 167 |
# File 'lib/vedeu/geometry/coordinate.rb', line 161 def defaults { name: '', offset: nil, type: :x, } end |
#dn_index ⇒ Fixnum (private)
Returns the maximum index for an area.
139 140 141 142 143 |
# File 'lib/vedeu/geometry/coordinate.rb', line 139 def dn_index return 0 if d_dn < 1 d_dn - 1 end |
#dn_position ⇒ Fixnum Also known as: xn, yn
Returns the maximum coordinate for an area.
30 31 32 33 34 |
# File 'lib/vedeu/geometry/coordinate.rb', line 30 def dn_position return 0 if d_dn <= 0 d + d_dn end |