parameters: (ctx)
docstring: Place the sub images in the atlas
docstring_summary: Place the sub images in the atlas
docstring_tokens: Place the sub images in the atlas
function: def place_sub_images(ctx):
      """ Place the sub images in the atlas """
  
      # Sort the images
      ctx.sub_images.sort(key=sort_image_key_diagonal, reverse=True)
  
      frame = Frame()
      frame.w = ctx.atlas_width
      frame.h = ctx.atlas_height
      frames = []
      frames.append(frame)
  
      unplaced_imgs = []
      for i in range(0, len(ctx.sub_images)):
          unplaced_imgs.append(i)
  
      while len(unplaced_imgs) > 0:
          sub_image = ctx.sub_images[unplaced_imgs[0]]
          unplaced_imgs.pop(0)
  
          printi("Will try to place image \"%s\" of size %ux%d" %
                 (sub_image.image_name, sub_image.width, sub_image.height))
  
          # Find best frame
          best_frame = None
          best_frame_idx = 0
          idx = 0
          for frame in frames:
              if not best_frame or closer_to_00(sub_image, best_frame, frame):
                  best_frame = frame
                  best_frame_idx = idx
              idx += 1
  
          assert best_frame != None, "See file"
  
          # Update the sub_image
          sub_image.atlas_x = best_frame.x + ctx.margin
          sub_image.atlas_y = best_frame.y + ctx.margin
          printi("Image placed in %dx%d" % (sub_image.atlas_x, sub_image.atlas_y))
  
          # Split frame
          frame_top = Frame()
          frame_top.x = best_frame.x + sub_image.mwidth
          frame_top.y = best_frame.y
          frame_top.w = best_frame.w - sub_image.mwidth
          frame_top.h = sub_image.mheight
  
          frame_bottom = Frame()
          frame_bottom.x = best_frame.x
          frame_bottom.y = best_frame.y + sub_image.mheight
          frame_bottom.w = best_frame.w
          frame_bottom.h = best_frame.h - sub_image.mheight
  
          frames.pop(best_frame_idx)
          frames.append(frame_top)
          frames.append(frame_bottom)
function_tokens: def place_sub_images ( ctx ) : # Sort the images ctx . sub_images . sort ( key = sort_image_key_diagonal , reverse = True ) frame = Frame ( ) frame . w = ctx . atlas_width frame . h = ctx . atlas_height frames = [ ] frames . append ( frame ) unplaced_imgs = [ ] for i in range ( 0 , len ( ctx . sub_images ) ) : unplaced_imgs . append ( i ) while len ( unplaced_imgs ) > 0 : sub_image = ctx . sub_images [ unplaced_imgs [ 0 ] ] unplaced_imgs . pop ( 0 ) printi ( "Will try to place image \"%s\" of size %ux%d" % ( sub_image . image_name , sub_image . width , sub_image . height ) ) # Find best frame best_frame = None best_frame_idx = 0 idx = 0 for frame in frames : if not best_frame or closer_to_00 ( sub_image , best_frame , frame ) : best_frame = frame best_frame_idx = idx idx += 1 assert best_frame != None , "See file" # Update the sub_image sub_image . atlas_x = best_frame . x + ctx . margin sub_image . atlas_y = best_frame . y + ctx . margin printi ( "Image placed in %dx%d" % ( sub_image . atlas_x , sub_image . atlas_y ) ) # Split frame frame_top = Frame ( ) frame_top . x = best_frame . x + sub_image . mwidth frame_top . y = best_frame . y frame_top . w = best_frame . w - sub_image . mwidth frame_top . h = sub_image . mheight frame_bottom = Frame ( ) frame_bottom . x = best_frame . x frame_bottom . y = best_frame . y + sub_image . mheight frame_bottom . w = best_frame . w frame_bottom . h = best_frame . h - sub_image . mheight frames . pop ( best_frame_idx ) frames . append ( frame_top ) frames . append ( frame_bottom )