module HexaPDF::Content::ColorSpace::ColorUtils

This module includes utility functions that are useful for all color classes.

Public Class Methods

normalize_value(value, upper) click to toggle source

Normalizes the given color value so that it is in the range from 0.0 to 1.0.

The conversion is done in the following way:

  • If the color value is an Integer, it is converted to a float and divided by upper.

  • If the color value is greater than 1.0, it is set to 1.0.

  • If the color value is less than 0.0, it is set to 0.0.

# File lib/hexapdf/content/color_space.rb, line 154
def normalize_value(value, upper)
  value = value.to_f / upper if value.kind_of?(Integer)
  value.clamp(0, 1)
end

Public Instance Methods

==(other) click to toggle source

Compares this color to another one by looking at their associated color spaces and their components.

# File lib/hexapdf/content/color_space.rb, line 163
def ==(other)
  other.respond_to?(:components) && other.respond_to?(:color_space) &&
    components == other.components && color_space == other.color_space
end

Private Instance Methods

normalize_value(value, upper) click to toggle source

Normalizes the given color value so that it is in the range from 0.0 to 1.0.

The conversion is done in the following way:

  • If the color value is an Integer, it is converted to a float and divided by upper.

  • If the color value is greater than 1.0, it is set to 1.0.

  • If the color value is less than 0.0, it is set to 0.0.

# File lib/hexapdf/content/color_space.rb, line 154
def normalize_value(value, upper)
  value = value.to_f / upper if value.kind_of?(Integer)
  value.clamp(0, 1)
end