Translation

tomni.json_operations.translation_json(json_object: dict, x_translation: int, y_translation: int)[source]

Translate a JSON object (ellipse or polygon) by specified amounts in the x and y directions.

Parameters
  • json_object (dict) – A JSON object following the standard format.

  • x_translation (int) – The translation in the x-direction.

  • y_translation (int) – The translation in the y-direction.

Raises

ValueError – If the JSON object type is not supported.

Returns

A translated JSON object.

Return type

dict

Example:

json_object = {
    "type": "ellipse",
    "center": {"x": 100, "y": 200},
    "radiusX": 50,
    "radiusY": 100,
    "angleOfRotation": 0,
    "id": "12345-abcde"
}
x_translation = 100
y_translation = -20

result = {
    "type": "ellipse",
    "center": {"x": 200, "y": 180},
    "radiusX": 50,
    "radiusY": 100,
    "angleOfRotation": 0,
    "id": "12345-abcde"
}