Module: Sevgi

Includes:
Wet
Defined in:
lib/sevgi/graphics/attribute.rb,
lib/sevgi/graphics.rb,
lib/sevgi/graphics/element.rb,
lib/sevgi/graphics/version.rb,
lib/sevgi/graphics/internal/dim.rb,
lib/sevgi/graphics/internal/wet.rb,
lib/sevgi/graphics/mixtures/rdf.rb,
lib/sevgi/graphics/document/base.rb,
lib/sevgi/graphics/document/html.rb,
lib/sevgi/graphics/mixtures/call.rb,
lib/sevgi/graphics/mixtures/core.rb,
lib/sevgi/graphics/mixtures/lint.rb,
lib/sevgi/graphics/mixtures/save.rb,
lib/sevgi/graphics/internal/float.rb,
lib/sevgi/graphics/internal/paper.rb,
lib/sevgi/graphics/auxilary/canvas.rb,
lib/sevgi/graphics/internal/margin.rb,
lib/sevgi/graphics/mixtures/render.rb,
lib/sevgi/graphics/auxilary/content.rb,
lib/sevgi/graphics/auxilary/profile.rb,
lib/sevgi/graphics/document/default.rb,
lib/sevgi/graphics/document/minimal.rb,
lib/sevgi/graphics/document/inkscape.rb,
lib/sevgi/graphics/mixtures/identify.rb,
lib/sevgi/graphics/mixtures/inkscape.rb,
lib/sevgi/graphics/mixtures/validate.rb,
lib/sevgi/graphics/mixtures/wrappers.rb,
lib/sevgi/graphics/mixtures/duplicate.rb,
lib/sevgi/graphics/mixtures/polyfills.rb,
lib/sevgi/graphics/mixtures/replicate.rb,
lib/sevgi/graphics/mixtures/transform.rb,
lib/sevgi/graphics/mixtures/underscore.rb

Overview

Some parts are adapted from github.com/DannyBen/victor (lib/victor/attributes.rb)

Defined Under Namespace

Modules: Function, Graphics, Wet Classes: Error

Constant Summary collapse

Dim =
Data.define(:width, :height, :unit) do
  include Comparable

  def initialize(width:, height:, unit: "mm") = super(width: Float(width), height: Float(height), unit:)

  def <=>(other)                              = deconstruct <=> other.deconstruct

  def eql?(other)                             = self.class == other.class && deconstruct == other.deconstruct

  def hash                                    = [ self.class, *deconstruct ].hash

  def longest                                 = [width, height].max

  def shortest                                = [width, height].min

  alias_method :==,   :eql?
end
ArgumentError =
Class.new(Error)
Paper =
{
  a3:        Dim[297.0, 420.0],
  a4:        Dim[210.0, 297.0],
  a5:        Dim[148.5, 210.0],
  a6:        Dim[105.0, 148.5],
  a7:        Dim[74.25, 105.0],
  b3:        Dim[353.0, 500.0],
  b4:        Dim[250.0, 353.0],
  b5:        Dim[176.5, 250.0],
  b6:        Dim[125.0, 176.5],
  b7:        Dim[88.25, 125.0],
  large:     Dim[130.0, 210.0],
  passport:  Dim[88.0,  125.0],
  pocket:    Dim[90.0,  140.0],
  travelers: Dim[110.0, 210.0],
  us:        Dim[215.9, 279.4],
  xlarge:    Dim[190.0, 250.0]
}.tap do
  def _1.default_proc = proc { |_, key| ArgumentError.("No such paper: #{key}") }

  def _1.default      = :a4
end.freeze
Margin =
Data.define(:top, :right, :bottom, :left) do
  include Comparable

  def initialize(top: nil, right: nil, bottom: nil, left: nil)
    case [ top, right, bottom, left ]
    in Numeric,  Numeric,  Numeric,  Numeric  then # nop
    in Numeric,  Numeric,  Numeric,  NilClass then left                     = right
    in Numeric,  Numeric,  NilClass, NilClass then bottom, left             = top, right
    in Numeric,  NilClass, NilClass, NilClass then bottom, left, right      = top, top, top
    in NilClass, NilClass, NilClass, NilClass then top, bottom, left, right = 0, 0, 0, 0
    end

    super(top: Float(top), right: Float(right), bottom: Float(bottom), left: Float(left))
  end

  def <=>(other)   = deconstruct <=> other.deconstruct

  def change(h, v) = self.class[top + v, right + h, bottom + v, left + h]

  def eql?(other)  = self.class == other.class && deconstruct == other.deconstruct

  def hash         = [ self.class, *deconstruct ].hash

  def htotal       = left + right

  def vtotal       = top + bottom

  alias_method :==,   :eql?
  alias_method :to_a, :deconstruct

  class << self
    def margin(array)
      self[
        *(array = Array(array)[0...(size = Margin.members.size)]).fill(nil, array.size, size - array.size)
      ]
    end

    def zero = (@zero ||= self[0.0, 0.0, 0.0, 0.0])
  end
end

Constants included from Wet

Wet::EMPTY_ARRAY, Wet::EMPTY_HASH, Wet::EMPTY_OPTS, Wet::EMPTY_STRING, Wet::F, Wet::Function, Wet::IDENTITY, Wet::Undefined

Method Summary

Methods included from Wet

included