From 779539ee697e1e182420492a2a23f3564943c287 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Thu, 15 Nov 2018 12:20:19 +0100 Subject: [PATCH] Use __contains__ method to check vehicules in area --- sumo_project/SUMOFactory.py | 3 +-- sumo_project/area.py | 6 +++--- sumo_project/emissions.py | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sumo_project/SUMOFactory.py b/sumo_project/SUMOFactory.py index 8f529db..80c9444 100644 --- a/sumo_project/SUMOFactory.py +++ b/sumo_project/SUMOFactory.py @@ -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): diff --git a/sumo_project/area.py b/sumo_project/area.py index 7f41202..b552aee 100644 --- a/sumo_project/area.py +++ b/sumo_project/area.py @@ -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(( diff --git a/sumo_project/emissions.py b/sumo_project/emissions.py index 7766ade..276dbb8 100644 --- a/sumo_project/emissions.py +++ b/sumo_project/emissions.py @@ -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)