You're correct, it should be passing the index it was actually added at.
Possibly there's no exception getting thrown. It depends whether the divide by zero is happening in an integer or floating point calculation. In floating point, dividing by zero gives a well defined result (infinity, -infinity, or nan depending on the numerator) rather than throwing an exception.
That's a fairly obscure piece of code that not many other people are likely to be depending on. So I'd think it's fine to just change it.
Sounds like a good idea. unit() and getNormalized() both sound like reasonable names. I wouldn't call it direction() because "direction vector" means something different. (When working in homogenous coordinates, a direction vector is one whose fourth component is zero.)
My current version creates a template image of the map that is larger or equal to the maximum size of preview images. This happens the first time a preview is needed. Then the scaled preview is always created form that. There's no need to create the scaled version of the image. Just use the version of drawImage() that scales it down.
There's a much faster way of doing it: create the preview image from the smallest mip map whose size is greater than or equal to the requested preview size. You're always generating it from maps, which can be very large, but you don't need to do that. If you have a 1000x1000 image and you want to create a 100x100 preview, you can generate it from the 128x128 mip map. There are other optimizations that could be used as well. You could require that preview image sizes always be a power of two (or...
Can you post your code? I'd like to see how you're doing it. If done properly, scaling images to any size should be super quick.
Creatig preview images can take quite a few fractions of quite a few econds if the images are large and there are very many of them. Did you implement the optimization I suggested where it skips images that are currently scrolled out of view? If there are a lot of images in the scene, you won't be able to see most of them. As you resize the window, it only needs to regenerate the previews for ones that are currently visible.