Thanks a lot Vladimir for noticing this, you are correct, this is a bug (typo).

Usually, its the first dimension that can have the opposite direction and that was the main motivation behind this correction (for the first dimension).

To be general, I also added a similar correction for the second dimension for completeness if such a case happens. But I missed this typo. Since I hadn't tested it on any actual dataset, I didn't notice it.