Module: Sevgi::Graphics::Mixtures::Duplicate

Defined in:
lib/sevgi/graphics/mixtures/duplicate.rb

Overview

DSL helpers for duplicating independent element subtrees.

Instance Method Summary collapse

Instance Method Details

#Duplicate(dx: nil, dy: nil, parent: nil) {|element| ... } ⇒ Sevgi::Graphics::Element

Duplicates an element subtree as an independent tree and optionally translates it. Copied elements receive new child arrays, attribute stores, and content arrays. Public id attributes are moved to an internal -id attribute before the optional block runs, allowing the block to derive replacement ids without rendering duplicate public ids.

Parameters:

  • dx (Numeric, nil) (defaults to: nil)

    x translation

  • dy (Numeric, nil) (defaults to: nil)

    y translation

  • parent (Sevgi::Graphics::Element, nil) (defaults to: nil)

    parent for the duplicated subtree

Yields:

  • (element)

    optional customization hook for each copied element

Yield Parameters:

Yield Returns:

  • (Object)

    ignored customization result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when the target parent has a different element class

  • (Sevgi::ArgumentError)

    when copied attributes or contents contain cyclic payloads



21
22
23
24
25
26
# File 'lib/sevgi/graphics/mixtures/duplicate.rb', line 21

def Duplicate(dx: nil, dy: nil, parent: nil, &block)
  duplicated = Subtree.copy(self)
  Subtree.prepare(duplicated, &block)
  Subtree.translate(duplicated, dx, dy)
  Subtree.attach(duplicated, self, parent)
end

#DuplicateX(dx, parent: nil) {|element| ... } ⇒ Sevgi::Graphics::Element

Duplicates an element subtree along the x-axis.

Parameters:

  • dx (Numeric)

    x translation

  • parent (Sevgi::Graphics::Element, nil) (defaults to: nil)

    parent for the duplicated subtree

Yields:

  • (element)

    optional customization hook for each copied element

Yield Parameters:

Yield Returns:

  • (Object)

    ignored customization result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when the target parent has a different element class

  • (Sevgi::ArgumentError)

    when copied attributes or contents contain cyclic payloads



37
# File 'lib/sevgi/graphics/mixtures/duplicate.rb', line 37

def DuplicateX(dx, parent: nil, &block) = Duplicate(dx:, dy: 0, parent:, &block)

#DuplicateY(dy, parent: nil) {|element| ... } ⇒ Sevgi::Graphics::Element

Duplicates an element subtree along the y-axis.

Parameters:

  • dy (Numeric)

    y translation

  • parent (Sevgi::Graphics::Element, nil) (defaults to: nil)

    parent for the duplicated subtree

Yields:

  • (element)

    optional customization hook for each copied element

Yield Parameters:

Yield Returns:

  • (Object)

    ignored customization result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when the target parent has a different element class

  • (Sevgi::ArgumentError)

    when copied attributes or contents contain cyclic payloads



48
# File 'lib/sevgi/graphics/mixtures/duplicate.rb', line 48

def DuplicateY(dy, parent: nil, &block) = Duplicate(dx: 0, dy:, parent:, &block)