internal static IEnumerable<DimensionLayout> LayoutPageDimension(float mapStart, float mapLength, float printableAreaStart, float printableAreaLength, float scaleRatio)
{
// Map coordinates are in mm, so there are 0.2544 map units per page unit.
float mmPerPageUnit = (0.254F * scaleRatio);
// Figure out the length this map part will need on the page, in 1/100 of an inch, given the scale ratio.
float pageLengthNeeded = mapLength / mmPerPageUnit;
// If it fits in the printable area, just center it and a single page suffices. 1/1000 of an inch slop allowed for roundoff issues.
if (pageLengthNeeded <= printableAreaLength + 0.1F) {
float borderAmount = (printableAreaLength - pageLengthNeeded) / 2F;
yield return new DimensionLayout(mapStart, mapLength, printableAreaStart + borderAmount, pageLengthNeeded);
}
else {
// Doesn't fit on one page. How many pages will be needed?
// The minimum amount of overlap is either 1 inch, or 1/6th of the printable area.
float minOverlap = Math.Min(100F, printableAreaLength / 6);
// How many pages?
int numberOfPages = (int)Math.Ceiling((pageLengthNeeded - minOverlap) / (printableAreaLength - minOverlap));
Debug.Assert(numberOfPages >= 2);
// How much overlap will there be between pages (in page units)?
float overlapPage = (numberOfPages * printableAreaLength - pageLengthNeeded) / (numberOfPages - 1);
// And create the pages.
float mapAdvance = (printableAreaLength - overlapPage) * mmPerPageUnit;
for (int i = 0; i < numberOfPages; ++i) {
yield return new DimensionLayout(mapStart + i * mapAdvance, printableAreaLength * mmPerPageUnit, printableAreaStart, printableAreaLength);
}
}
}