Class: Hornetseye::RGB

Inherits:
Object show all
Defined in:
docs/multiarray/lib/multiarray/rgb.rb

Overview

Representation for colour pixel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, g, b) ⇒ RGB

Constructor

Create new RGB object.

Parameters:

  • r (Object)

    Red colour component.

  • g (Object)

    Green colour component.

  • b (Object)

    Blue colour component.



103
104
105
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 103

def initialize( r, g, b )
  @r, @g, @b = r, g, b
end

Instance Attribute Details

#bObject

Access blue channel

Returns:

  • (Object)

    Value of blue channel.



94
95
96
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 94

def b
  @b
end

#gObject

Access green channel

Returns:

  • (Object)

    Value of green channel.



89
90
91
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 89

def g
  @g
end

#rObject

Access red channel

Returns:

  • (Object)

    Value of red channel.



84
85
86
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 84

def r
  @r
end

Instance Method Details

#+@RGB

This operation has no effect

Returns:

  • (RGB)

    Returns self.



150
151
152
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 150

def +@
  self
end

#==(other) ⇒ Boolean

Test on equality

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Returns boolean indicating whether objects are equal or not.



200
201
202
203
204
205
206
207
208
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 200

def ==(other)
  if other.is_a? RGB
    @r.eq( other.r ).and( @g.eq( other.g ) ).and( @b.eq( other.b ) )
  elsif RGB.generic? other
    @r.eq(other).and( @g.eq(other) ).and( @b.eq(other) )
  else
    false
  end
end

#inspectString

Return string with information about this object

Returns:

  • (String)

    Returns a string (e.g. “RGB(1,2,3)”).



110
111
112
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 110

def inspect
  "RGB(#{@r.inspect},#{@g.inspect},#{@b.inspect})"
end

#nonzero?Boolean, GCCValue

Check whether value is not equal to zero

Returns:

  • (Boolean, GCCValue)

    The result.



183
184
185
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 183

def nonzero?
  @r.nonzero?.or( @g.nonzero? ).or( @b.nonzero? )
end

#swap_rgbRGB

Swap colour channels

Returns:

  • (RGB)

    The result.



190
191
192
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 190

def swap_rgb
  RGB.new @b, @g, @r
end

#to_sString

Return string with information about this object

Returns:

  • (String)

    Returns a string (e.g. “RGB(1,2,3)”).



117
118
119
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 117

def to_s
  "RGB(#{@r.to_s},#{@g.to_s},#{@b.to_s})"
end

#zero?Boolean, GCCValue

Check whether value is equal to zero

Returns:

  • (Boolean, GCCValue)

    The result.



176
177
178
# File 'docs/multiarray/lib/multiarray/rgb.rb', line 176

def zero?
  @r.zero?.and( @g.zero? ).and( @b.zero? )
end