Module: Sevgi::Graphics::Mixtures::Hatch

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

Overview

DSL helpers for drawing geometry values and geometry-derived hatch lines.

Draw delegates to each geometry object's drawing protocol. Hatch first sweeps interior spans through a closed lined element, then draws them. Its angle describes line direction; step is perpendicular spacing. The default initial line passes through element.position. The built-in :inkscape document profile includes this mixture; :minimal, :default, and :html do not.

Hatch materializes separate finite SVG path elements. When only a repeated visual fill matters, use an SVG pattern and leave repetition and clipping to the renderer instead of computing line geometry.

Examples:

Add geometry drawing to a scoped custom profile

profile = Class.new(Sevgi::Graphics::Document::Base)
Sevgi::Graphics::Mixtures.mixin(:Hatch, profile)
region = Sevgi::Geometry::Rect[24, 12]
Sevgi::Graphics.SVG(profile) do
  Draw region.lines, stroke: "silver"
  Hatch region, angle: 30, step: 3, stroke: "black"
end.Render

See Also:

Instance Method Summary collapse

Instance Method Details

#Draw(lines, **kwargs) ⇒ Array<Sevgi::Graphics::Element>

Draws one or more geometry line-like objects into this element.

Examples:

Draw geometry lines into a library-built document

lines = [
  Sevgi::Geometry::Line.([0, 0], [20, 0]),
  Sevgi::Geometry::Line.([0, 5], [20, 5])
]
drawing = Sevgi::Graphics.SVG(:inkscape) { Draw lines, stroke: "silver" }
drawing.Render

Parameters:

  • lines (#draw, Array<#draw>)

    drawable geometry objects

  • kwargs (Hash)

    SVG attributes passed to each draw call

Returns:



39
40
41
# File 'lib/sevgi/graphics/mixtures/hatch.rb', line 39

def Draw(lines, **kwargs)
  Array(lines).map { it.draw(self, **kwargs) }
end

#Hatch(element, angle:, step:, initial: nil, **kwargs) ⇒ Array<Sevgi::Graphics::Element>

Draws hatch lines swept through a geometry element.

Examples:

Hatch a closed geometry shape

region = Sevgi::Geometry::Rect[24, 12, position: [2, 2]]
drawing = Sevgi::Graphics.SVG(:inkscape) do
  Hatch region, angle: 30, step: 3, stroke: "black"
end
drawing.Render

Control the first sweep line explicitly

region = Sevgi::Geometry::Rect[24, 12, position: [2, 2]]
Sevgi::Graphics.SVG(:inkscape) do
  Hatch region, initial: [2, 8], angle: 0, step: 3
end

Parameters:

  • element (Sevgi::Geometry::Element::Lined)

    lined geometry element to sweep

  • angle (Numeric)

    hatch angle in degrees

  • step (Numeric)

    distance between hatch lines

  • initial (Sevgi::Geometry::Point, Array<Numeric>, nil) (defaults to: nil)

    initial sweep point, or nil for element.position

  • kwargs (Hash)

    SVG attributes passed to each draw call

Returns:

Raises:

  • (Sevgi::MissingComponentError)

    when sevgi/geometry is unavailable

  • (Sevgi::Geometry::Operation::OperationInapplicableError)

    when element is not sweepable

  • (Sevgi::Geometry::Error)

    when initial, angle, or step is invalid

  • (Sevgi::Geometry::Operation::OperationError)

    when no hatch lines are found or iteration reaches the limit



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sevgi/graphics/mixtures/hatch.rb', line 65

def Hatch(element, angle:, step:, initial: nil, **kwargs)
  begin
    require "sevgi/geometry"

  rescue ::LoadError => e
    raise unless e.path == "sevgi/geometry"

    MissingComponentError.("sevgi/geometry")
  end

  initial = element.position if initial.nil? && element.is_a?(Geometry::Element::Lined)
  Draw(Geometry::Operation.sweep!(element, initial:, angle:, step:), **kwargs)
end