Class: Pdfrb::Model::Type::FunctionExponential

Inherits:
Function show all
Defined in:
lib/pdfrb/model/type/function_exponential.rb

Overview

Type 2 Exponential interpolation function (s8.9.4). Maps t ∈ [0,1] to C0 + (C1 - C0) * t^N. Commonly used for 2-color linear gradients.

Instance Attribute Summary

Attributes inherited from Object

#document, #gen, #oid, #value

Instance Method Summary collapse

Methods inherited from Function

#domain, #exponential?, #function_type, #input_dimension, #output_dimension, #postscript?, #range, #sampled?, #stitching?

Methods inherited from Cos::Dictionary

#[], #[]=, arlington_available?, arlington_default, arlington_key_to_symbol, arlington_loaded_for?, arlington_mark_loaded, arlington_object, arlington_one_type_to_ruby, arlington_required?, arlington_types_to_ruby, arlington_version, define_field, define_field_from_arlington, #delete, #each, each_field, #each_raw, #empty?, field, #initialize, #key?, #keys, lookup_type, own_fields, #pdf_type, register_type, type_map, #validate

Methods inherited from Object

#==, define_type, #deref, #indirect?, #initialize, #must_be_indirect?, #pdf_type, pdf_type

Constructor Details

This class inherits a constructor from Pdfrb::Model::Cos::Dictionary

Instance Method Details

#c0Object



10
# File 'lib/pdfrb/model/type/function_exponential.rb', line 10

def c0; self[:C0]; end

#c1Object



11
# File 'lib/pdfrb/model/type/function_exponential.rb', line 11

def c1; self[:C1]; end

#evaluate(t) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/pdfrb/model/type/function_exponential.rb', line 18

def evaluate(t)
  return nil unless c0 && c1

  arr0 = c0.is_a?(Pdfrb::Model::PdfArray) ? c0.to_a : c0
  arr1 = c1.is_a?(Pdfrb::Model::PdfArray) ? c1.to_a : c1
  n = exponent.to_f
  arr0.each_with_index.map do |a, i|
    a.to_f + ((arr1[i].to_f - a.to_f) * (t**n))
  end
end

#exponentObject



12
# File 'lib/pdfrb/model/type/function_exponential.rb', line 12

def exponent; self[:N] || 1; end

#linear?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/pdfrb/model/type/function_exponential.rb', line 14

def linear?
  exponent == 1
end