|
-
Aug 28th, 2007, 01:15 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Paper size fitting algorithm ?
I'm trying to find a way to automatically determine the best paper size to print a file onto.
Assume you have a list of 2 dimensional paper sizes.
Then given a 2 dimensional image size, find the best paper fit, where "best"
means the smallest paper the image can fit on. Rotation is acceptable - meaning the dimensions can be swapped x <-> y if they give the best fit.
So, given an image 5x9, a page that is 10x5 is acceptable if no other fit is better.
Also assume the list may contain repeats and swapped dimensions.
For example:
image: 209 x 280
available sizes:
1: 215 x 279
2: 279 x 431
3: 431 x 279
4: 215 x 355
5: 184 x 266
6: 297 x 420
7: 210 x 297
8: 165 x 131
9: 190 x 254
In this scenario 2,3, 4, 6 and 7 all would work, but 7 is the "best fit".
1, 5, 8 and 9 are too small.
Does anyone know of an algorithm to calculate this?
Thanks.
-
Aug 28th, 2007, 01:20 PM
#2
Re: Paper size fitting algorithm ?
Sounds pretty straightforward. Just loop through all available sizes. Check both dimensions against both image dimensions. If one image dimension is bigger than both paper dimensions, then the paper is too small. If both dimensions fit, calculate the remaining area. Check the area against the current minimum area; if less then this is your new "best fit".
-
Aug 28th, 2007, 01:52 PM
#3
Thread Starter
Hyperactive Member
Re: Paper size fitting algorithm ?
zaza-
Thanks - I was actually trying that and I thought I had it wrong.
But I went back and checked, and it seems I was not storing the "smallest" properly.
I think it's working now - thanks for the prodding...
-
Aug 28th, 2007, 02:23 PM
#4
Re: Paper size fitting algorithm ?
Jolly good. Don't forget to mark the thread Resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|