Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render_tiled_image is broken #1

Open
lilalinux opened this issue Aug 31, 2010 · 1 comment
Open

render_tiled_image is broken #1

lilalinux opened this issue Aug 31, 2010 · 1 comment

Comments

@lilalinux
Copy link

The iterator is wrong, you can't do (0...@tiled_rows) because @tiled_rows is an array. You should iterate over the indexes of @tiled_rows.
spans then is the current index.

(Maybe there is a smarter way to iterate over an array, but actually I don't know anything about ruby)

  1. (0...@tiled_rows.size).each do |spans|
  2. replace all occurences of spans by @tiled_rows[spans]

like this:

render a complete tiled image to gcode and gmask streams

def render_tiled_image gcode, gmask
debug "rendering tiled image"
job_id = job_hash
hyst = -@scale[0]/2
gcode.comment "raster gcode for job #{job_id}"
gcode.comment "image: #{@image.filename} #{@image.size.inspect}"
gcode.comment "config: #{@config.inspect}"

gcode.preamble :feed => @config[:feed], :mask => true
gmask.preamble

@config[:repeat][1].times do |ytile|
  debug "begin tile row #{ytile}"
  ypix = 0
  (0...@tiled_rows.size).each do |spans|
    debug "pixel row #{ypix} is empty" if @tiled_rows[spans].empty?
    unless @tiled_rows[spans].empty?
      yinches = y_inches(ytile, ypix)
      forward = @tiled_rows[spans][0][0] < @tiled_rows[spans][-1][1]
      dir = forward ? 1 : -1

      debug "pixel row #{ypix} at #{yinches} inches going #{forward ? 'forward' : 'backward'} with #{@tiled_rows[spans].size} spans"

      gcode.g0 :x => @tiled_rows[spans][0][0] - dir*@config[:overshoot], :y => yinches
      gcode.g1 :x => @tiled_rows[spans][-1][1] + dir*@config[:overshoot], :y => yinches
      gmask.begin_row forward
      @tiled_rows[spans].each {|span| gmask.span forward, span[0]+hyst, span[1]+hyst }
    end # unless spans.empty?
    ypix += 1
  end # @image.each_row
  debug "end tile row #{ytile}"
end # @config[:repeat][i].times

gcode.epilogue

end # def render_tiled_image

@alown
Copy link
Contributor

alown commented Sep 19, 2011

I have put this into a patch, and sent as a pull request to jebediah.

jedediah added a commit that referenced this issue Sep 20, 2011
Fixes issue #1 - render_tiled_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants