Class: Vedeu::Cursors::Coordinate Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vedeu/cursors/coordinate.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Crudely corrects out of range values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Cursors::Coordinate

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a new instance of Vedeu::Cursors::Coordinate.

Parameters:

  • attributes (Hash<Symbol => Fixnum|String|Symbol>) (defaults to: {})

Options Hash (attributes):



28
29
30
31
32
# File 'lib/vedeu/cursors/coordinate.rb', line 28

def initialize(attributes = {})
  defaults.merge!(attributes).each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#geometryVedeu::Geometries::Geometry (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
# File 'lib/vedeu/cursors/coordinate.rb', line 70

def geometry
  @geometry
end

#offsetFixnum (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


74
75
76
# File 'lib/vedeu/cursors/coordinate.rb', line 74

def offset
  @offset
end

#typeSymbol (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Symbol)


78
79
80
# File 'lib/vedeu/cursors/coordinate.rb', line 78

def type
  @type
end

Instance Method Details

#coordinateVedeu::XCoordinate|Vedeu::YCoordinate (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



84
85
86
87
88
89
90
91
92
# File 'lib/vedeu/cursors/coordinate.rb', line 84

def coordinate
  @_coordinate ||= case type
                   when :x then Vedeu::XCoordinate.new(geometry)
                   when :y then Vedeu::YCoordinate.new(geometry)
                   else
                     raise Vedeu::Error::InvalidSyntax,
                           'Coordinate type not given, cannot continue.'
                   end
end

#d_positionFixnum Also known as: x, y

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the coordinate for a given index.

Examples:

# d_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
position     # => 4
position(-2) # => 4
position(2)  # => 6
position(15) # => 13

Returns:

  • (Fixnum)


60
61
62
# File 'lib/vedeu/cursors/coordinate.rb', line 60

def d_position
  Vedeu::Point.coerce(value: position, min: bd, max: bdn).value
end

#d_rangeArray (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an array with all coordinates from d to dn.

Examples:

# d_dn = 10
# d = 4
# dn = 14
d_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

Returns:

  • (Array)


116
117
118
# File 'lib/vedeu/cursors/coordinate.rb', line 116

def d_range
  (d...dn_position).to_a
end

#defaultsHash<Symbol => void> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


121
122
123
124
125
126
127
# File 'lib/vedeu/cursors/coordinate.rb', line 121

def defaults
  {
    geometry: nil,
    offset:   nil,
    type:     :x,
  }
end

#dn_indexFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the maximum index for an area.

Examples:

# d_dn = 3
dn_index # => 2

Returns:

  • (Fixnum)


101
102
103
104
105
# File 'lib/vedeu/cursors/coordinate.rb', line 101

def dn_index
  return 0 if d_dn < 1

  d_dn - 1
end

#dn_positionFixnum Also known as: xn, yn

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the maximum coordinate for an area.

Examples:

# d = 2
# d_dn = 4 # represents width or height
dn # => 6

Returns:

  • (Fixnum)


42
43
44
45
46
# File 'lib/vedeu/cursors/coordinate.rb', line 42

def dn_position
  return 0 if d_dn <= 0

  d + d_dn
end

#positionFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the position respective of the offset.

Returns:

  • (Fixnum)


132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/vedeu/cursors/coordinate.rb', line 132

def position
  if offset <= 0
    d

  elsif offset > dn_index
    dn_position

  else
    d_range[offset]

  end
end