@@ -68,6 +68,7 @@ def __init__(self, file):
6868 self .lo_masks_inv = [0x00 , 0x80 , 0xC0 , 0xE0 , 0xF0 , 0xF8 , 0xFC , 0xFE , 0xFF ]
6969 self .hi_masks = [0xFF ^ mask for mask in self .lo_masks ]
7070 self .hi_masks_inv = [0xFF ^ mask for mask in self .lo_masks_inv ]
71+ self .coord_convert = [(2 ** (12 - i ),1.0 / 2 ** i ) for i in range (1 ,13 )]
7172
7273 self .read_basic = self .io .read
7374 '''
@@ -215,9 +216,22 @@ def read_object_id(self):
215216 """ Object ID is big-endian int32 """
216217 return self .read_int (endian = BIG_ENDIAN )
217218
218- def read_coordinate (self ):
219- coord = self .read (bits = 20 )
220- return [coord [0 ], coord [1 ] << 4 | coord [2 ],]
219+ def read_coordinate (self ):
220+ # Combine coordinate whole and fraction
221+ def _coord_to_float (coord ):
222+ fraction = 0
223+ for mask ,quotient in self .coord_convert :
224+ if (coord [1 ] & mask ):
225+ fraction = fraction + quotient
226+ return coord [0 ] + fraction
227+
228+ # Read an x or y coordinate dimension
229+ def _coord_dimension ():
230+ coord = self .read (bits = 20 )
231+ return _coord_to_float ([coord [0 ], coord [1 ] << 4 | coord [2 ],])
232+
233+ # TODO?: Handle optional z dimension
234+ return (_coord_dimension (), _coord_dimension ())
221235
222236 def read_bitmask (self ):
223237 """ Reads a bitmask given the current bitoffset """
0 commit comments