Track Location Node has precision error
chj990707 opened this issue ยท 1 comments
Because of the constructor logic, Track Location Node suffers precision error at coordinates larger than the float significand.
When x coord and z coord are converted to integers, if the absolute value of those are bigger than 2^24(around 1.6e+7), the resulting node location will be erroneous and the tracks won't connect properly.
It is because Math.round returns a long type value, which is an 64-bit integer. It is consecutively passed into Mth.floor, and because it is supposed to floor either float or double, long is implicitly cast to float. Because of this the value will lose the precision of original double value, and instead of being aligned at 0.5 blocks grid, the nodes will be aligned at 1 blocks grid.
While in most case the track won't be placed that far away, I faced this while testing the track with the Valkyrien Skies mod. Because VS places the blocks outside the float precision range, tracks on the ship won't connect properly.
I suggest changing the Mth.floor() operation to simple (int) casting. Technically this can cause problem if the result of the Math.round is outside of int range, but it will only happen when the absolute value is bigger than 2^30(INT_MAX_VALUE / 2). Alternative to this would be Using three long value instead of Vec3i but that might be too unefficient.