Module: Hornetseye::RGB_::Match

Included in:
Node
Defined in:
lib/multiarray/rgb.rb

Overview

Namespace containing method for matching elements of type RGB_

See Also:

Instance Method Summary collapse

Instance Method Details

#align(context) ⇒ Object

Perform type alignment

Align this type to another. This is used to prefer single-precision floating point in certain cases.

Parameters:

  • context (Class)

    Other type to align with.



507
508
509
510
511
512
513
# File 'lib/multiarray/rgb.rb', line 507

def align(context)
  if self < RGB_
    Hornetseye::RGB element_type.align(context)
  else
    super context
  end
end

#fit(*values) ⇒ Class

Method for matching elements of type RGB_

Parameters:

  • *values (Array<Object>)

    Values to find matching native element type for.

Returns:

  • (Class)

    Native type fitting all values.

See Also:



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/multiarray/rgb.rb', line 474

def fit( *values )
  if values.all? { |value| value.is_a? RGB or value.is_a? Float or
                           value.is_a? Integer }
    if values.any? { |value| value.is_a? RGB }
      elements = values.inject([]) do |arr,value|
        if value.is_a? RGB
          arr + [ value.r, value.g, value.b ]
        else
          arr + [ value ]
        end
      end
      element_fit = fit *elements
      if element_fit == OBJECT
        super *values
      else
        Hornetseye::RGB element_fit
      end
    else
      super *values
    end
  else
    super *values
  end
end