Module: Sumi::Graphics::Mixtures::Wrappers
- Defined in:
- graphics/lib/sumi/graphics/mixtures/wrappers.rb
Overview
DSL wrappers for common SVG shapes and content patterns.
Instance Method Summary collapse
-
#ArcBy(dx:, dy:, rx:, ry:, x: 0, y: 0, rotation: 0, large: false, sweep: false) ⇒ Sumi::Graphics::Element
Builds an elliptical arc path ending at a relative offset.
-
#ArcTo(x2:, y2:, rx:, ry:, x1: 0, y1: 0, rotation: 0, large: false, sweep: false) ⇒ Sumi::Graphics::Element
Builds an elliptical arc path ending at an absolute point.
-
#css(hash = nil, **attributes) ⇒ Sumi::Graphics::Element
Builds a style element with CSS content.
-
#HLineBy(length:, x: 0, y: 0) ⇒ Sumi::Graphics::Element
Builds a relative horizontal line path.
-
#HLineTo(x2:, x1: 0, y1: 0) ⇒ Sumi::Graphics::Element
Builds a horizontal line path ending at an absolute x coordinate.
-
#LineBy(angle:, length:, x: 0, y: 0) ⇒ Sumi::Graphics::Element
Builds a relative line path from angle and length.
-
#LineTo(x2:, y2:, x1: 0, y1: 0) ⇒ Sumi::Graphics::Element
Builds a line path ending at an absolute point.
-
#square(length:) ⇒ Sumi::Graphics::Element
Builds a square rect.
-
#Symbol(name, **kwargs) { ... } ⇒ Sumi::Graphics::Element
Builds a titled SVG symbol.
-
#VLineBy(length:, x: 0, y: 0) ⇒ Sumi::Graphics::Element
Builds a relative vertical line path.
-
#VLineTo(y2:, x1: 0, y1: 0) ⇒ Sumi::Graphics::Element
Builds a vertical line path ending at an absolute y coordinate.
Instance Method Details
#ArcBy(dx:, dy:, rx:, ry:, x: 0, y: 0, rotation: 0, large: false, sweep: false) ⇒ Sumi::Graphics::Element
Builds an elliptical arc path ending at a relative offset.
47 48 49 50 51 52 53 54 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 47 def ArcBy(dx:, dy:, rx:, ry:, x: 0, y: 0, rotation: 0, large: false, sweep: false, **) x, y, dx, dy, rx, ry, rotation = Scalar.numbers([x, y, dx, dy, rx, ry, rotation], context: "relative arc") unless [large, sweep].all? { it.equal?(true) || it.equal?(false) } ArgumentError.("Arc flags must be Boolean") end path(d: "M #{x} #{y} a #{rx} #{ry} #{rotation} #{large ? 1 : 0} #{sweep ? 1 : 0} #{dx} #{dy}", **) end |
#ArcTo(x2:, y2:, rx:, ry:, x1: 0, y1: 0, rotation: 0, large: false, sweep: false) ⇒ Sumi::Graphics::Element
Builds an elliptical arc path ending at an absolute point. SVG resolves the ellipse from its endpoints, radii, and flags, including radius correction and zero radii.
25 26 27 28 29 30 31 32 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 25 def ArcTo(x2:, y2:, rx:, ry:, x1: 0, y1: 0, rotation: 0, large: false, sweep: false, **) x1, y1, x2, y2, rx, ry, rotation = Scalar.numbers([x1, y1, x2, y2, rx, ry, rotation], context: "absolute arc") unless [large, sweep].all? { it.equal?(true) || it.equal?(false) } ArgumentError.("Arc flags must be Boolean") end path(d: "M #{x1} #{y1} A #{rx} #{ry} #{rotation} #{large ? 1 : 0} #{sweep ? 1 : 0} #{x2} #{y2}", **) end |
#css(hash = nil, **attributes) ⇒ Sumi::Graphics::Element
Builds a style element with CSS content.
146 147 148 149 150 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 146 def css(hash = nil, **attributes) hash, attributes = attributes, {} if hash.nil? style(Content.css(hash), type: "text/css", **attributes) end |
#HLineBy(length:, x: 0, y: 0) ⇒ Sumi::Graphics::Element
Builds a relative horizontal line path.
158 159 160 161 162 163 164 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 158 def HLineBy(length:, x: 0, y: 0, **) length = Scalar.number(length, context: "horizontal line", field: :length) x = Scalar.number(x, context: "horizontal line", field: :x) y = Scalar.number(y, context: "horizontal line", field: :y) path(d: "M #{x} #{y} h #{length}", **) end |
#HLineTo(x2:, x1: 0, y1: 0) ⇒ Sumi::Graphics::Element
Builds a horizontal line path ending at an absolute x coordinate.
81 82 83 84 85 86 87 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 81 def HLineTo(x2:, x1: 0, y1: 0, **) x1 = Scalar.number(x1, context: "horizontal line", field: :x1) y1 = Scalar.number(y1, context: "horizontal line", field: :y1) x2 = Scalar.number(x2, context: "horizontal line", field: :x2) path(d: "M #{x1} #{y1} H #{x2}", **) end |
#LineBy(angle:, length:, x: 0, y: 0) ⇒ Sumi::Graphics::Element
Builds a relative line path from angle and length.
133 134 135 136 137 138 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 133 def LineBy(angle:, length:, x: 0, y: 0, **) angle, length, x, y = Scalar.numbers([angle, length, x, y], context: "relative line") dx, dy = Scalar.numbers([length * F.cos(angle), length * F.sin(angle)], context: "relative line result") path(d: "M #{x} #{y} l #{dx} #{dy}", **) end |
#LineTo(x2:, y2:, x1: 0, y1: 0) ⇒ Sumi::Graphics::Element
Builds a line path ending at an absolute point.
66 67 68 69 70 71 72 73 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 66 def LineTo(x2:, y2:, x1: 0, y1: 0, **) x1 = Scalar.number(x1, context: "absolute line", field: :x1) y1 = Scalar.number(y1, context: "absolute line", field: :y1) x2 = Scalar.number(x2, context: "absolute line", field: :x2) y2 = Scalar.number(y2, context: "absolute line", field: :y2) path(d: "M #{x1} #{y1} L #{x2} #{y2}", **) end |
#square(length:) ⇒ Sumi::Graphics::Element
Builds a square rect.
170 171 172 173 174 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 170 def square(length:, **) length = Scalar.number(length, context: "square", field: :length) rect(width: length, height: length, **) end |
#Symbol(name, **kwargs) { ... } ⇒ Sumi::Graphics::Element
Builds a titled SVG symbol.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 96 def Symbol(name, **kwargs, &block) unless name.is_a?(::String) && !(words = name.split).empty? ArgumentError.("Symbol name must be a non-empty String") end ArgumentError.("Block required") unless block id = words.map(&:downcase).join("-") title = words.map(&:capitalize).join(" ") symbol(id:, **kwargs) do title(title) Within(&block) end end |
#VLineBy(length:, x: 0, y: 0) ⇒ Sumi::Graphics::Element
Builds a relative vertical line path.
182 183 184 185 186 187 188 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 182 def VLineBy(length:, x: 0, y: 0, **) length = Scalar.number(length, context: "vertical line", field: :length) x = Scalar.number(x, context: "vertical line", field: :x) y = Scalar.number(y, context: "vertical line", field: :y) path(d: "M #{x} #{y} v #{length}", **) end |
#VLineTo(y2:, x1: 0, y1: 0) ⇒ Sumi::Graphics::Element
Builds a vertical line path ending at an absolute y coordinate.
118 119 120 121 122 123 124 |
# File 'graphics/lib/sumi/graphics/mixtures/wrappers.rb', line 118 def VLineTo(y2:, x1: 0, y1: 0, **) x1 = Scalar.number(x1, context: "vertical line", field: :x1) y1 = Scalar.number(y1, context: "vertical line", field: :y1) y2 = Scalar.number(y2, context: "vertical line", field: :y2) path(d: "M #{x1} #{y1} V #{y2}", **) end |