Beispiel #1
0
def test_rotation():
    # normalization is not necessary
    ux = Vector(1, 2, 0)
    # only cartesian coord systems work
    uy = ux.rotate_deg(90)
    ucs = UCS(ux=ux, uy=uy)
    assert ucs.ux == ux.normalize()
    assert ucs.uy == uy.normalize()
    assert ucs.uz == (0, 0, 1)
    assert ucs.is_cartesian is True
Beispiel #2
0
def test_matrix44_rotation():
    # normalization is not necessary
    ux = Vector(1, 2, 0)
    # only cartesian coord systems work
    uy = ux.rotate_deg(90)
    ucs = UCS(ux=ux, uy=uy)
    m = Matrix44.ucs(ux=ux.normalize(), uy=uy.normalize())
    assert m.ux == ux.normalize()
    assert m.uy == uy.normalize()
    assert m.uz == (0, 0, 1)
    assert m.is_cartesian
    v = m.transform((1, 2, 3))
    assert v == ucs.to_wcs((1, 2, 3))
    assert m.ucs_vertex_from_wcs(v) == (1, 2, 3)
Beispiel #3
0
    def multi_insert(self) -> Iterable['Insert']:
        """ Yields a virtual INSERT entity for each grid element of a MINSERT
        entity (multi-insert).

        .. versionadded:: 0.14

        """

        def transform_attached_attrib_entities(insert, offset):
            for attrib in insert.attribs:
                attrib.dxf.insert += offset

        def adjust_dxf_attribs(insert, offset):
            dxf = insert.dxf
            dxf.insert += offset
            dxf.discard('row_count')
            dxf.discard('column_count')
            dxf.discard('row_spacing')
            dxf.discard('column_spacing')

        done = set()
        row_spacing = self.dxf.row_spacing
        col_spacing = self.dxf.column_spacing
        rotation = self.dxf.rotation
        for row in range(self.dxf.row_count):
            for col in range(self.dxf.column_count):
                # All transformations in OCS:
                offset = Vector(col * col_spacing, row * row_spacing)
                # If any spacing is 0, yield only unique locations:
                if offset not in done:
                    done.add(offset)
                    if rotation:  # Apply rotation to the grid.
                        offset = offset.rotate_deg(rotation)
                    # Do not apply scaling to the grid!
                    insert = self.copy()
                    adjust_dxf_attribs(insert, offset)
                    transform_attached_attrib_entities(insert, offset)
                    yield insert