Revert "Faster Bats"

This reverts commit e8f526f6b8.
This commit is contained in:
firestarsdog
2026-07-27 23:16:58 -04:00
parent 762ced4157
commit 28d03e95d3
2 changed files with 14 additions and 32 deletions
+3 -3
View File
@@ -463,12 +463,12 @@ class ModelRenderer(Widget):
rl.draw_triangle_fan(lead.chevron, len(lead.chevron), with_alpha(lead_color, lead.fill_alpha))
@staticmethod
def _get_path_length_idx(pos_x_array: np.ndarray, path_distance: float) -> int:
def _get_path_length_idx(pos_x_array: np.ndarray, path_height: float) -> int:
"""Get the index corresponding to the given path height"""
if len(pos_x_array) == 0:
return 0
idx = np.searchsorted(pos_x_array, path_distance, side='right') - 1
return idx if idx >= 0 else 0
indices = np.where(pos_x_array <= path_height)[0]
return indices[-1] if indices.size > 0 else 0
def _map_to_screen(self, in_x, in_y, in_z):
"""Project a point in car space to screen space"""
+11 -29
View File
@@ -606,35 +606,17 @@ class ModelRenderer(Widget):
radius = 4.0
red_color = rl.Color(255, 0, 0, 200)
# Pre-extract bounds and matrix values for native loop speed
x_min, x_max = self._rect.x, self._rect.x + self._rect.width
y_min, y_max = self._rect.y, self._rect.y + self._rect.height
t = self._car_space_transform
m00, m01, m02 = float(t[0, 0]), float(t[0, 1]), float(t[0, 2])
m10, m11, m12 = float(t[1, 0]), float(t[1, 1]), float(t[1, 2])
offset_z = float(self._path_offset_z)
for point in radar_points:
d_rel = float(point.dRel)
# 1. Fast binary search instead of np.where boolean mask
idx = np.searchsorted(path_x_array, d_rel, side='right') - 1
idx = idx if idx >= 0 else 0
z = float(line_z[idx]) if idx < len(line_z) else 0.0
d_rel = point.dRel
idx = self._get_path_length_idx(path_x_array, d_rel)
z = line_z[idx] if idx < len(line_z) else 0.0
# 2. Native unrolled matrix multiplication (Bypasses np.array allocation overhead)
in_y = float(-point.yRel)
in_z = z + offset_z
pt_x = m00 * d_rel + m01 * in_y + m02 * in_z
pt_y = m10 * d_rel + m11 * in_y + m12 * in_z
# 3. Native clipping (50x faster than np.clip on scalars)
x = max(x_min, min(pt_x, x_max))
y = max(y_min, min(pt_y, y_max))
rl.draw_circle_v(rl.Vector2(x, y), radius, red_color)
calibrated_point = self._map_to_screen(d_rel, -point.yRel, z + self._path_offset_z)
if calibrated_point:
x, y = calibrated_point
x = np.clip(x, self._rect.x, self._rect.x + self._rect.width)
y = np.clip(y, self._rect.y, self._rect.y + self._rect.height)
rl.draw_circle_v(rl.Vector2(x, y), radius, red_color)
def _update_adjacent_paths(self, max_idx: int, max_distance: float):
"""Compute adjacent lane path polygons by averaging lane line pairs."""
@@ -723,8 +705,8 @@ class ModelRenderer(Widget):
"""Get the index corresponding to the given path distance"""
if len(pos_x_array) == 0:
return 0
idx = np.searchsorted(pos_x_array, path_distance, side='right') - 1
return idx if idx >= 0 else 0
indices = np.where(pos_x_array <= path_distance)[0]
return indices[-1] if indices.size > 0 else 0
def _map_to_screen(self, in_x, in_y, in_z):
"""Project a point in car space to screen space"""