Пример #1
0
def _locate_point_in_indexed_polygons(tree: r.Tree,
                                      polygons: Sequence[Polygon],
                                      point: Point,
                                      context: Context) -> Location:
    candidates_indices = tree.find_supersets_indices(
        context.box_cls(point.x, point.x, point.y, point.y))
    for candidate_index in candidates_indices:
        location = polygons[candidate_index].locate(point)
        if location is not Location.EXTERIOR:
            return location
    return Location.EXTERIOR
Пример #2
0
def from_points(points: Iterable[Point],
                *,
                context: Context) -> Box:
    """
    Builds box from points.
    """
    points = iter(points)
    point = next(points)
    min_x, min_y = max_x, max_y = point.x, point.y
    for point in points:
        x, y = point.x, point.y
        if x < min_x:
            min_x = x
        elif x > max_x:
            max_x = x
        if y < min_y:
            min_y = y
        elif y > max_y:
            max_y = y
    return context.box_cls(min_x, max_x, min_y, max_y)