Class: Hornetseye::RGB_
- Defined in:
- lib/multiarray/rgb.rb
Defined Under Namespace
Modules: Match
Class Method Summary collapse
-
.==(other) ⇒ Boolean
Test equality of classes.
-
.coerce(other) ⇒ Array<Class>
Type coercion for native elements.
-
.coercion(other) ⇒ Class
Compute balanced type for binary operation.
-
.construct(r, g, b) ⇒ RGB
Construct new object from arguments.
-
.default ⇒ Object
Get default value for elements of this type.
-
.eql?(other) ⇒ Boolean
Equality for hash operations.
-
.float ⇒ Class
Convert to type based on floating point numbers.
-
.hash ⇒ Fixnum
Compute hash value for this class.
-
.inherited(subclass) ⇒ Object
Set base class attribute.
-
.inspect ⇒ String
Diplay information about this class.
-
.maxint ⇒ Class
Get corresponding maximum integer type.
- .rgb? ⇒ Boolean
Instance Method Summary collapse
-
#dup ⇒ RGB_
Duplicate object.
-
#initialize(value = self.class.default) ⇒ RGB_
constructor
A new instance of RGB_.
-
#store(value) ⇒ Object
Store new value in this object.
-
#values ⇒ Array<Object>
Get values of composite number.
Methods inherited from Composite
basetype, descriptor, directive, memory, scalar, storage_size, typecodes
Methods inherited from Element
#compilable?, #descriptor, fetch, #get, #skip, #strip, #write
Methods inherited from Node
===, #[], #[]=, #array_type, array_type, basetype, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, #compilable?, compilable?, cond, contiguous, #decompose, #demand, #descriptor, descriptor, dimension, #dimension, empty?, #empty?, finalised?, #finalised?, float_scalar, floating, #force, #get, height, #height, indgen, #inspect, match, #memory, pointer_type, #pointer_type, #rgb?, scalar, #shape, shape, #simplify, #size, size, #storage_size, strip, #strip, subst, #subst, #to_a, to_s, #to_s, to_type, #typecode, typecode, typecodes, variables, #variables, #width, width
Methods included from FLOAT_::Match
Methods included from OBJECT::Match
Methods included from COMPLEX_::Match
Methods included from Sequence_::Match
Methods included from BOOL::Match
Methods included from Match
Methods included from INT_::Match
Methods included from Operations
#+@, #<=>, #b=, #b_with_decompose, #collect, #conditional, #convolve, define_binary_op, define_unary_op, #diagonal, #eq_with_multiarray, #fill!, #g=, #g_with_decompose, #histogram, #histogram_with_composite, #imag=, #imag_with_decompose, #inject, #integral, #lut, #lut_with_composite, #max, #min, #normalise, #product, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #roll, #sum, #to_type, #to_type_with_rgb, #transpose, #unroll
Constructor Details
#initialize(value = self.class.default) ⇒ RGB_
Returns a new instance of RGB_.
324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/multiarray/rgb.rb', line 324 def initialize( value = self.class.default ) if Thread.current[ :function ].nil? or [ value.r, value.g, value.b ].all? { |c| c.is_a? GCCValue } @value = value else r = GCCValue.new Thread.current[ :function ], value.r.to_s g = GCCValue.new Thread.current[ :function ], value.g.to_s b = GCCValue.new Thread.current[ :function ], value.b.to_s @value = RGB.new r, g, b end end |
Class Method Details
.==(other) ⇒ Boolean
Test equality of classes
293 294 295 296 |
# File 'lib/multiarray/rgb.rb', line 293 def ==( other ) other.is_a? Class and other < RGB_ and element_type == other.element_type end |
.coerce(other) ⇒ Array<Class>
Type coercion for native elements
278 279 280 281 282 283 284 285 286 |
# File 'lib/multiarray/rgb.rb', line 278 def coerce( other ) if other < RGB_ return other, self elsif other < INT_ or other < FLOAT_ return Hornetseye::RGB( other ), self else super other end end |
.coercion(other) ⇒ Class
Compute balanced type for binary operation
261 262 263 264 265 266 267 268 269 |
# File 'lib/multiarray/rgb.rb', line 261 def coercion( other ) if other < RGB_ Hornetseye::RGB element_type.coercion( other.element_type ) elsif other < INT_ or other < FLOAT_ Hornetseye::RGB element_type.coercion( other ) else super other end end |
.construct(r, g, b) ⇒ RGB
Construct new object from arguments
202 203 204 |
# File 'lib/multiarray/rgb.rb', line 202 def construct( r, g, b ) new RGB.new( r, g, b ) end |
.default ⇒ Object
Get default value for elements of this type
211 212 213 |
# File 'lib/multiarray/rgb.rb', line 211 def default RGB.new 0, 0, 0 end |
.eql?(other) ⇒ Boolean
Equality for hash operations
314 315 316 |
# File 'lib/multiarray/rgb.rb', line 314 def eql?( other ) self == other end |
.float ⇒ Class
Convert to type based on floating point numbers
250 251 252 |
# File 'lib/multiarray/rgb.rb', line 250 def float Hornetseye::RGB element_type.float end |
.hash ⇒ Fixnum
Compute hash value for this class.
303 304 305 |
# File 'lib/multiarray/rgb.rb', line 303 def hash [ :RGB_, element_type ].hash end |
.inherited(subclass) ⇒ Object
Set base class attribute
Sets number of elements to three.
189 190 191 |
# File 'lib/multiarray/rgb.rb', line 189 def inherited( subclass ) subclass.num_elements = 3 end |
.inspect ⇒ String
Diplay information about this class
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/multiarray/rgb.rb', line 218 def inspect unless element_type.nil? { BYTE => 'BYTERGB', UBYTE => 'UBYTERGB', SINT => 'SINTRGB', USINT => 'USINTRGB', INT => 'INTRGB', UINT => 'UINTRGB', LONG => 'LONGRGB', ULONG => 'ULONGRGB', SFLOAT => 'SFLOATRGB', DFLOAT => 'DFLOATRGB' }[ element_type ] || "RGB(#{element_type.inspect})" else super end end |
.maxint ⇒ Class
Get corresponding maximum integer type
241 242 243 |
# File 'lib/multiarray/rgb.rb', line 241 def maxint Hornetseye::RGB element_type.maxint end |
.rgb? ⇒ Boolean
318 319 320 |
# File 'lib/multiarray/rgb.rb', line 318 def rgb? true end |
Instance Method Details
#dup ⇒ RGB_
Duplicate object
339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/multiarray/rgb.rb', line 339 def dup if Thread.current[ :function ] r = Thread.current[ :function ].variable self.class.element_type, 'v' g = Thread.current[ :function ].variable self.class.element_type, 'v' b = Thread.current[ :function ].variable self.class.element_type, 'v' r.store @value.r g.store @value.g b.store @value.b self.class.new RGB.new( r, g, b ) else self.class.new get end end |
#store(value) ⇒ Object
Store new value in this object
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/multiarray/rgb.rb', line 360 def store( value ) value = value.simplify if @value.r.respond_to? :store @value.r.store value.get.r else @value.r = value.get.r end if @value.g.respond_to? :store @value.g.store value.get.g else @value.g = value.get.g end if @value.b.respond_to? :store @value.b.store value.get.b else @value.b = value.get.b end value end |