Example #1
0
def extents(entities: Iterable['DXFEntity'],
            cache: Cache = None) -> BoundingBox:
    """ Returns a single bounding box for all given `entities`. """
    _extends = BoundingBox()
    for box in multi_flat(entities, cache):
        _extends.extend(box)
    return _extends
Example #2
0
 def test_init_none(self):
     bbox = BoundingBox()
     assert bbox.is_empty is True
     assert bbox.has_data is False
     bbox.extend([(0, 0, 0), (10, 10, 10)])
     assert bbox.size == (10, 10, 10)
     assert bbox.is_empty is False
     assert bbox.has_data is True
Example #3
0
def test_nearly_vertical_parallel_lines_in_linear_trace_builder():
    width = 30
    trace = LinearTrace()
    trace.add_station((0, 100), width, width)
    trace.add_station((0, 100_000), width, width)
    trace.add_station((0.001, 0), width, width)
    bbox = BoundingBox()
    for face in trace.faces():
        bbox.extend(face)
    assert bbox.extmin.y > -100
Example #4
0
File: bbox.py Project: malanx/ezdxf
def extends(entities: Iterable['DXFEntity'],
            cache: Cache = None) -> BoundingBox:
    """ Returns a single bounding box for the given `entities` and their sub
    entities. Good caching behavior!

    """
    _extends = BoundingBox()
    for box in multi_flat(entities, cache):
        _extends.extend(box)
    return _extends
Example #5
0
def extents(entities: Iterable['DXFEntity'], *,
            flatten: float = MAX_FLATTENING_DISTANCE,
            cache: Cache = None) -> BoundingBox:
    """ Returns a single bounding box for all given `entities`.

    Calculate bounding boxes from flattened curves, if argument `flatten`
    is not 0 (max flattening distance), else from control points.

    """
    _extends = BoundingBox()
    for box in multi_flat(entities, flatten=flatten, cache=cache):
        _extends.extend(box)
    return _extends
Example #6
0
def extents(entities: Iterable['DXFEntity'],
            *,
            flatten: bool = True,
            cache: Cache = None) -> BoundingBox:
    """ Returns a single bounding box for all given `entities`.

    Calculate bounding boxes from flattened curves, if argument `flatten` is
    ``True``, else from control points.

    """
    _extends = BoundingBox()
    for box in multi_flat(entities, flatten=flatten, cache=cache):
        _extends.extend(box)
    return _extends
Example #7
0
def bbox(paths: Iterable[Path], flatten=0.01,
         segments: int = 16) -> BoundingBox:
    """ Returns the :class:`~ezdxf.math.BoundingBox` for the given paths.

    Args:
        paths: iterable of :class:`~ezdxf.path.Path` objects
        flatten: value != 0  for bounding box calculation from the flattened
        path and value == 0 for bounding box from the control vertices.
        Default value is 0.01 as max flattening distance.
        segments: minimal segment count for flattening

    """
    box = BoundingBox()
    for p in paths:
        if flatten:
            box.extend(p.flattening(distance=abs(flatten), segments=segments))
        else:
            box.extend(p.control_vertices())
    return box
Example #8
0
def bbox(paths: Iterable[Path],
         flatten=True,
         distance: float = 0.01,
         segments: int = 16) -> BoundingBox:
    """ Returns the :class:`~ezdxf.math.BoundingBox` for the given paths.

    Args:
        paths: iterable of :class:`~ezdxf.path.Path` objects
        flatten: ``True`` for bounding box from the flattened path and ``False``
            for bounding box from the control vertices.
        distance: flattening distance, default is 0.01
        segments: minimal segment count for flattening

    """
    box = BoundingBox()
    for p in paths:
        if flatten:
            box.extend(p.flattening(distance, segments=segments))
        else:
            box.extend(p.control_vertices())
    return box
Example #9
0
    def test_extend(self):
        bbox = BoundingBox([(0, 0, 0), (10, 10, 10)])
        bbox.extend([(5, 5, 5)])
        assert bbox.extmin == (0, 0, 0)
        assert bbox.extmax == (10, 10, 10)

        bbox.extend([(15, 16, 17)])
        assert bbox.extmin == (0, 0, 0)
        assert bbox.extmax == (15, 16, 17)

        bbox.extend([(-15, -16, -17)])
        assert bbox.extmin == (-15, -16, -17)
        assert bbox.extmax == (15, 16, 17)
Example #10
0
 def extends_(entities_: Iterable['DXFEntity']) -> BoundingBox:
     _extends = BoundingBox()
     for _box in multi_recursive(entities_, cache):
         _extends.extend(_box)
     return _extends
Example #11
0
 def extends_(entities_: Iterable["DXFEntity"]) -> BoundingBox:
     _extends = BoundingBox()
     for _box in multi_recursive(entities_, flatten=flatten, cache=cache):
         _extends.extend(_box)
     return _extends
Example #12
0
 def test_extend_by_bbox(self):
     bbox = BoundingBox([(0, 0, 0), (10, 10, 10)])
     bbox2 = BoundingBox([(5, 5, 5), (15, 16, 17)])
     bbox.extend(bbox2)
     assert bbox.extmin == (0, 0, 0)
     assert bbox.extmax == (15, 16, 17)
Example #13
0
 def test_extend_by_empty_list(self):
     bbox = BoundingBox([(0, 0, 0), (10, 10, 10)])
     bbox.extend([])
     assert bbox.extmin == (0, 0, 0)
     assert bbox.extmax == (10, 10, 10)