# Module: EnfEditor::ColorUtils

Included in:
  EEBrepEdge, EEBrepFace, EEBrepSurface, EEBrepVertex, EEBrepVolume

Defined in:
  lib/enfeditor/core_ext/color_utils.rb

## Overview

Mixin module to handle color property

## Instance Method Summary collapse

- #has_material_color? ⇒ Boolean

  Returns true if element has material color.

- #has_material_color_rgb? ⇒ Boolean

  Returns true if element has material color and color type is not alpha.

- #material_color ⇒ EEMaterialColor? (also: #color)

  Returns material color instance or nil for no color.

- #material_color=(material_color) ⇒ Object (also: #color=)

## Instance Method Details

### #has_material_color? ⇒ `Boolean`

Returns true if element has material color.

Examples:

    unless element.has_material_color?
      puts "element has no color"
    end

Returns:

- (`Boolean`) —

  Returns true if element has material color.

See Also:

- EEMaterialColor

Since:

- 0.1.0.0

    57
    58
    59
    60
    # File 'lib/enfeditor/core_ext/color_utils.rb', line 57

    def has_material_color?
      self.has_property(@@propkey_color) and
      self._material_color_property(@@propkey_color).color_type != :unknown
    end

### #has_material_color_rgb? ⇒ `Boolean`

Returns true if element has material color and color type is not alpha.

Examples:

    if element.has_material_color_rgb?
      p rgb = element.color.to_rgb  #=> [1.0, 0.0, 0.0]
    end

Returns:

- (`Boolean`) —

  Returns true if element has material color and color type is not alpha.

See Also:

- EEMaterialColor

Since:

- 0.1.0.0

    70
    71
    72
    73
    # File 'lib/enfeditor/core_ext/color_utils.rb', line 70

    def has_material_color_rgb?
      return false unless self.has_material_color?
      return self.material_color.color_type != :alpha
    end

### #material_color ⇒ `EEMaterialColor`? Also known as: color

Returns material color instance or nil for no color.

Examples:

    color = element.material_color #=> (EEMaterialColor)
    color = element.color          #=> (EEMaterialColor)  same as material_color

Returns:

- (`EEMaterialColor`, `nil`) —

  Returns material color instance or nil for no color.

See Also:

- EEMaterialColor

Since:

- 0.1.0.0

    19
    20
    21
    22
    # File 'lib/enfeditor/core_ext/color_utils.rb', line 19

    def material_color
      return nil unless self.has_material_color?
      self._material_color_property(@@propkey_color)
    end

### #material_color=(material_color) ⇒ `Object` Also known as: color=

Examples:

    face.material_color = volume.material_color
    face.color = volume.color                           # same as material_color

Parameters:

- material_color (`EEMaterialColor`, `nil`) —

  Material color instance or nil for no color.

See Also:

- EEMaterialColor

Since:

- 0.1.0.0

    31
    32
    33
    # File 'lib/enfeditor/core_ext/color_utils.rb', line 31

    def material_color=(material_color)
      self.set_material_color(material_color)
    end