1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-22 03:26: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) traci.vehicle.remove(veh_id, traci.constants.REMOVE_PARKING)
def lanes_in_area(self, area): def lanes_in_area(self, area):
polygon_area = area.rectangle
for lane_id in traci.lane.getIDList(): for lane_id in traci.lane.getIDList():
polygon_lane = LineString(traci.lane.getShape(lane_id)) polygon_lane = LineString(traci.lane.getShape(lane_id))
if polygon_area.intersects(polygon_lane): if area.rectangle.intersects(polygon_lane):
yield lane_id yield lane_id
def lock_area(self, area): def lock_area(self, area):

View File

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

View File

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