Phase 2.2: performance optimizations, debug tools, app close fix
This commit is contained in:
@@ -98,6 +98,59 @@ class LineOfSightService:
|
||||
"profile": profile
|
||||
}
|
||||
|
||||
def check_line_of_sight_sync(
|
||||
self,
|
||||
tx_lat: float, tx_lon: float, tx_height: float,
|
||||
rx_lat: float, rx_lon: float, rx_height: float = 1.5,
|
||||
num_samples: int = 50
|
||||
) -> dict:
|
||||
"""
|
||||
Sync LOS check - terrain tiles must be pre-loaded into memory.
|
||||
Returns dict with has_los, clearance, blocked_at (no profile for speed).
|
||||
"""
|
||||
profile = self.terrain.get_elevation_profile_sync(
|
||||
tx_lat, tx_lon, rx_lat, rx_lon, num_samples
|
||||
)
|
||||
|
||||
if not profile:
|
||||
return {"has_los": True, "clearance": 0, "blocked_at": None}
|
||||
|
||||
tx_ground = profile[0]["elevation"]
|
||||
rx_ground = profile[-1]["elevation"]
|
||||
|
||||
tx_total = tx_ground + tx_height
|
||||
rx_total = rx_ground + rx_height
|
||||
|
||||
total_distance = profile[-1]["distance"]
|
||||
|
||||
min_clearance = float('inf')
|
||||
blocked_at = None
|
||||
|
||||
for point in profile:
|
||||
d = point["distance"]
|
||||
terrain_elev = point["elevation"]
|
||||
|
||||
if total_distance == 0:
|
||||
los_height = tx_total
|
||||
else:
|
||||
los_height = tx_total + (rx_total - tx_total) * (d / total_distance)
|
||||
|
||||
effective_radius = self.K_FACTOR * self.EARTH_RADIUS
|
||||
curvature = (d * (total_distance - d)) / (2 * effective_radius)
|
||||
los_height_corrected = los_height - curvature
|
||||
clearance = los_height_corrected - terrain_elev
|
||||
|
||||
if clearance < min_clearance:
|
||||
min_clearance = clearance
|
||||
if clearance <= 0:
|
||||
blocked_at = d
|
||||
|
||||
return {
|
||||
"has_los": min_clearance > 0,
|
||||
"clearance": min_clearance,
|
||||
"blocked_at": blocked_at,
|
||||
}
|
||||
|
||||
async def calculate_fresnel_clearance(
|
||||
self,
|
||||
tx_lat: float, tx_lon: float, tx_height: float,
|
||||
|
||||
Reference in New Issue
Block a user