Module: Sumi::Graphics::Mixtures::Duplicate
- Defined in:
- graphics/lib/sumi/graphics/mixtures/duplicate.rb
Overview
DSL helpers for duplicating independent element subtrees.
Instance Method Summary collapse
-
#Duplicate(dx: nil, dy: nil, parent: nil) {|element| ... } ⇒ Sumi::Graphics::Element
Duplicates an element subtree as an independent tree and optionally translates it.
-
#DuplicateX(dx, parent: nil) {|element| ... } ⇒ Sumi::Graphics::Element
Duplicates an element subtree along the x-axis.
-
#DuplicateY(dy, parent: nil) {|element| ... } ⇒ Sumi::Graphics::Element
Duplicates an element subtree along the y-axis.
Instance Method Details
#Duplicate(dx: nil, dy: nil, parent: nil) {|element| ... } ⇒ Sumi::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.
The copied subtree has no parent during customization and is attached to the target parent afterward.
29 30 31 32 33 34 35 |
# File 'graphics/lib/sumi/graphics/mixtures/duplicate.rb', line 29 def Duplicate(dx: nil, dy: nil, parent: nil, &block) dx, dy, target = Subtree.channels(self, dx, dy, parent) duplicated = dup Subtree.prepare(duplicated, &block) Subtree.translate(duplicated, dx, dy) Subtree.attach(duplicated, target) end |
#DuplicateX(dx, parent: nil) {|element| ... } ⇒ Sumi::Graphics::Element
Duplicates an element subtree along the x-axis.
47 48 49 50 |
# File 'graphics/lib/sumi/graphics/mixtures/duplicate.rb', line 47 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| ... } ⇒ Sumi::Graphics::Element
Duplicates an element subtree along the y-axis.
62 63 64 65 |
# File 'graphics/lib/sumi/graphics/mixtures/duplicate.rb', line 62 def DuplicateY(dy, parent: nil, &block) ArgumentError.("Duplicate y translation cannot be nil") if dy.nil? Duplicate(dx: 0, dy:, parent:, &block) end |