valetudo-map-parser 0.1.9b70__py3-none-any.whl → 0.1.9b72__py3-none-any.whl

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.
@@ -223,9 +223,7 @@ class Drawable:
223
223
 
224
224
  @staticmethod
225
225
  def point_inside(x: int, y: int, points: list[Tuple[int, int]]) -> bool:
226
- """
227
- Check if a point (x, y) is inside a polygon defined by a list of points.
228
- """
226
+ """Check if a point (x, y) is inside a polygon defined by a list of points."""
229
227
  n = len(points)
230
228
  inside = False
231
229
  xinters = 0.0
@@ -243,79 +241,80 @@ class Drawable:
243
241
 
244
242
  @staticmethod
245
243
  def _line(
246
- layer: NumpyArray,
244
+ layer: np.ndarray,
247
245
  x1: int,
248
246
  y1: int,
249
247
  x2: int,
250
248
  y2: int,
251
249
  color: Color,
252
250
  width: int = 3,
253
- ) -> NumpyArray:
251
+ ) -> np.ndarray:
254
252
  """
255
- Draw a line on a NumPy array (layer) from point A to B using vectorized operations.
256
-
253
+ Draw a line on a NumPy array (layer) from point A to B using Bresenham's algorithm.
254
+
257
255
  Args:
258
- layer: The numpy array to draw on
256
+ layer: The numpy array to draw on (H, W, C)
259
257
  x1, y1: Start point coordinates
260
258
  x2, y2: End point coordinates
261
- color: Color to draw with
262
- width: Width of the line
259
+ color: Color to draw with (tuple or array)
260
+ width: Width of the line in pixels
263
261
  """
264
- # Ensure coordinates are integers
265
262
  x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
266
-
267
- # Get blended color for the line
263
+
268
264
  blended_color = get_blended_color(x1, y1, x2, y2, layer, color)
269
-
270
- # Calculate line length
271
- length = max(abs(x2 - x1), abs(y2 - y1))
272
- if length == 0: # Handle case of a single point
273
- # Draw a dot with the specified width
274
- for i in range(-width // 2, (width + 1) // 2):
275
- for j in range(-width // 2, (width + 1) // 2):
276
- if 0 <= x1 + i < layer.shape[1] and 0 <= y1 + j < layer.shape[0]:
277
- layer[y1 + j, x1 + i] = blended_color
278
- return layer
279
-
280
- # Create parametric points along the line
281
- t = np.linspace(0, 1, length * 2) # Double the points for smoother lines
282
- x_coords = np.round(x1 * (1 - t) + x2 * t).astype(int)
283
- y_coords = np.round(y1 * (1 - t) + y2 * t).astype(int)
284
-
285
- # Draw the line with the specified width
286
- if width == 1:
287
- # Fast path for width=1
288
- for x, y in zip(x_coords, y_coords):
289
- if 0 <= x < layer.shape[1] and 0 <= y < layer.shape[0]:
290
- layer[y, x] = blended_color
291
- else:
292
- # For thicker lines, draw a rectangle at each point
293
- half_width = width // 2
294
- for x, y in zip(x_coords, y_coords):
295
- for i in range(-half_width, half_width + 1):
296
- for j in range(-half_width, half_width + 1):
297
- if (
298
- i * i + j * j <= half_width * half_width # Make it round
299
- and 0 <= x + i < layer.shape[1]
300
- and 0 <= y + j < layer.shape[0]
301
- ):
302
- layer[y + j, x + i] = blended_color
303
-
304
- return layer
305
-
306
- @staticmethod
307
- async def draw_virtual_walls(
308
- layer: NumpyArray, virtual_walls, color: Color
309
- ) -> NumpyArray:
310
- """
311
- Draw virtual walls on the input layer.
312
- """
313
- for wall in virtual_walls:
314
- for i in range(0, len(wall), 4):
315
- x1, y1, x2, y2 = wall[i : i + 4]
316
- # Draw the virtual wall as a line with a fixed width of 6 pixels
317
- layer = Drawable._line(layer, x1, y1, x2, y2, color, width=6)
265
+
266
+ dx = abs(x2 - x1)
267
+ dy = abs(y2 - y1)
268
+ sx = 1 if x1 < x2 else -1
269
+ sy = 1 if y1 < y2 else -1
270
+ err = dx - dy
271
+
272
+ half_w = width // 2
273
+ h, w = layer.shape[:2]
274
+
275
+ while True:
276
+ # Draw a filled circle for thickness
277
+ yy, xx = np.ogrid[-half_w:half_w + 1, -half_w:half_w + 1]
278
+ mask = xx**2 + yy**2 <= half_w**2
279
+ y_min = max(0, y1 - half_w)
280
+ y_max = min(h, y1 + half_w + 1)
281
+ x_min = max(0, x1 - half_w)
282
+ x_max = min(w, x1 + half_w + 1)
283
+
284
+ submask = mask[
285
+ (y_min - (y1 - half_w)):(y_max - (y1 - half_w)),
286
+ (x_min - (x1 - half_w)):(x_max - (x1 - half_w))
287
+ ]
288
+ layer[y_min:y_max, x_min:x_max][submask] = blended_color
289
+
290
+ if x1 == x2 and y1 == y2:
291
+ break
292
+
293
+ e2 = 2 * err
294
+ if e2 > -dy:
295
+ err -= dy
296
+ x1 += sx
297
+ if e2 < dx:
298
+ err += dx
299
+ y1 += sy
300
+
318
301
  return layer
302
+
303
+
304
+
305
+ @staticmethod
306
+ async def draw_virtual_walls(
307
+ layer: NumpyArray, virtual_walls, color: Color
308
+ ) -> NumpyArray:
309
+ """
310
+ Draw virtual walls on the input layer.
311
+ """
312
+ for wall in virtual_walls:
313
+ for i in range(0, len(wall), 4):
314
+ x1, y1, x2, y2 = wall[i : i + 4]
315
+ # Draw the virtual wall as a line with a fixed width of 6 pixels
316
+ layer = Drawable._line(layer, x1, y1, x2, y2, color, width=6)
317
+ return layer
319
318
 
320
319
  @staticmethod
321
320
  async def lines(arr: NumpyArray, coords, width: int, color: Color) -> NumpyArray:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: valetudo-map-parser
3
- Version: 0.1.9b70
3
+ Version: 0.1.9b72
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
@@ -4,7 +4,7 @@ valetudo_map_parser/config/async_utils.py,sha256=e1j9uTtg4dhPVWvB2_XgqaH4aeSjRAP
4
4
  valetudo_map_parser/config/auto_crop.py,sha256=Aes7vfv4z8ihYvGaH5Nryj6Y9mHDerZLIeyvePjf9aQ,19259
5
5
  valetudo_map_parser/config/color_utils.py,sha256=nXD6WeNmdFdoMxPDW-JFpjnxJSaZR1jX-ouNfrx6zvE,4502
6
6
  valetudo_map_parser/config/colors.py,sha256=DG-oPQoN5gsnwDbEsuFr8a0hRCxmbFHObWa4_5pr-70,29910
7
- valetudo_map_parser/config/drawable.py,sha256=2MeVHXqZuVuJk3eerMJYGwo25rVetHx3xB_vxecEFOQ,34168
7
+ valetudo_map_parser/config/drawable.py,sha256=9twbotqVEQ7A_9W-XWg2zx8414Kvwm_B9dFgu4nyJ9Q,33606
8
8
  valetudo_map_parser/config/drawable_elements.py,sha256=o-5oiXmfqPwNQLzKIhkEcZD_A47rIU9E0CqKgWipxgc,11516
9
9
  valetudo_map_parser/config/enhanced_drawable.py,sha256=QlGxlUMVgECUXPtFwIslyjubWxQuhIixsRymWV3lEvk,12586
10
10
  valetudo_map_parser/config/optimized_element_map.py,sha256=52BCnkvVv9bre52LeVIfT8nhnEIpc0TuWTv1xcNu0Rk,15744
@@ -20,8 +20,8 @@ valetudo_map_parser/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
20
20
  valetudo_map_parser/rand256_handler.py,sha256=daaSQ5ktMUYMnYxJkjS75UdBchpXVZ58HIomwHBFivs,27651
21
21
  valetudo_map_parser/reimg_draw.py,sha256=1q8LkNTPHEA9Tsapc_JnVw51kpPYNhaBU-KmHkefCQY,12507
22
22
  valetudo_map_parser/rooms_handler.py,sha256=ovqQtAjauAqwUNPR0aX27P2zhheQmqfaFhDE3_AwYWk,17821
23
- valetudo_map_parser-0.1.9b70.dist-info/LICENSE,sha256=Lh-qBbuRV0-jiCIBhfV7NgdwFxQFOXH3BKOzK865hRs,10480
24
- valetudo_map_parser-0.1.9b70.dist-info/METADATA,sha256=oadNkSUgJDO-yswCRC2dow27dI0ntUsKH10Z5OURuic,3353
25
- valetudo_map_parser-0.1.9b70.dist-info/NOTICE.txt,sha256=5lTOuWiU9aiEnJ2go8sc7lTJ7ntMBx0g0GFnNrswCY4,2533
26
- valetudo_map_parser-0.1.9b70.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
27
- valetudo_map_parser-0.1.9b70.dist-info/RECORD,,
23
+ valetudo_map_parser-0.1.9b72.dist-info/LICENSE,sha256=Lh-qBbuRV0-jiCIBhfV7NgdwFxQFOXH3BKOzK865hRs,10480
24
+ valetudo_map_parser-0.1.9b72.dist-info/METADATA,sha256=04tAbYfZ0ZiwdCoHppkEaSjtgfcwQvriXny3LeBsWpg,3353
25
+ valetudo_map_parser-0.1.9b72.dist-info/NOTICE.txt,sha256=5lTOuWiU9aiEnJ2go8sc7lTJ7ntMBx0g0GFnNrswCY4,2533
26
+ valetudo_map_parser-0.1.9b72.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
27
+ valetudo_map_parser-0.1.9b72.dist-info/RECORD,,