Example #1
0
def test_full_circle_ellipse_edge_transformation(closed_edge_hatch):
    edge = closed_edge_hatch.paths[0].edges[0]
    assert arc_angle_span_deg(edge.start_angle,
                              edge.end_angle) == pytest.approx(360)

    closed_edge_hatch.transform(Matrix44.z_rotate(math.radians(30)))
    edge2 = closed_edge_hatch.paths[0].edges[0]
    assert arc_angle_span_deg(edge2.start_angle,
                              edge2.end_angle) == pytest.approx(360)
    def test_reflections(self, s, e, rotation, sx, sy):
        m = Matrix44.chain(
            Matrix44.scale(sx, sy, 1),
            Matrix44.z_rotate(rotation),
        )
        expected_start = m.transform(Vec3.from_deg_angle(s))
        expected_end = m.transform(Vec3.from_deg_angle(e))
        expected_angle_span = arc_angle_span_deg(s, e)

        ocs = OCSTransform(Z_AXIS, m)
        new_s, new_e = ocs.transform_ccw_arc_angles_deg(s, e)
        wcs_start = ocs.new_ocs.to_wcs(Vec3.from_deg_angle(new_s))
        wcs_end = ocs.new_ocs.to_wcs(Vec3.from_deg_angle(new_e))
        assert arc_angle_span_deg(new_s, new_e) == pytest.approx(
            expected_angle_span
        )
        assert wcs_start.isclose(expected_start)
        assert wcs_end.isclose(expected_end)
def test_dimension_line_divided_by_measurement_text(doc: Drawing, s, e):
    """Vertical centered measurement text should hide the part of the
    dimension line beneath the text. This creates two arcs instead of one.
    """
    msp = doc.modelspace()
    dim = msp.add_angular_dim_cra(
        center=Vec2(),
        radius=5,
        start_angle=s,
        end_angle=e,
        distance=2,
        override={"dimtad": 0},  # vertical centered text
    )
    dim.render()
    arcs = dim.dimension.get_geometry_block().query("ARC")
    assert len(arcs) == 2
    assert sum(
        arc_angle_span_deg(arc.dxf.start_angle, arc.dxf.end_angle)
        for arc in arcs) < arc_angle_span_deg(
            s, e), "sum of visual arcs should be smaller than the full arc"
Example #4
0
    def transform(self, m: Matrix44) -> 'Arc':
        """ Transform ARC entity by transformation matrix `m` inplace.

        Raises ``NonUniformScalingError()`` for non uniform scaling.

        """
        ocs = OCSTransform(self.dxf.extrusion, m)
        super().transform(m)
        s = self.dxf.start_angle
        e = self.dxf.end_angle
        if not math.isclose(arc_angle_span_deg(s, e), 360.0):
            self.dxf.start_angle = ocs.transform_deg_angle(s)
            self.dxf.end_angle = ocs.transform_deg_angle(e)
        return self
Example #5
0
    def transform(self, m: Matrix44) -> "Arc":
        """Transform ARC entity by transformation matrix `m` inplace.

        Raises ``NonUniformScalingError()`` for non uniform scaling.

        """
        ocs = OCSTransform(self.dxf.extrusion, m)
        super()._transform(ocs)
        s: float = self.dxf.start_angle
        e: float = self.dxf.end_angle
        if not math.isclose(arc_angle_span_deg(s, e), 360.0):
            (
                self.dxf.start_angle,
                self.dxf.end_angle,
            ) = ocs.transform_ccw_arc_angles_deg(s, e)
        self.post_transform(m)
        return self
Example #6
0
    def transform(self, ocs: OCSTransform, elevation: float) -> None:
        self.center = ocs.transform_2d_vertex(self.center, elevation)
        self.radius = ocs.transform_length(Vec3(self.radius, 0, 0))
        if not math.isclose(
            arc_angle_span_deg(self.start_angle, self.end_angle), 360.0
        ):  # open arc
            # The transformation of the ccw flag is not necessary for the current
            # implementation of OCS transformations. The arc angles have always
            # a counter clockwise orientation around the extrusion vector and
            # this orientation is preserved even for mirroring, which flips the
            # extrusion vector to (0, 0, -1) for entities in the xy-plane.

            self.start_angle = ocs.transform_deg_angle(self.start_angle)
            self.end_angle = ocs.transform_deg_angle(self.end_angle)
        else:  # full circle
            # Transform only start point to preserve the connection point to
            # adjacent edges:
            self.start_angle = ocs.transform_deg_angle(self.start_angle)
            # ArcEdge is represented in counter-clockwise orientation:
            self.end_angle = self.start_angle + 360.0
 def span(self, s, e):
     return arc_angle_span_deg(s, e)
Example #8
0
 def test_arc(self, start, end, expected):
     assert arc_angle_span_deg(start, end) == pytest.approx(expected)
Example #9
0
 def test_full_circle(self, start, end):
     assert arc_angle_span_deg(start, end) == 360.0
Example #10
0
 def test_no_arc(self, start, end):
     assert arc_angle_span_deg(start, end) == 0