As a Roblox developer, it is currently too hard to serialize Region3s accurately. This is because there is no way to get the values used to construct the Region3, so its components need to be calculated using division, which is prone to floating point errors.
If properties were added to Region3 to expose the Vector3s that were used to construct it, it would be far easier to serialize accurately because it wouldn’t be prone to floating point problems. Region3int16, bizarrely enough, has properties to get its constructor arguments, so it would be nice to have them as part of Region3 as well.
The only properties provided at the moment for Region3 are Size
and CFrame
. As a result, the lower corner of a Region3 have to be calculated via Region3.CFrame.Position-Region3.Size/2
and the upper corner via Region3.CFrame.Position+Region3.Size/2
.
This method is not good enough because of the division involve. As an example, take Region3.new(Vector3.new(0.25, -10, 3.14), Vector3.new(0, 1337, 9000))
. All of the values used to construct this Region3 are exactly representable by floats except 3.14
, which is actually (when cast to a single precision float) 3.14000010490417480469
.
When the math is done to calculate the lower and upper corners of this Region3 however, the results are Vector3.new(0.25, -10, 3.13964844)
and Vector3.new(0, 1337, 9000)
. The difference between 3.13964844
and 3.14
is significant enough to matter (0.0004
, roughly, compared to the 0.0000001
it should be normally). This is obviously a result of the division involved and so long as it’s involved, it’s unavoidable.
Properties to get the lower and upper corners of a Region3 would be incredibly helpful since that would avoid the floating point errors that come from division.