valetudo-map-parser 0.1.9b71__tar.gz → 0.1.9b72__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 (27) hide show
  1. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/PKG-INFO +1 -1
  2. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/drawable.py +47 -64
  3. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/pyproject.toml +1 -1
  4. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/LICENSE +0 -0
  5. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/NOTICE.txt +0 -0
  6. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/README.md +0 -0
  7. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/__init__.py +0 -0
  8. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/__init__.py +0 -0
  9. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/async_utils.py +0 -0
  10. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/auto_crop.py +0 -0
  11. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/color_utils.py +0 -0
  12. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/colors.py +0 -0
  13. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/drawable_elements.py +0 -0
  14. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/enhanced_drawable.py +0 -0
  15. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/optimized_element_map.py +0 -0
  16. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/rand256_parser.py +0 -0
  17. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/shared.py +0 -0
  18. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/types.py +0 -0
  19. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/config/utils.py +0 -0
  20. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/hypfer_draw.py +0 -0
  21. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/hypfer_handler.py +0 -0
  22. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/hypfer_rooms_handler.py +0 -0
  23. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/map_data.py +0 -0
  24. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/py.typed +0 -0
  25. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/rand256_handler.py +0 -0
  26. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/reimg_draw.py +0 -0
  27. {valetudo_map_parser-0.1.9b71 → valetudo_map_parser-0.1.9b72}/SCR/valetudo_map_parser/rooms_handler.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: valetudo-map-parser
3
- Version: 0.1.9b71
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
@@ -240,30 +240,6 @@ class Drawable:
240
240
  return inside
241
241
 
242
242
  @staticmethod
243
- def _bresenham_line_coords(x1: int, y1: int, x2: int, y2: int) -> Tuple[np.ndarray, np.ndarray]:
244
- """Return integer coordinates for a line using Bresenham's algorithm."""
245
- dx = abs(x2 - x1)
246
- dy = abs(y2 - y1)
247
- sx = 1 if x1 < x2 else -1
248
- sy = 1 if y1 < y2 else -1
249
- err = dx - dy
250
-
251
- xs, ys = [], []
252
- while True:
253
- xs.append(x1)
254
- ys.append(y1)
255
- if x1 == x2 and y1 == y2:
256
- break
257
- e2 = 2 * err
258
- if e2 > -dy:
259
- err -= dy
260
- x1 += sx
261
- if e2 < dx:
262
- err += dx
263
- y1 += sy
264
- return np.array(xs, dtype=int), np.array(ys, dtype=int)
265
-
266
-
267
243
  def _line(
268
244
  layer: np.ndarray,
269
245
  x1: int,
@@ -273,7 +249,8 @@ class Drawable:
273
249
  color: Color,
274
250
  width: int = 3,
275
251
  ) -> np.ndarray:
276
- """Draw a line on a NumPy array (layer) from point A to B using a fully vectorized approach.
252
+ """
253
+ Draw a line on a NumPy array (layer) from point A to B using Bresenham's algorithm.
277
254
 
278
255
  Args:
279
256
  layer: The numpy array to draw on (H, W, C)
@@ -283,55 +260,61 @@ class Drawable:
283
260
  width: Width of the line in pixels
284
261
  """
285
262
  x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
286
- h, w = layer.shape[:2]
287
263
 
288
264
  blended_color = get_blended_color(x1, y1, x2, y2, layer, color)
289
265
 
290
- # Get core line coordinates
291
- xs, ys = _bresenham_line_coords(x1, y1, x2, y2)
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
292
271
 
293
- if width == 1:
294
- # Clip to bounds in one go
295
- mask = (xs >= 0) & (xs < w) & (ys >= 0) & (ys < h)
296
- layer[ys[mask], xs[mask]] = blended_color
297
- return layer
272
+ half_w = width // 2
273
+ h, w = layer.shape[:2]
298
274
 
299
- # Precompute circular mask for thickness
300
- r = width // 2
301
- yy, xx = np.ogrid[-r:r + 1, -r:r + 1]
302
- circle_mask = (xx**2 + yy**2) <= r**2
303
- dy_idx, dx_idx = np.nonzero(circle_mask) # offsets inside the circle
304
- dy_idx -= r
305
- dx_idx -= r
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)
306
283
 
307
- # Broadcast offsets to all line points
308
- all_x = (xs[:, None] + dx_idx[None, :]).ravel()
309
- all_y = (ys[:, None] + dy_idx[None, :]).ravel()
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
310
289
 
311
- # Clip to image bounds
312
- valid = (all_x >= 0) & (all_x < w) & (all_y >= 0) & (all_y < h)
313
- all_x = all_x[valid]
314
- all_y = all_y[valid]
290
+ if x1 == x2 and y1 == y2:
291
+ break
315
292
 
316
- # Draw all pixels in one go
317
- layer[all_y, all_x] = blended_color
293
+ e2 = 2 * err
294
+ if e2 > -dy:
295
+ err -= dy
296
+ x1 += sx
297
+ if e2 < dx:
298
+ err += dx
299
+ y1 += sy
318
300
 
319
301
  return layer
320
-
321
-
322
- @staticmethod
323
- async def draw_virtual_walls(
324
- layer: NumpyArray, virtual_walls, color: Color
325
- ) -> NumpyArray:
326
- """
327
- Draw virtual walls on the input layer.
328
- """
329
- for wall in virtual_walls:
330
- for i in range(0, len(wall), 4):
331
- x1, y1, x2, y2 = wall[i : i + 4]
332
- # Draw the virtual wall as a line with a fixed width of 6 pixels
333
- layer = Drawable._line(layer, x1, y1, x2, y2, color, width=6)
334
- 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
335
318
 
336
319
  @staticmethod
337
320
  async def lines(arr: NumpyArray, coords, width: int, color: Color) -> NumpyArray:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "valetudo-map-parser"
3
- version = "0.1.9b71"
3
+ version = "0.1.9b72"
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"