Skip to content

Does it change the order of items? #2

Answered by ThomasMiz
jj21asd asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @jjblock21 ! There is no guarantee the rectangles will be returned in the same order after packing, that's what the id exists for.

This is because the algorithm internally sorts the rectangles differently, and sorting back to their original position takes time and performance, and not all people need it.

My suggestion is to set the rectangle ids to their index in the array before sorting, and then use that to number to know where they were originally. If you don't want to have to change the rest of your code, you may set the ids before packing and sort back to their original order afterwards like so:

PackingRectangle[] rectangles = ...

for (int i = 0; i < rectangles.Length; i++)
    r…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jj21asd
Comment options

@ThomasMiz
Comment options

Answer selected by jj21asd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants