Skip to content

Commit b17d4d9

Browse files
MLanghofkrisives
authored andcommitted
Changed compass range. (#128)
The compass now always returns a positive float between 0 and 2 pi.
1 parent dd596d4 commit b17d4d9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/asmcup/runtime/Robot.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ protected void handleIO(World world) {
346346
vm.push8(world.recv(this, frequency));
347347
break;
348348
case IO_COMPASS:
349-
vm.pushFloat(facing % (float)Math.PI);
349+
vm.pushFloat(floatModPositive(facing, (float)(Math.PI * 2)));
350350
break;
351351
case IO_BEAM_DIRECTION:
352352
beamDirection = popFloatSafe(-1.0f, 1.0f);
@@ -430,6 +430,10 @@ protected static float clampSafe(float f, float min, float max) {
430430
return f;
431431
}
432432

433+
protected static float floatModPositive(float dividend, float divisor) {
434+
return ((dividend % divisor) + divisor) % divisor;
435+
}
436+
433437
public static final int IO_SENSOR = 0;
434438
public static final int IO_MOTOR = 1;
435439
public static final int IO_STEER = 2;

0 commit comments

Comments
 (0)