def test_point2f(self): pt = Point2(54.3, 72.9) msg = serialize_point2f(pt) pt2 = deserialize_point2f(msg) self.assertAlmostEqual(pt2.x, pt.x) self.assertAlmostEqual(pt2.y, pt.y)
def deserialize(msg): handles = [ RectAlignment.__deserialize_handle(i) for i in msg.handles] dimHandles = [ RectAlignment.__deserialize_handle(i) for i in msg.dimHandles] dims = [i for i in msg.dims] assert len(handles) == 12 assert len(dimHandles) == 4 assert len(dims) == 2 originCorner = {"lowerLeft": 0, "lowerRight": 1, "upperLeft" : 2, "upperRight": 3}[str(msg.originCorner)] originCenter = deserialize_point2f(msg.originCenter) return RectAlignment(handles, dimHandles, dims, msg.lockedToDim, originCenter, originCorner, msg.flipX, msg.flipY)
def deserialize(msg: ser.ImageTransform.RectTransformMeta.Reader) -> 'RectAlignment': handles = [RectAlignment.__deserialize_handle(i) for i in msg.handles] dimHandles = [RectAlignment.__deserialize_handle(i) for i in msg.dimHandles] dims = [i for i in msg.dims] assert len(handles) == 12 assert len(dimHandles) == 4 assert len(dims) == 2 originCorner = { "lowerLeft": 0, "lowerRight": 1, "upperLeft": 2, "upperRight": 3}[str(msg.originCorner)] originCenter = deserialize_point2f(msg.originCenter) return RectAlignment(handles, dimHandles, dims, msg.lockedToDim, originCenter, originCorner, msg.flipX, msg.flipY)
def __deserialize_handle(msg): if msg.which() == "none": return None else: return deserialize_point2f(msg.point)
def deserialize(project, msg): obj = KeyPointAlignment() for i in msg.keypoints: obj.set_keypoint_position(project.scontext.get(i.kpSid), deserialize_point2f(i.position)) return obj
def __deserialize_handle(msg: ser.Handle.Reader) -> Optional[Vec2]: if msg.which() == "none": return None else: return deserialize_point2f(msg.point)
def deserialize(project: 'Project', msg: ser.ImageTransform.KeypointTransformMeta) -> 'KeyPointAlignment': obj = KeyPointAlignment() for i in msg.keypoints: obj.set_keypoint_position(project.scontext.get(i.kpSid), deserialize_point2f(i.position)) return obj