Here are five images of pears and a steel chute:
These are only thumbnails, click them for full size!
(I made these with Algodoo.)
This class of images always has the following properties:
- They are always 400×400 pixels with a white background. (It may not be exactly white since SE images are lossily compressed.)
- They have 1 to 4 identical pears, each rotated and positioned in (almost) any way.
- They have one vertical steel chute that reaches to the bottom of the image.
- Other than the bottom of the chute, the chute and the pear bounding boxes (bounding box example) never touch or go out of the image bounds.
- The bounding boxes of the pears never overlap each other nor overlap the chute.
- The pears may be under the sloped part of the chute, as in B, C, and D. (So the bounding box of the chute may overlap the bounding box of a pear.)
- The chute may have any horizontal and vertical position as long as there is enough room for all the bounding boxes of the pears to fit freely above it (no "barely fits" cases will be tested) and part of the column portion is visible.
Challenge
Write a program that takes in such an image and outputs another 400×400 image with the chute in the same place, but with the pears repositioned so they are all above the chute (so they can fall into it and be juiced and whatnot).
The requirements for the output image are:
- All the pears in the input image must be repositioned such that they are above the chute, between the left and right edge of its funnel. (Above an edge is not ok.)
- Each pear must maintain its rotation angle. (So you should be cutting and pasting the pears, not redrawing them.)
- The pears must not overlap or touch each other or the chute. (The pear bounding boxes may overlap though.)
- The pears must not touch or go out of the image bounds.
Here are examples of valid outputs for the five sample images:
These are only thumbnails, click them for full size!
Note that the input image for E was already a valid output, but rearranging the pears when not technically necessary is just fine.
Details
- Take the filename of the image or the raw image data via stdin/command line/function call.
- Output the image to a file with the name of your choice or output the raw image file data to stdout or simply display the image.
- Any common lossless image file format may be used.
- Graphics and image libraries may be used.
- A few incorrect pixels here and there (due to lossiness or something) is not a big deal. If I can't tell anything is wrong visually then it's probably alright.
The shortest code in bytes wins. Tiebreaker is highest voted post.