That class I took 15 years ago sure paid off, or not ;o I'm lost.. some fuckery is present. What's wrong boss?
So this was a very good response to the problem. There's three big things it does that are critical:
1. It uses a source-based search for finding the rotated point. Rather than iterating over the source and rotating each point to find the destination it's better to iterate over the destination and find its source. This removes the hole problem completely without adding any more 'holy filling' processing.
2. You avoid the double for loops over height/width by just iterating from 0 - totalSize. Another thing that I've found really speeds up iterating over data is to forgo all index operations and to avoid the for loop entirely. Ex:
actually runs faster with:
Like many improvements in efficiency this, of course, reduces readability, maintainability and can be easier to add bugs in code. But when performance is needed you can really speed things up. The codebase I'm working on would simply not work fast enough with the processing payload we use if I didn't do this in a lot of areas.
3. You were careful with casting from double to int and made sure to round the numbers by adding 0.5 before the cast. This is very important with this operation because if you don't cast properly the displayed map will be jittery and jump around a lot.
As for the fuckery, I can only assume you mean the values at the corners. This is completely unavoidable for this problem because you're effectively changing the size of the array without being able to add new information. There's nothing you can do about this and you either need to have the output be a subset of the initial array, change the shape of the data to a circle or hide it in some other way (In my case I'm not displayed rows of data, I'm displaying obstacles that can pop in and out as you drive, so the fact that you are changing the shape is somewhat mitigated unless you're very clever or know the system more than a user should).