Sha256: c9860d39ebb3830a78a57fbab18585d5e0d02497f559c30bd0622c5c77ad1a45

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Gruff
  # @private
  class Renderer::Line
    EPSILON = 0.001

    def initialize(renderer, color:, width: nil)
      @renderer = renderer
      @color = color
      @width = width
    end

    def render(start_x, start_y, end_x, end_y)
      render_line(start_x, start_y, end_x, end_y, @color)
    end

  private

    def render_line(start_x, start_y, end_x, end_y, color)
      # FIXME(uwe): Workaround for Issue #66
      #             https://github.com/topfunky/gruff/issues/66
      #             https://github.com/rmagick/rmagick/issues/82
      #             Remove if the issue gets fixed.
      unless defined?(JRUBY_VERSION)
        start_x += EPSILON
        end_x += EPSILON
        start_y += EPSILON
        end_y += EPSILON
      end

      @renderer.draw.push
      @renderer.draw.stroke(color)
      @renderer.draw.fill(color)
      @renderer.draw.stroke_width(@width) if @width
      @renderer.draw.line(start_x, start_y, end_x, end_y)
      @renderer.draw.pop
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gruff-0.18.0-java lib/gruff/renderer/line.rb
gruff-0.18.0 lib/gruff/renderer/line.rb
gruff-0.17.0-java lib/gruff/renderer/line.rb
gruff-0.17.0 lib/gruff/renderer/line.rb
gruff-0.16.0 lib/gruff/renderer/line.rb
gruff-0.16.0-java lib/gruff/renderer/line.rb