# remap a distribution of objects

I have an array of N number of rectangles, each if WxH in size (all the same) each object has an X,Y coordinate which are in a virtual space (0,0)->(Ws,Hs)

I need to alter the coordinates (X,Y) but NOT the size (W,H) to a physical space (Left,Top)-(Width,Height)

So that the new Coordinate in the phsyical space is based on the percentage of its location in the virtual space. Meaning if the object Y value is 50% of Hs then its new value is 50% of Height offset by Top

I thought it would be “easy”. Find the min/max values, normalize all the coodinates to 0,0, divide them all by the (max-min) value to convert to a percentage, multiply that by the height of the physical space (Height-Top) and offset by top

Then all of the objects need to be further adjusted to “center” the collection in the physical space

For X coodinates there is no issue, as the Virtual and Physical are the same width, and so far everything I have done it still comes out wrong

What are you trying to accomplish? I mean visually.
What is your code so far?
What is “coming out wrong”?

[quote]if the object Y value is 50% of Hs then its new value is 50% of Height offset by Top
For X coodinates there is no issue, as the Virtual and Physical are the same width[/quote]

So you might have this in virtual

[code]AAA BBB CCC

DDD EEE FFF[/code]

And need

[code]AAA BBB CCC

DDD EEE FFF[/code]
in physical because the physical is a larger space.
because it is larger, the spaces between ‘rows’ will be bigger but the objects remain the same size.
Rather like placing lego bricks on a sheet of rubber and pulling one end.

With apologies if I have misunderstood:

[code]dim Mn as double = 9999999
//for each object
if Object.Y <Mn then Mn = Object.Y
//next

//for each object
Object.Y = Object.Y - Mn //normalise everything so that the group ‘starts’ at 0
Object.Y = Object.Y * (Physical Height / Virtual Height) // adjust for new spacing
//next

Dim Offset as double = 0
//for each object
if Object.Y > Offset then Offset = Object.Y
//next
Offset = Offset/2

//for each object
Object.Y = Object.Y + Offset //centre the objects around the new centre
//next[/code]

Its akin to Autolayout, but it isn’t

Actually it is an attempt to design a format to store a Solitaire game layout in such a manner that regardless (within reason) of the screen size (for example “i” devices) the “virtual” coordinates can be recalculated (once) to render on the given device. The kicker is that for each device the size of the “cards” is constant.

What is “wrong” is the fact that because the card size is different… it complicates the calcuations to the point where the top of the top row of cards and the bottom of the bottom row of cards is usually outside the bounds of the display box.

The math to center the cards is not a problem. The problem is the mapping to device oriented coordinates

Also because the layouts involve so many objects (ie. cards) and there are potentially hundreds of these, I didn’t want to get into an “Autolayout” type of defintion.

All of these layouts need to be stored in some type of text file (XML, JSON whatever), and read in and translated at runtime. This is to allow additional layouts to be added in the future without making any code changes.

I have a format that I found eons ago, that allow the rules for almost any type of Solitaire game to be defined. But that format was used for a 640x480 VGA screen, which isn’t appropriate now.

@Dave S  One problem here is that you stated that “I need to alter the coordinates (X,Y) but NOT the size (W,H)” but I don’t think that is correct. Even if the horizontal and vertical resolutions are the same, you need to scale your rectangles from the virtual to the physical space, i.e. all of X, Y, W and H have to be a percentage of the virtual space.

Also, a common mistake would be to consider only the value of the rectangles’ X value to determine the full width. The full width is the difference between the maximum value of (rect.X + rect.W) and the minimum value of rect.X. Same for the full height of course.

HTH

Stepane… you are correct to a point. the size of the rectangle will be constant based on the resolution of the device, as each card must have a very specific aspect ratio, and all cards displayed on a given screen are the same size. Currently I am using

• w= screen_width/11
• h = 1.40 * w

I understand what you are saying… but that is part of the difficulty.

LIGHT BULB! … hmmmmm… that DID give me an idea however… stay tuned

Figured it out… and was a brain-fart on my part
I already have an app designed to GUI layouts for iOS… and it has routines to remap between screen sizes.
I adapted that same code to this problem and it works perfectly

``newX = (dest_dev_width / src_dev_width) * src_xCoor``

same for yPos and size of object

so far it has correctly mapped even the most complex layout properly