Skip to content

Commit

Permalink
Use point map instead of find
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Apr 18, 2024
1 parent a245183 commit fa0c13f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/admin_panel/src/lib/home/Stream.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,24 @@
function subscribeLidarDrawing() {
return lidar.subscribe((/** @type {Array<Point>} */ points) => {
if (points.length === 0) {
return;
}
lidar_context_.clearRect(
0,
0,
lidar_canvas_.width,
lidar_canvas_.height,
);
if (points.length === 0) {
return;
/** @type {Map<number, Point>} */
const point_map = new Map();
for (const point of points) {
point_map.set(round0_25(point.angle), point);
}
const space_between_angles = lidar_canvas_.width / 90;
const lidar_canvas_midpoint_y = lidar_canvas_.height / 2;
for (let i = 0; i < 90; i += 0.25) {
const point = points.find(
(point) => round0_25(point.angle) === i + offset_angle,
);
const point = point_map.get(round0_25(i + offset_angle));
if (point !== undefined) {
const angle = point.angle;
const distance = point.distance;
Expand Down

0 comments on commit fa0c13f

Please sign in to comment.