lib/vedeu/geometries/position.rb in vedeu-0.8.4 vs lib/vedeu/geometries/position.rb in vedeu-0.8.5

- old
+ new

@@ -42,21 +42,24 @@ new(value, 1) elsif value.is_a?(Hash) new(value.fetch(:y, 1), value.fetch(:x, 1)) + elsif value.is_a?(NilClass) + nil + end end # Initializes a new instance of Vedeu::Geometries::Position. # # @param y [Fixnum] The row/line position. # @param x [Fixnum] The column/character position. # @return [Vedeu::Geometries::Position] def initialize(y = 1, x = 1) - @y = (y.nil? || y < 1) ? 1 : y - @x = (x.nil? || x < 1) ? 1 : x + @y = Vedeu::Point.coerce(value: y, max: Vedeu.height).value + @x = Vedeu::Point.coerce(value: x, max: Vedeu.width).value freeze end # Converts a position into an index for the terminal. An index @@ -85,10 +88,10 @@ # An object is equal when its values are the same. # # @param other [Vedeu::Geometries::Position] # @return [Boolean] def eql?(other) - self.class == other.class && (x == other.x && y == other.y) + self.class == other.class && x == other.x && y == other.y end alias_method :==, :eql? # Return a tuple containing the y and x coordinates. #