0
votes

I'm using Farseer Physics, which is a fork of Box2D rewritten in C#.

In my understanding, there is no strict limit on world size in the Farseer/Box2D engine. The only limitation, in my understanding, is that with increased world size the precision will decrease to a point where glitches are visible. Currently, Farseer uses float types for all values (e.g. vectors). By replacing all floats with a higher-precision type like double or decimal make the effective maximum world size increase? Is there any meaningful downside to swapping these out or is it a pretty straight-forward 1-to-1?

1

1 Answers

1
votes

In my understanding, there is no strict limit on world size in the Farseer/Box2D engine. The only limitation, in my understanding, is that with increased world size the precision will decrease to a point where glitches are visible.

Yep. For a point of reference on this, see What units does Box2D use?. Or Maximum World Size and Units.

By replacing all floats with a higher-precision type like double or decimal will that make the effective maximum world size increase?

I've added the italicized text for clarity.

Short answer from my experience: Sort of, yes.

A related online discussion can be found in Switching JBox2D (Box2D) from Float to Double precision.

Note that while the max and least values for double are larger in magnitude than the max and least for float, there will still be limitations like from the settings that are optimized in part for single precision floating point format of the float type however.

Is there any meaningful downside to swapping these out or is it a pretty straight-forward 1-to-1?

Here are some downsides that I can foresee:

  1. Some calculations will be slower because of the increased memory access of using double over float.
  2. Some calculations will be slower because of the increased precision requirements of double compared to float.
  3. An application's memory footprint & requirements will be twice as large for all the doubles used as it is for floats.
  4. The settings have in part been optimized for float so you may have more need to tweak them for using double.

Whether these are meaningful however, will be dependent on the individual situation and users. I made a Solar system demo that uses doubles so that everything it represents could be represented to scale including collisions. Admittedly I used a Box2D derivative physics engine for this but in principal I think things should be able to work in Box2D as well.

Hope this helps.