<commit_before>### define 
../dimensions : Dimensions
libs/drawing : Drawing
###


class VolumeLayer
  
  constructor : (@plane, @thirdDimensionValue) ->
    
    @contourList = []
    @maxCoord    = null
    @minCoord    = null

  addContour : (pos) ->
    
    @contourList.push(pos)
    @updateArea(pos)


  updateArea : (pos) ->

    unless @maxCoord?
      @maxCoord = pos.slice()
      @minCoord = pos.slice()

    for i in [0..2]
      @minCoord[i] = Math.min(@minCoord[i], Math.floor(pos[i]) - 1)
      @maxCoord[i] = Math.max(@maxCoord[i], Math.ceil(pos[i]) + 1)


  getSmoothedContourList : ->

    return Drawing.smoothLine(@contourList, ( (pos) => @updateArea(pos) ) )


  getVoxelIterator : ->

    unless @minCoord
      return { hasNext : false }

    @addContour( @contourList[0] )

    minCoord2d = @get2DCoordinate(@minCoord)
    maxCoord2d = @get2DCoordinate(@maxCoord)

    # There should be a clear 1-pixel line at each side
    width      = maxCoord2d[0] - minCoord2d[0] + 1 + 2
    height     = maxCoord2d[1] - minCoord2d[1] + 1 + 2
    
    map = new Array(width)
    for x in [0...width]
      map[x] = new Array(height)
      for y in [0...height]
        map[x][y] = true

    setMap = (x, y, value = true) ->

      x = Math.floor(x); y = Math.floor(y)
      map[x - minCoord2d[0] + 1][y - minCoord2d[1] + 1] = value


    # The approach is to initialize the map to true, then
    # draw the outline with false, then fill everything
    # outside the cell with false and then repaint the outline
    # with true.
    #
    # Reason:
    # Unless the shape is something like a ring, the area
    # outside the cell will be in one piece, unlike the inner
    # area if you consider narrow shapes.
    # Also, it will be very clear where to start the filling
    # algorithm.
    @drawOutlineVoxels( (x, y) -> setMap(x, y, false) )
    @fillOutsideArea(map, width, height)
    @drawOutlineVoxels(setMap)
<commit_msg>#183 Fix offset issues<commit_after>### define 
../dimensions : Dimensions
libs/drawing : Drawing
###


class VolumeLayer
  
  constructor : (@plane, @thirdDimensionValue) ->
    
    @contourList = []
    @maxCoord    = null
    @minCoord    = null

  addContour : (pos) ->
    
    @contourList.push(pos)
    @updateArea(pos)


  updateArea : (pos) ->

    unless @maxCoord?
      @maxCoord = pos.slice()
      @minCoord = pos.slice()

    for i in [0..2]
      @minCoord[i] = Math.min(@minCoord[i], Math.floor(pos[i]) - 2)
      @maxCoord[i] = Math.max(@maxCoord[i], Math.ceil(pos[i]) + 2)


  getSmoothedContourList : ->

    return Drawing.smoothLine(@contourList, ( (pos) => @updateArea(pos) ) )


  getVoxelIterator : ->

    unless @minCoord
      return { hasNext : false }

    @addContour( @contourList[0] )

    minCoord2d = @get2DCoordinate(@minCoord)
    maxCoord2d = @get2DCoordinate(@maxCoord)

    width      = maxCoord2d[0] - minCoord2d[0] + 1
    height     = maxCoord2d[1] - minCoord2d[1] + 1
    
    map = new Array(width)
    for x in [0...width]
      map[x] = new Array(height)
      for y in [0...height]
        map[x][y] = true

    setMap = (x, y, value = true) ->

      x = Math.floor(x); y = Math.floor(y)
      map[x - minCoord2d[0]][y - minCoord2d[1]] = value


    # The approach is to initialize the map to true, then
    # draw the outline with false, then fill everything
    # outside the cell with false and then repaint the outline
    # with true.
    #
    # Reason:
    # Unless the shape is something like a ring, the area
    # outside the cell will be in one piece, unlike the inner
    # area if you consider narrow shapes.
    # Also, it will be very clear where to start the filling
    # algorithm.
    @drawOutlineVoxels( (x, y) -> setMap(x, y, false) )
    @fillOutsideArea(map, width, height)
    @drawOutlineVoxels(setMap)

{'fraction_non_alphanumeric': 0.12909138517936633, 'fraction_numerical': 0.015187221785807803, 'mean_word_length': 2.550185873605948, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7660823', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1310, 'n_words': 365}