Пример #1
0
    def test_bytes_error(self):
        from QGIS_FMV.klvdata.common import bytes_to_float

        with self.assertRaises(ValueError):
            bytes_to_float(b'\x7F\xFF\xFF',
                           _domain=(-(2**15 - 1), 2**15 - 1),
                           _range=(-20, 20))
Пример #2
0
    def test_bytes_signed(self):
        from QGIS_FMV.klvdata.common import bytes_to_float

        self.assertAlmostEqual(
            bytes_to_float(
                b"\x80\x01", _domain=(-(2 ** 15 - 1), 2 ** 15 - 1), _range=(-20, 20)
            ),
            -20.0,
        )

        self.assertAlmostEqual(
            bytes_to_float(
                b"\x00\x00", _domain=(-(2 ** 15 - 1), 2 ** 15 - 1), _range=(-20, 20)
            ),
            0.0,
        )

        self.assertAlmostEqual(
            bytes_to_float(
                b"\xFD\x3D", _domain=(-(2 ** 15 - 1), 2 ** 15 - 1), _range=(-20, 20)
            ),
            -0.4315,
            3,
        )

        self.assertAlmostEqual(
            bytes_to_float(
                b"\x7F\xFF", _domain=(-(2 ** 15 - 1), 2 ** 15 - 1), _range=(-20, 20)
            ),
            20.0,
            7,
        )
Пример #3
0
    def test_bytes_unsigned(self):
        from QGIS_FMV.klvdata.common import bytes_to_float
        self.assertAlmostEqual(
            bytes_to_float(b'\x00\x00',
                           _domain=(0, 2**16 - 1),
                           _range=(0, 360)), 0.0)

        self.assertAlmostEqual(
            bytes_to_float(b'\x71\xC2',
                           _domain=(0, 2**16 - 1),
                           _range=(0, 360)), 159.974, 3)

        self.assertAlmostEqual(
            bytes_to_float(b'\xFF\xFF',
                           _domain=(0, 2**16 - 1),
                           _range=(0, 360)), 360.0)
Пример #4
0
    def __init__(self, value, _domain, _range):
        self._domain = _domain
        self._range = _range

        try:
            self.value = round(
                bytes_to_float(value, self._domain, self._range), 4)
        except TypeError:
            self.value = value
Пример #5
0
    def __init__(self, value, _domain, _range, _error):
        self._domain = _domain
        self._range = _range
        self._error = _error

        try:
            self.value = bytes_to_float(value, self._domain, self._range,
                                        self._error)
        except TypeError:
            self.value = value