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. Visible id attributes are
moved to non-rendering -id metadata before the optional block runs, allowing the block to derive replacement
ids without rendering duplicates. A pre-existing -id takes precedence over the visible id.
Translation and parent channels are validated before the subtree is copied or the customization block runs.
28 29 30 31 32 33 34 |
# File 'lib/sevgi/graphics/mixtures/duplicate.rb', line 28 def Duplicate(dx: nil, dy: nil, parent: nil, &block) dx, dy, target = Subtree.channels(self, dx, dy, parent) duplicated = Subtree.copy(self) Subtree.prepare(duplicated, &block) Subtree.translate(duplicated, dx, dy) Subtree.attach(duplicated, target) end |
#DuplicateX(dx, parent: nil) {|element| ... } ⇒ Sevgi::Graphics::Element
Duplicates an element subtree along the x-axis.
46 47 48 49 |
# File 'lib/sevgi/graphics/mixtures/duplicate.rb', line 46 def DuplicateX(dx, parent: nil, &block) ArgumentError.("Duplicate x translation cannot be nil") if dx.nil? Duplicate(dx:, dy: 0, parent:, &block) end |
#DuplicateY(dy, parent: nil) {|element| ... } ⇒ Sevgi::Graphics::Element
Duplicates an element subtree along the y-axis.
61 62 63 64 |
# File 'lib/sevgi/graphics/mixtures/duplicate.rb', line 61 def DuplicateY(dy, parent: nil, &block) ArgumentError.("Duplicate y translation cannot be nil") if dy.nil? Duplicate(dx: 0, dy:, parent:, &block) end |