Feedback: Correct Fixed Point conversion & take mod of angle send value
This commit is contained in:
1 parent
a60b513e74
commit
0b127da0ca
3 files changed
+9
-8
No files matched your search
@@ -122,12 +122,13 @@ class Angle(Type):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def read(file_object):
|
def read(file_object):
|
||||||
# Linearly transform angle in steps of 1/256 into steps of 1/360
|
# Linearly transform angle in steps of 1/256 into steps of 1/360
|
||||||
return 360 * UnsignedByte.read(file_object) / 255
|
return 360 * UnsignedByte.read(file_object) / 256
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def send(value, socket):
|
def send(value, socket):
|
||||||
# Normalize angle between 0 and 255 and convert to int.
|
# Normalize angle between 0 and 255 and convert to int.
|
||||||
UnsignedByte.send(round(255 * (value / 360)), socket)
|
|
||||||
|
UnsignedByte.send(round(256 * ((value % 360) / 360)), socket)
|
||||||
|
|
||||||
|
|
||||||
class VarInt(Type):
|
class VarInt(Type):
|
||||||
|
|||||||
@@ -236,9 +236,9 @@ class TestReadWritePackets(unittest.TestCase):
|
|||||||
if context.protocol_version < 49:
|
if context.protocol_version < 49:
|
||||||
del packet2.velocity
|
del packet2.velocity
|
||||||
self._test_read_write_packet(packet, context,
|
self._test_read_write_packet(packet, context,
|
||||||
yaw=360/255, pitch=360/255)
|
yaw=360/256, pitch=360/256)
|
||||||
self._test_read_write_packet(packet2, context,
|
self._test_read_write_packet(packet2, context,
|
||||||
yaw=360/255, pitch=360/255)
|
yaw=360/256, pitch=360/256)
|
||||||
|
|
||||||
def test_sound_effect_packet(self):
|
def test_sound_effect_packet(self):
|
||||||
for protocol_version in TEST_VERSIONS:
|
for protocol_version in TEST_VERSIONS:
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ TEST_DATA = {
|
|||||||
UnsignedLong: [0, 400],
|
UnsignedLong: [0, 400],
|
||||||
Integer: [-1000, 1000],
|
Integer: [-1000, 1000],
|
||||||
FixedPointInteger: [float(-13098.3435), float(-0.83), float(1000)],
|
FixedPointInteger: [float(-13098.3435), float(-0.83), float(1000)],
|
||||||
Angle: [0, 360.0, 90, 47.12947238973, 214.588235],
|
Angle: [0, 360.0, 720, 47.12947238973, -108.7],
|
||||||
VarInt: [1, 250, 50000, 10000000],
|
VarInt: [1, 250, 50000, 10000000],
|
||||||
Long: [50000000],
|
Long: [50000000],
|
||||||
Float: [21.000301],
|
Float: [21.000301],
|
||||||
@@ -60,10 +60,10 @@ class SerializationTest(unittest.TestCase):
|
|||||||
self.assertAlmostEqual(
|
self.assertAlmostEqual(
|
||||||
test_data, deserialized, delta=1.0/32.0)
|
test_data, deserialized, delta=1.0/32.0)
|
||||||
elif data_type is Angle:
|
elif data_type is Angle:
|
||||||
self.assertAlmostEqual(test_data, deserialized,
|
self.assertAlmostEqual(test_data % 360, deserialized,
|
||||||
delta=360/255)
|
delta=360/256)
|
||||||
elif data_type is Float or data_type is Double:
|
elif data_type is Float or data_type is Double:
|
||||||
self.assertAlmostEquals(test_data, deserialized, 3)
|
self.assertAlmostEqual(test_data, deserialized, 3)
|
||||||
else:
|
else:
|
||||||
self.assertEqual(test_data, deserialized)
|
self.assertEqual(test_data, deserialized)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user