mirror of
				https://github.com/Ahp06/SUMO_Emissions.git
				synced 2025-11-04 03:59:19 +00:00 
			
		
		
		
	Use __contains__ method to check vehicules in area
This commit is contained in:
		@@ -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):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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((
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user