def rect(x: float, y: float, width: float, height: float) -> vp.LineCollection: """ Generate a rectangle. The rectangle is defined by its top left corner (X, Y) and its width and height. """ return vp.LineCollection([vp.rect(x, y, width, height)])
def rect( x: float, y: float, width: float, height: float, radii: Tuple[float, float, float, float], quantization: float, ) -> vp.LineCollection: """Generate a rectangle, with optional rounded angles. The rectangle is defined by its top left corner (X, Y) and its width and height. Examples: Straight-angle rectangle: vpype rect 10cm 10cm 3cm 2cm show Rounded-angle rectangle: vpype rect --radii 5mm 5mm 5mm 5mm 10cm 10cm 3cm 2cm show Rounded-angle rectangle with quantization control: vpype rect --quantization 0.1mm --radii 5mm 5mm 5mm 5mm 10cm 10cm 3cm 2cm show """ return vp.LineCollection( [vp.rect(x, y, width, height, *radii, quantization)])
def test_rect_quantization(quantization): line = vp.rect(0, 0, 300, 400, 3, 3, 3, 3, quantization) seg_len = np.abs(np.diff(line)) assert np.max(seg_len[seg_len < 100]) < quantization
from vsketch.fill import generate_fill from vsketch.utils import complex_to_2d def _simulate_pen(lc: vp.LineCollection, lw: float) -> MultiPolygon: return unary_union( [ LineString(complex_to_2d(line)).buffer(lw, join_style=2, mitre_limit=10.0) for line in lc ] ) @pytest.mark.skip(reason="this cannot work until Toblerity/Shapely#958 is fixed") @pytest.mark.parametrize("line", [vp.circle(0, 0, 10), vp.rect(0, 0, 10, 20)]) @pytest.mark.parametrize("lw", [0.01, 0.1, 1, 10]) def test_fill(line, lw): """Let's use some computational geometry to ensure the fill pattern properly covers the desired area """ p = Polygon(complex_to_2d(line)) fill_lc = generate_fill(line, lw) overfill_p = _simulate_pen(fill_lc, 1.2 * lw / 2) underfill_p = _simulate_pen(fill_lc, 0.8 * lw / 2) assert overfill_p.contains(p) assert p.contains(underfill_p)