1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-21 19:16:30 +00:00

Use __contains__ method to check vehicules in area

This commit is contained in:
Thibaud Gasser 2018-11-15 12:20:19 +01:00
parent 938e64b1f4
commit 779539ee69
3 changed files with 5 additions and 6 deletions

View File

@ -14,10 +14,9 @@ class SUMOFactory(object):
traci.vehicle.remove(veh_id, traci.constants.REMOVE_PARKING)
def lanes_in_area(self, area):
polygon_area = area.rectangle
for lane_id in traci.lane.getIDList():
polygon_lane = LineString(traci.lane.getShape(lane_id))
if polygon_area.intersects(polygon_lane):
if area.rectangle.intersects(polygon_lane):
yield lane_id
def lock_area(self, area):

View File

@ -12,13 +12,13 @@ class Area:
def __eq__(self, other):
return self.rectangle.__eq__(other)
def __contains__(self, item):
return self.rectangle.contains(Point(item))
@property
def bounds(self):
return self.rectangle.bounds
def contains(self, other):
return self.rectangle.contains(Point(other))
@classmethod
def from_bounds(cls, xmin, ymin, xmax, ymax):
return cls((

View File

@ -26,7 +26,7 @@ def emission_for_area(area):
# retrieve all vehicles into this area
for veh_id in traci.vehicle.getIDList():
pos = traci.vehicle.getPosition(veh_id)
if area.contains(pos):
if pos in area:
area.emissions += traci.vehicle.getCO2Emission(veh_id)