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
-
#Duplicate(dx: nil, dy: nil, parent: nil) {|element| ... } ⇒ Sevgi::Graphics::Element
Duplicates an element subtree as an independent tree and optionally translates it.
-
#DuplicateX(dx, parent: nil) {|element| ... } ⇒ Sevgi::Graphics::Element
Duplicates an element subtree along the x-axis.
-
#DuplicateY(dy, parent: nil) {|element| ... } ⇒ Sevgi::Graphics::Element
Duplicates an element subtree along the y-axis.
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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sevgi/graphics/mixtures/duplicate.rb', line 19 def Duplicate(dx: nil, dy: nil, parent: nil, &block) duplicated = Subtree.copy(self) duplicated.Traverse() do |element| id = element.attributes.delete(:id) element[:"#{ATTRIBUTE_INTERNAL_PREFIX}id"] = id if id block&.call(element) end duplicated.Translate(dx, dy) if dx || dy duplicated.Adopt(parent) duplicated end |
#DuplicateX(dx, parent: nil) {|element| ... } ⇒ Sevgi::Graphics::Element
Duplicates an element subtree along the x-axis.
42 |
# File 'lib/sevgi/graphics/mixtures/duplicate.rb', line 42 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.
51 |
# File 'lib/sevgi/graphics/mixtures/duplicate.rb', line 51 def DuplicateY(dy, parent: nil, &block) = Duplicate(dx: 0, dy:, parent:, &block) |