Skip to content

Commit beb078f

Browse files
hadiTabmartins-mozeiko
authored andcommitted
Add batch processing for Map/GPS conversions
1 parent 5cfffdd commit beb078f

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

lgsvl/geometry.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ def to_json(self):
2020
def __repr__(self):
2121
return "Vector({}, {}, {})".format(self.x, self.y, self.z)
2222

23+
def __add__(self, v):
24+
return Vector(self.x + v.x, self.y + v.y, self.z + v.z)
25+
26+
def __sub__(self, v):
27+
return Vector(self.x - v.x, self.y - v.y, self.z - v.z)
28+
29+
def __mul__(self, v):
30+
return Vector(self.x * v.x, self.y * v.y, self.z * v.z)
2331

2432
class BoundingBox:
2533
def __init__(self, min, max):

lgsvl/simulator.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,45 @@ def map_from_gps(self, latitude = None, longitude = None, northing = None, easti
175175
if orientation is not None:
176176
if not isinstance(orientation, numtype): raise TypeError("Argument 'orientation' should have '{}' type".format(numtype))
177177
j["orientation"] = orientation
178-
j = self.remote.command("map/from_gps", j)
179-
return Transform.from_json(j)
178+
j = self.remote.command("map/from_gps", [j])
179+
return Transform.from_json(j[0])
180+
181+
def map_from_gps_batch(self, coords):
182+
# coords dictionary
183+
jarr = []
184+
185+
for c in coords:
186+
j = {}
187+
numtype = (int, float)
188+
if ("latitude" in c) and ("longitude" in c):
189+
if not isinstance(c["latitude"], numtype): raise TypeError("Argument 'latitude' should have '{}' type".format(numtype))
190+
if not isinstance(c["longitude"], numtype): raise TypeError("Argument 'longitude' should have '{}' type".format(numtype))
191+
if c["latitude"] < -90 or c["latitude"] > 90: raise ValueError("Latitude is out of range")
192+
if c["longitude"] < -180 or c["longitude"] > 180: raise ValueError("Longitude is out of range")
193+
j["latitude"] = c["latitude"]
194+
j["longitude"] = c["longitude"]
195+
elif ("northing" in c) and ("easting" in c):
196+
if not isinstance(c["northing"], numtype): raise TypeError("Argument 'northing' should have '{}' type".format(numtype))
197+
if not isinstance(c["easting"], numtype): raise TypeError("Argument 'easting' should have '{}' type".format(numtype))
198+
if c["northing"] < 0 or c["northing"] > 10000000: raise ValueError("Northing is out of range")
199+
if c["easting"] < -340000 or c["easting"] > 334000 : raise ValueError("Easting is out of range")
200+
j["northing"] = c["northing"]
201+
j["easting"] = c["easting"]
202+
else:
203+
raise Exception("Either latitude and longitude or northing and easting should be specified")
204+
if "altitude" in c:
205+
if not isinstance(c["altitude"], numtype): raise TypeError("Argument 'altitude' should have '{}' type".format(numtype))
206+
j["altitude"] = c["altitude"]
207+
if "orientation" in c:
208+
if not isinstance(c["orientation"], numtype): raise TypeError("Argument 'orientation' should have '{}' type".format(numtype))
209+
j["orientation"] = c["orientation"]
210+
jarr.append(j)
211+
212+
jarr = self.remote.command("map/from_gps", jarr)
213+
transforms = []
214+
for j in jarr:
215+
transforms.append(Transform.from_json(j))
216+
return transforms
180217

181218
@accepts(Vector)
182219
def map_point_on_lane(self, point):

0 commit comments

Comments
 (0)