Skip to content

Commit

Permalink
Clean up get_origin_pointcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
leavauchier committed Aug 22, 2024
1 parent c8e8a36 commit 228c569
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions pdaltools/pcd_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ def get_pointcloud_origin_from_tile_width(points: np.array, tile_width: int = 10
x_min, y_min = np.min(points[:, :2], axis=0) + buffer_size
x_max, y_max = np.max(points[:, :2], axis=0) - buffer_size

# Calculate the difference Xmin and Xmax, then Ymin and Ymax
diff_tile_x = np.floor(x_max / tile_width) - np.floor(x_min / tile_width)
is_x_max_on_edge = x_max % tile_width == 0
diff_tile_y = np.ceil(y_max / tile_width) - np.ceil(y_min / tile_width)
is_y_min_on_edge = y_min % tile_width == 0
# Check [x_min - x_max] == amplitude and [y_min - y_max] == amplitude
if (diff_tile_x == 0 or (diff_tile_x == 1 and is_x_max_on_edge)) and (
diff_tile_y == 0 or (diff_tile_y == 1 and is_y_min_on_edge)
):
origin_x = np.floor(x_min / tile_width) * tile_width # round low
origin_y = np.ceil(y_max / tile_width) * tile_width # round top
# Calculate the tiles to which x, y bounds belong
tile_x_min = np.floor(x_min / tile_width)
tile_x_max = np.floor(x_max / tile_width) if x_max % tile_width != 0 else np.floor(x_max / tile_width) - 1
tile_y_min = np.ceil(y_min / tile_width) if y_min % tile_width != 0 else np.floor(y_min / tile_width) + 1
tile_y_max = np.ceil(y_max / tile_width)

if not (tile_x_max - tile_x_min) and not (tile_y_max - tile_y_min):
origin_x = tile_x_min * tile_width
origin_y = tile_y_max * tile_width
return origin_x, origin_y
else:
raise ValueError(
Expand Down

0 comments on commit 228c569

Please sign in to comment.