Fence Behaviour
Bounce Mode
For the sake of explanation, consider this scene:
@F 0 0 2 2
@DIR 0 // North
@BOUNCE 1
To start, the turtle is at (0.5, 0.5), i.e.: he is standing in the middle of the cell. Then, @STEP.
Scenario 1: The fence is at the edge of the cell
The turtle walks 1 cell in the direction of the north fence. Halfway, he hits the fence and turns around. After traveling the distance of 1 cell, the turtle is back where he started, facing the other direction.
Scenario 2: The fence is in the middle of the cell
The turtle starts to walk, but he immediately hits the fence and turns around. He walks 1 cell’s distance and arrives at (0.5, 1.5).
Wrap Mode
@F 0 0 2 2
@DIR 0
@WRAP 1
As before, we start at (0.5, 0.5). @STEP.
Scenario 1 (edge)
The turtle walks 1 cell in the direction of the fence. Halfway, he is teleported to (0.5, 3.0). Then he walks the remaining half a cell and ends up at (0.5, 2.5).
Scenario 2 (middle)
The turtle walks 1 cell in the direction of the fence, and is immediately teleported to (0.5, 2.5). He finishes his 1 cell walk, and he arrives at (0.5, 1.5). This violates the intent of wrap mode, where you would expect to land at (0.5, 2.5).
Bump Mode
@F 0 0 2 2
@DIR 0
@BUMP 1 // default, actually
From (0.5, 0.5), @STEP.
Scenario 1 (edge)
The turtle walks towards the fence, but halfway through his one-cell step, he hits the fence and stops. He is now at (0.5, 0). We might say that he’s kind of lost “alignment” with the middle of the cell. It will still behave as expected on subsequent steps, but it’s offset internally.
Scenario 2 (middle)
The turtle starts to walk toward the fence, but is immediately stopped by the fence. He remains at (0.5, 0.5), retaining his middle-of-the-cell alignment.
Conclusion
There is no fence alignment that satisfies the needs of all three modes. Fortunately, I can assign the fence position differently for each mode. My preferences:
-
@BOUNCE - middle
-
@WRAP - edge
-
@BUMP - middle
I hope that the preceding analysis answers any outstanding uncertainty regarding the fence behaviour.
Warning: stop reading if you value the comfort of certainty.
! Integers have an even number of values, as does the fractional content which is implemented with integer math. You are never really in the center of the cell, as there are an even number of positions to be in, and no middle.
! There are conceptual ways around this fact, such as designing a numbering system with an odd number of values, but they’re more effort than they’re worth.
! The fractional values are only used internally, so the only thing that matters is the behaviour, i.e.: the resultant non-fractional integer, so I let this little imperfection slide.
! The sin() implementation is probably less accurate than this tiny offset, so what happens at non-cardinal angles is more governed by that fact than by the minute offset that the number system introduces.