Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SCR/valetudo_map_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Valetudo map parser.
Version: 0.3.0b2"""
Version: 0.3.1"""

from pathlib import Path

Expand Down
64 changes: 64 additions & 0 deletions SCR/valetudo_map_parser/conga_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,67 @@ async def async_get_conga_from_json(
scaled_json = self._scale_conga_json(m_json, CONGA_SCALE)
self.json_data = await HyperMapData.async_from_valetudo_json(scaled_json)
return await super().async_get_image_from_json(m_json=scaled_json)

def get_vacuum_points(self, rotation_angle: int) -> list[dict[str, int]]:
"""Calculate the calibration points from crop_area.

The vacuum points must be returned in the order that matches map_points:
[top-left, top-right, bottom-right, bottom-left] of the DISPLAYED image.

crop_area is in vacuum coordinates and doesn't rotate, so we need to
map the correct crop_area corners to the displayed image corners based
on rotation.
"""
if not self.crop_area:
return [
{"x": 0, "y": 0},
{"x": 0, "y": 0},
{"x": 0, "y": 0},
{"x": 0, "y": 0},
]

vacuum_points = [
{
"x": self.crop_area[0] // CONGA_SCALE + self.offset_x,
"y": self.crop_area[1] // CONGA_SCALE + self.offset_y,
},
{
"x": self.crop_area[2] // CONGA_SCALE - self.offset_x,
"y": self.crop_area[1] // CONGA_SCALE + self.offset_y,
},
{
"x": self.crop_area[2] // CONGA_SCALE - self.offset_x,
"y": self.crop_area[3] // CONGA_SCALE - self.offset_y,
},
{
"x": self.crop_area[0] // CONGA_SCALE + self.offset_x,
"y": self.crop_area[3] // CONGA_SCALE - self.offset_y,
},
]

match rotation_angle:
case 90:
vacuum_points = [
vacuum_points[1],
vacuum_points[2],
vacuum_points[3],
vacuum_points[0],
]
case 180:
vacuum_points = [
vacuum_points[2],
vacuum_points[3],
vacuum_points[0],
vacuum_points[1],
]
case 270:
vacuum_points = [
vacuum_points[3],
vacuum_points[0],
vacuum_points[1],
vacuum_points[2],
]
case _:
pass

return vacuum_points
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "valetudo-map-parser"
version = "0.3.0"
version = "0.3.1"
description = "A Python library to parse Valetudo map data returning a PIL Image object."
authors = ["Sandro Cantarella <gsca075@gmail.com>"]
license = "Apache-2.0"
Expand Down