[Gist/Resource] Selection Objects (Shapes, Lines, etc.)

Discussion in 'Resources' started by Jnorr44, Nov 13, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Jnorr44

    Hello everyone,
    I opened a public Gist (GitHub) for all developers to use and improve upon. It contains a few useful selection utilities that I have created, and I hope others can improve on it and add to it (and sometimes condense it). I will post the link below so you can use it:

     
  2. Offline

    Ultimate_n00b

    Nice! If you're looking for something else to do, you could add hollow shapes.
     
  3. Offline

    mkremins

    I noticed a few things that could be improved about the implementation. I might get around to making pull requests to fix some of them over the next few days.

    As long as the only thing that matters with regards to a single location is whether or not that location falls within the selection, you can (and, for performance reasons, almost certainly should) use a HashSet rather than an ArrayList to store locations. HashSet's .contains() method is O(1) and doesn't take longer to run as more locations are selected, whereas ArrayList's .contains() is O(N) and takes longer to run on a larger selection. By switching, you would lose any predictable iteration order over selected locations, but a predictable iteration order doesn't seem to matter in this case.

    Speaking of iteration: if you make the selection classes implement Iterable<Location>, you'll be able to use them directly within foreach-style loops, rather than having to invoke .getLocations() and iterate over that instead. An example of what I mean:
    Code:
    for (Location loc: yourSelectionObject) {
        // do stuff with loc
    }
    
    Additionally, since you already have a backing collection of locations for each class (and because there's only one method on the Iterable interface), you can implement this really simply just by having YourSelectionClass.iterator() return theBackingCollection.iterator() and be done with it.

    Nice work on the whole – a lightweight library of consistent, well-designed selection classes could do a lot to make block manipulation easier without forcing people to fall back on WorldEdit.
     
    CaptainBern likes this.
  4. Offline

    Jnorr44

    These are all very good suggestions guys. Ultimate_n00b I think the hollow shapes would just be a boolean in a constructor, although I'm not sure how exactly that would work with all of the methods and stuff. mkremins You have some great ideas, and your big O notation - which I rarely ever see and would like to see more of for methods - really put the speed of it all in perspective for me. I will work on some of these soon enough, but if you have the time feel free to add what you can, it really would be appreciated not only by me but by all of the devs who can/will use it.
     
  5. Jnorr44 Oh nice!! I've been really into math thingies lately (yesterday I found out how to make a cube :D )
     
Thread Status:
Not open for further replies.

Share This Page