def from_mxCell(el, lineWidth=10) -> Tuple[List[Component], dict]: # Parse style style = parse_style(el.attrib['style']) # Get parent style['parent'] = el.attrib['parent'] # Get geometry geometry = el[0] x = float(geometry.attrib.get('x', '0')) y = float(geometry.attrib.get('y', '0')) width = float(geometry.attrib['width']) height = float(geometry.attrib['height']) # Create drawing pos = Position(x=x, y=y, w=width, h=height, movable=False) rotate = 0 if style.get('rotation', '') != '': rotate = int(style['rotation']) if rotate < 0: rotate = 360 + rotate pos.angle = rotate center = (pos.x + pos.w // 2, pos.y + pos.h // 2) if 'ellipse' in style: draw = primitives.Ellipse(center, width, height, style, rotate) col_points = draw._get_points() else: col_points = pos._get_box() return [pos, Collidable([(center, col_points)])], style
def from_mxCell(el, lineWidth=10): # Parse style style = parse_style(el.attrib['style']) if style.get('shape') != 'mxgraph.floorplan.wall': raise Exception( "Cannot create Wall from {}: shape is not mxgraph.floorplan.wall". format(el)) # Get parent parent_element = el.attrib['parent'] style['parent'] = parent_element # Get geometry geometry = el[0] x = float(geometry.attrib.get('x', '0')) y = float(geometry.attrib.get('y', '0')) width = float(geometry.attrib['width']) height = float(geometry.attrib['height']) # Create drawing pos = Position(x=x, y=y, w=width, h=height, movable=False) rotate = 0 if 'rotation' in style: rotate = float(style['rotation']) rotate = (360 + rotate) % 360 pos.angle = rotate # Create collision box col_points = pos._get_box() center = (pos.x + pos.w // 2, pos.y + pos.h // 2) return [pos, Collidable([(center, col_points)])], style
def build_object(object, world: esper.World, window_options, draw2entity): logger = logging.getLogger(__name__) mxCell = object[0] mxGeometry = mxCell[0] # Get X, Y coordinates x = float(mxGeometry.attrib.get('x', 0)) y = float(mxGeometry.attrib.get('y', 0)) width = float(mxGeometry.attrib.get('width', 0)) height = float(mxGeometry.attrib.get('height', 0)) pos = Position(x, y, 0, width, height) x += (width // 2) y += (height // 2) # Get the Map for simulation or create one # Entity 1 is the simulation entity if world.has_component(1, Map): simulation_map = world.component_for_entity(1, Map) else: simulation_map = Map() world.add_component(1, simulation_map) # Get POI tag if 'tag' in object.attrib: tag = object.attrib['tag'] else: tag = 'POI_' + str(len(simulation_map.pois)) logger.warning(f'POI ({x}, {y}) with no TAG. Using {tag}') simulation_map.pois[tag] = (x, y) # Alternatively display the POI if object.attrib.get('display', False): skeleton = Skeleton(object.attrib['id'], mxCell.attrib['style'], tag) world.create_entity(pos, skeleton) return {}, [], {}
def find_safe_route(hover: Hover, mypos: Position, myvel: Velocity, they: List[Position]): # Local refs to functions rotate_point = rotate_around_point pos_x = mypos.x pos_y = mypos.y # is_hovering = hover.status == HoverState.HOVERING SAFE_FACTOR = 1 if not is_hovering else 0 # 10 degrees increments from original goal up do 90 degrees HEADINGS = [ 0.0, 0.523599, 1.047198, 1.48353, 5.23599, 5.759589, 5.759587, 2.094396, 2.617995, 3.061594, 3.665193, 4.188792, 4.712391 ] hits = [(0, 0, 0, 0)] * 13 for i, h in enumerate(HEADINGS): newx = pos_x + myvel.x newy = pos_y + myvel.y newx, newy = rotate_point((newx, newy), h, (pos_x, pos_y)) my_next_position = Position(x=newx, y=newy, w=mypos.w, h=mypos.h) hit = reduce( lambda acc, hit_count: acc + hit_count, map(lambda t: intercept(my_next_position, t, SAFE_FACTOR), they), 0) # for other in they: # if intercept(my_next_position, other, SAFE_FACTOR): # hit += 1 hits[i] = (hit, i, newx, newy) hits.sort() (hit, i, newx, newy) = hits[0] myvel.x = (newx - pos_x) / (1 + hit + random.random() if not is_hovering else 1.1) myvel.y = (newy - pos_y) / (1 + hit + random.random() if not is_hovering else 1.1)
def from_mxCell(el, line_width=10) -> Tuple[List[Component], dict]: # Parse style style = parse_style(el.attrib['style']) if style.get('shape', "") != 'mxgraph.floorplan.wallCorner': raise Exception( "Cannot create Wall from {}: shape is not mxgraph.floorplan.wallCorner" .format(el)) # Get parent parent_element = el.attrib['parent'] direction = style.get('direction', 'east') style['parent'] = parent_element # Get geometry geometry = el[0] x = float(geometry.attrib.get('x', '0')) y = float(geometry.attrib.get('y', '0')) width = float(geometry.attrib['width']) height = float(geometry.attrib['height']) # Create drawing pos = Position(x=x, y=y, w=width, h=height, movable=False) center = (pos.x + pos.w // 2, pos.y + pos.h // 2) boxes: List[ShapeDefinition] = [ ((pos.x + line_width // 2, pos.y + pos.h // 2), [(pos.x, pos.y), (pos.x + line_width, pos.y), (pos.x + line_width, pos.y + pos.h), (pos.x, pos.y + pos.h)]), ((pos.x + pos.w // 2, pos.y + line_width // 2), [(pos.x, pos.y), (pos.x + pos.w, pos.y), (pos.x + pos.w, pos.y + line_width), (pos.x, pos.y + line_width)]) ] # Get the right corner if direction == 'north': boxes = list( map(lambda sd: mirror_shape_definition_vertically(sd, pos.center), boxes)) elif direction == 'south': # Mirror along vertical axis boxes = list( map( lambda sd: mirror_shape_definition_horizontally( sd, pos.center), boxes)) elif direction == 'west': boxes = list( map(lambda sd: rotate_shape_definition(sd, 180, pos.center), boxes)) # Check for rotation if style.get('rotation', '') != '': rotate = int(style['rotation']) if rotate < 0: rotate = 360 + rotate boxes = list( map(lambda sd: rotate_shape_definition(sd, rotate, pos.center), boxes)) return [pos, Collidable(boxes)], style
def from_mxCell(el: Element, line_width=10) -> Tuple[List[Component], dict]: # Parse style style = parse_style(el.attrib['style']) if style.get('shape', "") != 'mxgraph.floorplan.room': raise Exception( "Cannot create Wall from {}: shape is not mxgraph.floorplan.room". format(el)) # Get geometry geometry = el[0] x = float(geometry.attrib.get('x', '0')) y = float(geometry.attrib.get('y', '0')) width = float(geometry.attrib['width']) height = float(geometry.attrib['height']) # Create drawing pos = Position(x=x, y=y, w=width, h=height, movable=False) center = (pos.x + pos.w // 2, pos.y + pos.h // 2) points = [(pos.x, pos.y), (pos.x, pos.y + pos.h), (pos.x - line_width // 2, pos.y + pos.h), (pos.x + pos.w + line_width // 2, pos.y + pos.h), (pos.x + pos.w, pos.y + pos.h), (pos.x + pos.w, pos.y), (pos.x + pos.w + line_width // 2, pos.y), (pos.x - line_width // 2, pos.y)] # Collision points # TODO: Verify corners boxes: List[ShapeDefinition] = [ ((pos.x + line_width // 2, pos.y + pos.h // 2), [(pos.x, pos.y), (pos.x, pos.y + pos.h), (pos.x + line_width, pos.y + pos.h), (pos.x + line_width, pos.y)]), ((pos.x + pos.w // 2, pos.y + pos.h + line_width // 2), [(pos.x, pos.y + pos.h), (pos.x, pos.y + pos.h + line_width), (pos.x + pos.w, pos.y + pos.h + line_width), (pos.x + pos.w, pos.y + pos.h)]), ((pos.x + pos.w + line_width // 2, pos.y + pos.h // 2), [(pos.x + pos.w, pos.y + pos.h), (pos.x + pos.w + line_width, pos.y + pos.h), (pos.x + pos.w + line_width, pos.y), (pos.x + pos.w, pos.y)]), ((pos.x + pos.w // 2, pos.y + line_width // 2), [(pos.x, pos.y), (pos.x, pos.y + line_width), (pos.x + pos.w, pos.y + line_width), (pos.x + pos.w, pos.y)]) ] if style.get('rotation', '') != '': rotate = int(style['rotation']) if rotate < 0: rotate = 360 - rotate boxes = list( map(lambda sd: rotate_shape_definition(sd, rotate, center), boxes)) return [pos, Collidable(boxes)], style
def from_mxCell(el, line_width=10) -> Tuple[List[Component], dict]: # Parse style style = parse_style(el.attrib['style']) if style.get('shape', "") != 'mxgraph.floorplan.wallU': raise Exception("Cannot create Wall from {}: shape is not mxgraph.floorplan.wallU".format(el)) # Get parent style['parent'] = el.attrib['parent'] # Get geometry geometry = el[0] x = float(geometry.attrib.get('x', '0')) y = float(geometry.attrib.get('y', '0')) width = float(geometry.attrib['width']) height = float(geometry.attrib['height']) # Create drawing pos = Position(x=x, y=y, w=width, h=height, movable=False) # Collision box boxes: List[ShapeDefinition] = [ ( (pos.x + line_width // 2, pos.y + pos.h // 2), [(pos.x, pos.y), (pos.x + line_width, pos.y), (pos.x + line_width, pos.y + pos.h), (pos.x, pos.y + pos.h)] ), ( (pos.x + pos.w // 2, pos.y + line_width // 2), [(pos.x, pos.y), (pos.x + pos.w, pos.y), (pos.x + pos.w, pos.y + line_width), (pos.x, pos.y + line_width)] ), ( (pos.x + pos.w - (line_width // 2), pos.y + pos.h // 2), [(pos.x + pos.w - line_width, pos.y), (pos.x + pos.w, pos.y), (pos.x + pos.w, pos.y + pos.h), (pos.x + pos.w - line_width, pos.y + pos.h)] ) ] if style.get('rotation', '') != '': rotate = int(style['rotation']) rotate = (rotate + 360) % 360 boxes = list(map(lambda sd: rotate_shape_definition(sd, -rotate, pos.center), boxes)) return [pos, Collidable(boxes)], style
def add_sector_info(self, pos: Position): pos.sector = ((pos.y // self.sector_size) * self.maxx) + (pos.x // self.sector_size)