Code Monkey home page Code Monkey logo

Comments (1)

caffeinepills avatar caffeinepills commented on July 20, 2024

It's been a long time, I forgot I made this post, but I did end up fixing this, atleast for top left ONLY (selectAllOrder is completely ignored). This will force the order to top left down no matter what. Obviously, this isn't optimal, but it gets the job done.

Just change OrderBoxes to the following and compile.:

public static List<Rectangle> OrderBoxes(List<Rectangle> boxes, Enums.SelectAllOrder selectAllOrder, Size spriteSheetSize)
        {
            List<List<Rectangle>> listsOfBoxes = new List<List<Rectangle>>();
            bool found = false;

            List<Rectangle> returnedOrder = boxes.OrderBy(w => w.Y + w.Height).ToList();
            foreach (Rectangle box in returnedOrder)
            {
                foreach (Rectangle compareBox in returnedOrder)
                {
                    // Find a rect on the same Y axis.
                    if (box.Top < compareBox.Bottom && box.Bottom > compareBox.Top)
                    {
                        found = false;
                        // Look for a list containing the matched rect.
                        foreach (List<Rectangle> groupedList in listsOfBoxes)
                        {
                            // Add our rect to a list we found.
                            if (groupedList.Contains(compareBox))
                            {
                                groupedList.Add(box);
                                found = true;
                                break;
                            }
                        }

                        // No list was found, create a new list and put the rect in it.
                        if (found == false)
                        {
                            List<Rectangle> newList = new List<Rectangle>();
                            listsOfBoxes.Add(newList);

                            newList.Add(box);
                        }
                        // We found a rect, stop searching for others.
                        break;
                    }
                }
            }

            // Begin to sort all of the lists by the X axis and dump into a single list.
            List<Rectangle> properOrder = new List<Rectangle>();

            foreach (List<Rectangle> groupedList in listsOfBoxes)
            {
                List<Rectangle> orderedList = groupedList.OrderBy(w => w.X).ToList();
                properOrder.AddRange(orderedList);
            }

            return properOrder;
        }

from alferd-spritesheet-unpacker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.