0

I have a map representing some terrain. I've worked out how to break this map down into "regions" such as islands, seas, oceans, continents etc. The way the map is broken down is completely arbitrary, I may break it down into political borders.

With each "region" I know about every single pixel that is a part of this "region" as well as each pixels coordinates. I'd like to now dynamically size and position the text that labels it.

First off, getting the size of the text seems fairly straight forward (something like total area * 0.5), but it's the positioning that has me confuddled. I can get the absolute center coordinate, but this is not guaranteed to be in the center of the mass, so positioning the text here may have it completely outside of the "region" (in the case of an U shaped region).

It would be good to curve the path to fit the biggest sized text possible, given a maximum amount of curve. So in the U shape it would also draw in as much of a U shape as possible (staying under the max curve amount) with a text size just big enough to fit within the bounds of the area.

Has anyone got any suggestions or links to help with this? I'm using C++ and SFML2.1 but I'm happy to just get some theory.

2 Answers 2

0

Problem Doesn't looks like like possible to solve in some linear way. But recursion would be possible - here my (ad hoc written) algorithm:

Calculate two rectangles smallest possible (as small as possible to keep text readable) and the largest (max/min x/y coordinates of your shape)

Calculate result rectangle as x/2, y/2of largest rectangle

Check if it's possible to place result rectangle on the map (first check if all corners are possible to place on the map, then check rest of rectangles points - can be optimized by using some grid of points i.e. placed 5px one to other) to check if maps are not

If it's possible to place set the replace the smallest rect with result rect otherwise replace the largest rest with result rect

Repeat as long as smalest != largest - then walue it's your's result

Center of mass calculation is quite easy, but it won't help you much - just imagine something U-shaped - center of mass is outside the shape - anyway:

Calculate total number of pixels of your shape, find vertical line dividing your shape's mass equaly the do this same with horizontal line - you will get the x,y for center of mass (ok, something similar - to calculate it in physical sense you need to check (mass of pixel *distance from center of mass)

0

So I've managed to find a solution using the Maximal Rectangle Problem.

It gives me the bounding box of the best fit area to squash the text into. It doesn't curve it all all, but it's a start. I'll add more answer if I ever work it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.