Any way to optimize MapPalette.getDistance()?

Discussion in 'Plugin Development' started by Cirno, May 9, 2015.

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

    Cirno

  2. What I would do to get the distance between something like that is this:
    Code:
    public double getDistance(Color c1, Color c2) {
      double red = c2.getRed() - c1.getRed();
      double green = c2.getGreen() - c1.getGreen();
      double blue = c2.getBlue() - c1.getBlue();
      return Math.sqrt(red * red + green * green + blue * blue);
    }
    I'm not sure if it's the best way but it seems pretty good for me (It's the same method the Location class uses for distance(otherLoc) :p
     
  3. Offline

    blablubbabc

    @megamichiel

    The linked method calculates a different kind of distance.

    @Cirno

    I don't see any heavy operations in that method. Maybe you could optimize it by calling it less often instead:
    If you are for example converting lots of images to those minecraft colors, you might check if you could, maybe even asynchronously, pre-calculate those, before you start displaying them. And if your usecase includes displaying the same images again later then maybe also store the result (those color bytes) of those images.
     
  4. Offline

    1Rogue

    Cache, don't Thread.
     
Thread Status:
Not open for further replies.

Share This Page