Use decimal instead of long for WPos offset
To remove overflow risk.
This commit is contained in:
@@ -64,8 +64,8 @@ namespace OpenRA
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
// Add an additional quadratic variation to height
|
// Add an additional quadratic variation to height
|
||||||
// Attempts to avoid integer overflow by keeping the intermediate variables reasonably sized
|
// Uses decimal to avoid integer overflow
|
||||||
var offset = (int)(((((((long)(b - a).Length * mul) / div) * (div - mul)) / div) * pitch.Tan()) / 1024);
|
var offset = (int)((decimal)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div));
|
||||||
return new WPos(ret.X, ret.Y, ret.Z + offset);
|
return new WPos(ret.X, ret.Y, ret.Z + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user