Ok, that kinda makes me a little happier. This was the same problem I was having when implementing the Python code in Java. I thought it was a problem with the language conversion, but it seems to be in the algorithm itself.
btw, here's a picture of what the shapes look like if it will help you step through your code:

