def test_load_malformed_circle(): circle = Circle.from_text(MALFORMED_CIRCLE) assert circle.dxf.layer == "LY_EZDXF" assert circle.dxf.linetype == "LT_EZDXF" assert circle.dxf.color == 7 assert circle.dxf.center.isclose((1, 2, 3)) assert circle.dxf.radius == 2.0
def test_circle_fast_translation(): circle = Circle.new( dxfattribs={'center': (2, 3, 4), 'extrusion': Vector.random()}) ocs = circle.ocs() offset = Vector(1, 2, 3) center = ocs.to_wcs(circle.dxf.center) + offset circle.translate(*offset) assert ocs.to_wcs(circle.dxf.center).isclose(center, abs_tol=1e-9)
def test_circle_default_ocs(): circle = Circle.new(dxfattribs={'center': (2, 3, 4), 'thickness': 2}) # 1. rotation - 2. scaling - 3. translation m = Matrix44.chain(Matrix44.scale(2, 2, 3), Matrix44.translate(1, 1, 1)) # default extrusion is (0, 0, 1), therefore scale(2, 2, ..) is a uniform scaling in the xy-play of the OCS circle.transform(m) assert circle.dxf.center == (5, 7, 13) assert circle.dxf.extrusion == (0, 0, 1) assert circle.dxf.thickness == 6
def test_circle_to_code(): from ezdxf.entities.circle import Circle entity = Circle.new(handle='ABBA', owner='0', dxfattribs={ 'color': '7', 'center': (1, 2, 3), 'radius': 2, }) new_entity = translate_to_code_and_execute(entity) for name in ('color', 'center', 'radius'): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
def test_circle_non_uniform_scaling(): circle = Circle.new(dxfattribs={'center': (2, 3, 4), 'extrusion': (0, 1, 0), 'thickness': 2}) # extrusion in WCS y-axis, therefore scale(2, ..., 3) is a non uniform # scaling in the xy-play of the OCS which is the xz-plane of the WCS with pytest.raises(NonUniformScalingError): circle.transform(Matrix44.scale(2, 2, 3)) # source values unchanged after exception assert circle.dxf.center == (2, 3, 4) assert circle.dxf.extrusion == (0, 1, 0) assert circle.dxf.thickness == 2
def test_circle_to_code(): from ezdxf.entities.circle import Circle entity = Circle.new( handle="ABBA", owner="0", dxfattribs={ "color": "7", "center": (1, 2, 3), "radius": 2, }, ) new_entity = translate_to_code_and_execute(entity) for name in ("color", "center", "radius"): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
def test_circle_user_ocs(): center = (2, 3, 4) extrusion = (0, 1, 0) circle = Circle.new( dxfattribs={'center': center, 'extrusion': extrusion, 'thickness': 2}) ocs = OCS(extrusion) v = ocs.to_wcs(center) # (-2, 4, 3) v = Vector(v.x * 2, v.y * 4, v.z * 2) v += (1, 1, 1) # and back to OCS, extrusion is unchanged result = ocs.from_wcs(v) m = Matrix44.chain(Matrix44.scale(2, 4, 2), Matrix44.translate(1, 1, 1)) circle.transform(m) assert circle.dxf.center == result assert circle.dxf.extrusion == (0, 1, 0) assert circle.dxf.thickness == 8 # in WCS y-axis
def test_extrusion_can_not_be_a_null_vector(): circle = Circle.new(dxfattribs={'extrusion': (0, 0, 0)}) assert circle.dxf.extrusion == (0, 0, 1), 'expected default extrusion'
def test_zero_radius(): circle = Circle.new(dxfattribs={'radius': 0}) assert circle.dxf.radius == 0, 'Radius == 0 is valid'
def test_negative_radius(): circle = Circle.new(dxfattribs={'radius': -1}) assert circle.dxf.radius == -1, 'Radius < 0 is valid'
def test_zero_radius(): circle = Circle.new(dxfattribs={"radius": 0}) assert circle.dxf.radius == 0, "Radius == 0 is valid"
def test_circle_flattening(radius, sagitta, count): circle = Circle.new(dxfattribs={"radius": radius}) assert len(list(circle.flattening(sagitta))) == count