-
Notifications
You must be signed in to change notification settings - Fork 38
⚡ Bolt: Add bounding box pre-filter to spatial query #907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,10 +76,17 @@ def find_nearby_issues( | |
| """ | ||
| nearby_issues = [] | ||
|
|
||
| # Pre-filter using bounding box with 5% epsilon to optimize expensive haversine calculations | ||
| min_lat, max_lat, min_lon, max_lon = get_bounding_box(target_lat, target_lon, radius_meters * 1.05) | ||
|
|
||
| for issue in issues: | ||
| if issue.latitude is None or issue.longitude is None: | ||
| continue | ||
|
|
||
| # Fast bounding box pre-filter check | ||
| if not (min_lat <= issue.latitude <= max_lat and min_lon <= issue.longitude <= max_lon): | ||
| continue | ||
|
|
||
|
Comment on lines
+79
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== backend/spatial_utils.py (relevant slice) =="
nl -ba backend/spatial_utils.py | sed -n '1,220p'
echo
echo "== Search for longitude normalization / antimeridian handling =="
rg -n "longitude|antimeridian|180|normalize|bounding box|haversine" backend tests . -g '!**/.git/**' || true
echo
echo "== File list for nearby spatial tests =="
fd -a -t f "test|spec" backend tests . || trueRepository: RohanExploit/VishwaGuru Length of output: 249 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== backend/spatial_utils.py (relevant slice) =="
cat -n backend/spatial_utils.py | sed -n '1,220p'
echo
echo "== Search for longitude normalization / antimeridian handling =="
rg -n "longitude|antimeridian|180|normalize|bounding box|haversine" backend tests . -g '!**/.git/**' || true
echo
echo "== Files with tests/specs =="
fd -a -t f "test|spec" backend tests . || trueRepository: RohanExploit/VishwaGuru Length of output: 50380 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== longitude validation contract =="
cat -n backend/schemas.py | sed -n '40,70p'
echo
cat -n backend/main_fixed.py | sed -n '315,335p'
echo
echo "== spatial test coverage =="
cat -n tests/test_spatial_deduplication.py | sed -n '1,220p'
echo
echo "== antimeridian edge-case probe =="
python3 - <<'PY'
import math
def get_bounding_box(lat, lon, radius_meters):
R = 6378137.0
effective_lat = max(min(lat, 89.9), -89.9)
dlat = radius_meters / R
dlon = radius_meters / (R * math.cos(math.pi * effective_lat / 180.0))
lat_offset = dlat * 180.0 / math.pi
lon_offset = dlon * 180.0 / math.pi
return lat - lat_offset, lat + lat_offset, lon - lon_offset, lon + lon_offset
def haversine_distance(lat1, lon1, lat2, lon2):
R = 6371000.0
phi1, phi2 = math.radians(lat1), math.radians(lat2)
dphi = math.radians(lat2 - lat1)
dlambda = math.radians(lon2 - lon1)
a = math.sin(dphi / 2)**2 + math.cos(phi1) * math.cos(phi2) * math.sin(dlambda / 2)**2
return R * (2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)))
target_lat, target_lon, radius = 0.0, 179.9999, 50.0
issue_lat, issue_lon = 0.0, -179.9999
min_lat, max_lat, min_lon, max_lon = get_bounding_box(target_lat, target_lon, radius * 1.05)
print("bbox:", (min_lat, max_lat, min_lon, max_lon))
print("bbox_contains_issue:", min_lat <= issue_lat <= max_lat and min_lon <= issue_lon <= max_lon)
print("distance_m:", haversine_distance(target_lat, target_lon, issue_lat, issue_lon))
PYRepository: RohanExploit/VishwaGuru Length of output: 11117 Handle longitude ranges that cross the antimeridian. 🤖 Prompt for AI Agents |
||
| distance = haversine_distance( | ||
| target_lat, target_lon, | ||
| issue.latitude, issue.longitude | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Bounding box pre-filter can silently drop valid nearby issues when the search crosses the 180th meridian.
get_bounding_boxsubtracts/addslon_offsetfrom raw longitude without normalizing to [-180, 180], so near ±180° the box wraps incorrectly. For example, target_lon=179° with a large radius produces min_lon=172°, max_lon=186°, and an issue at -178° (2° away) fails the chained comparison and gets skipped. Consider normalizing the bounding box longitude range inget_bounding_box, or at least note the limitation. The PR default radius of 50m makes this very rare in practice; flagging for awareness.Prompt for AI agents