valetudo-map-parser 0.1.9b49__tar.gz → 0.1.9b50__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/PKG-INFO +1 -1
  2. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/color_utils.py +3 -5
  3. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/colors.py +0 -1
  4. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/drawable.py +55 -37
  5. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/pyproject.toml +1 -1
  6. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/LICENSE +0 -0
  7. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/NOTICE.txt +0 -0
  8. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/README.md +0 -0
  9. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/__init__.py +0 -0
  10. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/__init__.py +0 -0
  11. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/auto_crop.py +0 -0
  12. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/drawable_elements.py +0 -0
  13. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/enhanced_drawable.py +0 -0
  14. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/optimized_element_map.py +0 -0
  15. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/rand25_parser.py +0 -0
  16. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/room_outline.py +0 -0
  17. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/shared.py +0 -0
  18. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/types.py +0 -0
  19. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/config/utils.py +0 -0
  20. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/hypfer_draw.py +0 -0
  21. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/hypfer_handler.py +0 -0
  22. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/map_data.py +0 -0
  23. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/py.typed +0 -0
  24. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/rand25_handler.py +0 -0
  25. {valetudo_map_parser-0.1.9b49 → valetudo_map_parser-0.1.9b50}/SCR/valetudo_map_parser/reimg_draw.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: valetudo-map-parser
3
- Version: 0.1.9b49
3
+ Version: 0.1.9b50
4
4
  Summary: A Python library to parse Valetudo map data returning a PIL Image object.
5
5
  License: Apache-2.0
6
6
  Author: Sandro Cantarella
@@ -2,8 +2,8 @@
2
2
 
3
3
  from typing import Tuple, Optional
4
4
 
5
- from SCR.valetudo_map_parser.config.colors import ColorsManagement
6
- from SCR.valetudo_map_parser.config.types import NumpyArray, Color
5
+ from .colors import ColorsManagement
6
+ from .types import NumpyArray, Color
7
7
 
8
8
 
9
9
  def get_blended_color(
@@ -35,9 +35,7 @@ def get_blended_color(
35
35
  start_blended_color = color
36
36
 
37
37
  if 0 <= y1 < arr.shape[0] and 0 <= x1 < arr.shape[1]:
38
- end_blended_color = ColorsManagement.sample_and_blend_color(
39
- arr, x1, y1, color
40
- )
38
+ end_blended_color = ColorsManagement.sample_and_blend_color(arr, x1, y1, color)
41
39
  else:
42
40
  end_blended_color = color
43
41
 
@@ -139,7 +139,6 @@ color_array = [
139
139
  ]
140
140
 
141
141
 
142
-
143
142
  class SupportedColor(StrEnum):
144
143
  """Color of a supported map element."""
145
144
 
@@ -75,7 +75,7 @@ class Drawable:
75
75
  # Get the region to update
76
76
  region_slice = (
77
77
  slice(row, row + pixel_size),
78
- slice(col + i * pixel_size, col + (i + 1) * pixel_size)
78
+ slice(col + i * pixel_size, col + (i + 1) * pixel_size),
79
79
  )
80
80
 
81
81
  if need_blending:
@@ -84,8 +84,10 @@ class Drawable:
84
84
  center_x = col + i * pixel_size + pixel_size // 2
85
85
 
86
86
  # Only blend if coordinates are valid
87
- if (0 <= center_y < image_array.shape[0] and
88
- 0 <= center_x < image_array.shape[1]):
87
+ if (
88
+ 0 <= center_y < image_array.shape[0]
89
+ and 0 <= center_x < image_array.shape[1]
90
+ ):
89
91
  # Get blended color
90
92
  blended_color = ColorsManagement.sample_and_blend_color(
91
93
  image_array, center_x, center_y, full_color
@@ -296,9 +298,11 @@ class Drawable:
296
298
  for x, y in zip(x_coords, y_coords):
297
299
  for i in range(-half_width, half_width + 1):
298
300
  for j in range(-half_width, half_width + 1):
299
- if (i*i + j*j <= half_width*half_width and # Make it round
300
- 0 <= x + i < layer.shape[1] and
301
- 0 <= y + j < layer.shape[0]):
301
+ if (
302
+ i * i + j * j <= half_width * half_width # Make it round
303
+ and 0 <= x + i < layer.shape[1]
304
+ and 0 <= y + j < layer.shape[0]
305
+ ):
302
306
  layer[y + j, x + i] = blended_color
303
307
 
304
308
  return layer
@@ -371,7 +375,7 @@ class Drawable:
371
375
  dist_sq = (y_indices - y) ** 2 + (x_indices - x) ** 2
372
376
 
373
377
  # Create masks for the circle and outline
374
- circle_mask = dist_sq <= radius ** 2
378
+ circle_mask = dist_sq <= radius**2
375
379
 
376
380
  # Apply the fill color
377
381
  image[min_y:max_y, min_x:max_x][circle_mask] = color
@@ -468,7 +472,7 @@ class Drawable:
468
472
  adjusted_points = [(p[0] - min_x, p[1] - min_y) for p in points]
469
473
 
470
474
  # Create a grid of coordinates and use it to test all points at once
471
- y_indices, x_indices = np.mgrid[0:mask.shape[0], 0:mask.shape[1]]
475
+ y_indices, x_indices = np.mgrid[0 : mask.shape[0], 0 : mask.shape[1]]
472
476
 
473
477
  # Test each point in the grid
474
478
  for i in range(mask.shape[0]):
@@ -476,7 +480,7 @@ class Drawable:
476
480
  mask[i, j] = Drawable.point_inside(j, i, adjusted_points)
477
481
 
478
482
  # Apply the fill color to the masked region
479
- arr[min_y:max_y+1, min_x:max_x+1][mask] = fill_color
483
+ arr[min_y : max_y + 1, min_x : max_x + 1][mask] = fill_color
480
484
 
481
485
  return arr
482
486
 
@@ -530,7 +534,7 @@ class Drawable:
530
534
  y_indices, x_indices = np.ogrid[y_min:y_max, x_min:x_max]
531
535
 
532
536
  # Create a circular mask
533
- mask = (y_indices - y)**2 + (x_indices - x)**2 <= dot_radius**2
537
+ mask = (y_indices - y) ** 2 + (x_indices - x) ** 2 <= dot_radius**2
534
538
 
535
539
  # Apply the color to the masked region
536
540
  layers[y_min:y_max, x_min:x_max][mask] = blended_color
@@ -607,8 +611,12 @@ class Drawable:
607
611
  y2 = int(tmp_y + r_cover * math.cos(a2))
608
612
 
609
613
  # Draw the direction line
610
- if (0 <= x1 < tmp_width and 0 <= y1 < tmp_height and
611
- 0 <= x2 < tmp_width and 0 <= y2 < tmp_height):
614
+ if (
615
+ 0 <= x1 < tmp_width
616
+ and 0 <= y1 < tmp_height
617
+ and 0 <= x2 < tmp_width
618
+ and 0 <= y2 < tmp_height
619
+ ):
612
620
  tmp_layer = Drawable._line(tmp_layer, x1, y1, x2, y2, outline, width=1)
613
621
 
614
622
  # Draw the lidar indicator
@@ -694,14 +702,14 @@ class Drawable:
694
702
  # Get image dimensions
695
703
  height, width = image.shape[:2]
696
704
 
697
- if element_type == 'circle':
705
+ if element_type == "circle":
698
706
  # Extract circle centers and radii
699
707
  centers = []
700
708
  radii = []
701
709
  for elem in elements:
702
- if isinstance(elem, dict) and 'center' in elem and 'radius' in elem:
703
- centers.append(elem['center'])
704
- radii.append(elem['radius'])
710
+ if isinstance(elem, dict) and "center" in elem and "radius" in elem:
711
+ centers.append(elem["center"])
712
+ radii.append(elem["radius"])
705
713
  elif isinstance(elem, (list, tuple)) and len(elem) >= 3:
706
714
  # Format: (x, y, radius)
707
715
  centers.append((elem[0], elem[1]))
@@ -709,7 +717,9 @@ class Drawable:
709
717
 
710
718
  # Process circles with the same radius together
711
719
  for radius in set(radii):
712
- same_radius_centers = [centers[i] for i in range(len(centers)) if radii[i] == radius]
720
+ same_radius_centers = [
721
+ centers[i] for i in range(len(centers)) if radii[i] == radius
722
+ ]
713
723
  if same_radius_centers:
714
724
  # Create a combined mask for all circles with this radius
715
725
  mask = np.zeros((height, width), dtype=bool)
@@ -725,20 +735,22 @@ class Drawable:
725
735
  y_indices, x_indices = np.ogrid[min_y:max_y, min_x:max_x]
726
736
 
727
737
  # Add this circle to the mask
728
- circle_mask = (y_indices - cy)**2 + (x_indices - cx)**2 <= radius**2
738
+ circle_mask = (y_indices - cy) ** 2 + (
739
+ x_indices - cx
740
+ ) ** 2 <= radius**2
729
741
  mask[min_y:max_y, min_x:max_x] |= circle_mask
730
742
 
731
743
  # Apply color to all circles at once
732
744
  image[mask] = color
733
745
 
734
- elif element_type == 'line':
746
+ elif element_type == "line":
735
747
  # Extract line endpoints
736
748
  lines = []
737
749
  widths = []
738
750
  for elem in elements:
739
- if isinstance(elem, dict) and 'start' in elem and 'end' in elem:
740
- lines.append((elem['start'], elem['end']))
741
- widths.append(elem.get('width', 1))
751
+ if isinstance(elem, dict) and "start" in elem and "end" in elem:
752
+ lines.append((elem["start"], elem["end"]))
753
+ widths.append(elem.get("width", 1))
742
754
  elif isinstance(elem, (list, tuple)) and len(elem) >= 4:
743
755
  # Format: (x1, y1, x2, y2, [width])
744
756
  lines.append(((elem[0], elem[1]), (elem[2], elem[3])))
@@ -746,19 +758,25 @@ class Drawable:
746
758
 
747
759
  # Process lines with the same width together
748
760
  for width in set(widths):
749
- same_width_lines = [lines[i] for i in range(len(lines)) if widths[i] == width]
761
+ same_width_lines = [
762
+ lines[i] for i in range(len(lines)) if widths[i] == width
763
+ ]
750
764
  if same_width_lines:
751
765
  # Create a combined mask for all lines with this width
752
766
  mask = np.zeros((height, width), dtype=bool)
753
767
 
754
768
  # Draw all lines into the mask
755
- for (start, end) in same_width_lines:
769
+ for start, end in same_width_lines:
756
770
  x1, y1 = start
757
771
  x2, y2 = end
758
772
 
759
773
  # Skip invalid lines
760
- if not (0 <= x1 < width and 0 <= y1 < height and
761
- 0 <= x2 < width and 0 <= y2 < height):
774
+ if not (
775
+ 0 <= x1 < width
776
+ and 0 <= y1 < height
777
+ and 0 <= x2 < width
778
+ and 0 <= y2 < height
779
+ ):
762
780
  continue
763
781
 
764
782
  # Use Bresenham's algorithm to get line points
@@ -783,8 +801,12 @@ class Drawable:
783
801
  max_x = min(width, x + half_width + 1)
784
802
 
785
803
  # Create a circular brush
786
- y_indices, x_indices = np.ogrid[min_y:max_y, min_x:max_x]
787
- brush = (y_indices - y)**2 + (x_indices - x)**2 <= half_width**2
804
+ y_indices, x_indices = np.ogrid[
805
+ min_y:max_y, min_x:max_x
806
+ ]
807
+ brush = (y_indices - y) ** 2 + (
808
+ x_indices - x
809
+ ) ** 2 <= half_width**2
788
810
  mask[min_y:max_y, min_x:max_x] |= brush
789
811
 
790
812
  # Apply color to all lines at once
@@ -826,20 +848,16 @@ class Drawable:
826
848
  )
827
849
 
828
850
  # Add to centers list with radius
829
- centers.append({
830
- 'center': (x, y),
831
- 'radius': 6,
832
- 'color': obstacle_color
833
- })
851
+ centers.append({"center": (x, y), "radius": 6, "color": obstacle_color})
834
852
  except (KeyError, TypeError):
835
853
  continue
836
854
 
837
855
  # Draw each obstacle with its blended color
838
856
  if centers:
839
857
  for obstacle in centers:
840
- cx, cy = obstacle['center']
841
- radius = obstacle['radius']
842
- obs_color = obstacle['color']
858
+ cx, cy = obstacle["center"]
859
+ radius = obstacle["radius"]
860
+ obs_color = obstacle["color"]
843
861
 
844
862
  # Create a small mask for the obstacle
845
863
  min_y = max(0, cy - radius)
@@ -851,7 +869,7 @@ class Drawable:
851
869
  y_indices, x_indices = np.ogrid[min_y:max_y, min_x:max_x]
852
870
 
853
871
  # Create a circular mask
854
- mask = (y_indices - cy)**2 + (x_indices - cx)**2 <= radius**2
872
+ mask = (y_indices - cy) ** 2 + (x_indices - cx) ** 2 <= radius**2
855
873
 
856
874
  # Apply the color to the masked region
857
875
  image[min_y:max_y, min_x:max_x][mask] = obs_color
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "valetudo-map-parser"
3
- version = "0.1.9.b49"
3
+ version = "0.1.9.b50"
4
4
  description = "A Python library to parse Valetudo map data returning a PIL Image object."
5
5
  authors = ["Sandro Cantarella <gsca075@gmail.com>"]
6
6
  license = "Apache-2.0"