def test_square_default_success(vsk: vsketch.Vsketch) -> None: vsk.square(2, 2, 2.5) assert line_count_equal(vsk, 1) assert line_exists(vsk, np.array( [2 + 2j, 4.5 + 2j, 4.5 + 4.5j, 2 + 4.5j, 2 + 2j]), strict=False)
def test_square_mode_success( vsk: vsketch.Vsketch, data: Tuple[float, float, float], mode: str, expected: Sequence[float], ) -> None: vsk.square(*data, mode=mode) # type: ignore assert line_count_equal(vsk, 1) assert line_exists(vsk, np.array(expected, dtype=complex), strict=False)
def draw(self, vsk: vsketch.Vsketch) -> None: vsk.size("a4", landscape=False) vsk.scale("1mm") with vsk.pushMatrix(): for _ in range(40): vsk.rotate(2, degrees=True) vsk.scale(0.95) vsk.point(-75, 75) vsk.point(0, 75) vsk.point(75, 75) vsk.point(75, 0) vsk.point(75, -75) vsk.point(0, -75) vsk.point(-75, -75) vsk.point(-75, 0) with vsk.pushMatrix(): vsk.rotate(80, degrees=True) vsk.scale(0.95**40) vsk.square(0, 0, 150, mode="center")
def draw(self, vsk: vsketch.Vsketch) -> None: vsk.size("a4", landscape=True) vsk.scale("1cm") vsk.penWidth("0.5mm") p = translate( Polygon( [(-3, -1), (1.5, -2), (1.4, 2), (0, 1.5), (-1, 2.3)], holes=[[(-0.5, -0.5), (0.5, -0.5), (0.5, 0.5), (-0.5, 0.5)]], ), 2.5, 14, ) # the default is no fill and stroke to layer 1 vsk.square(0, 0, 4) vsk.circle(2, 8, 4) vsk.geometry(p) vsk.translate(7, 0) # add some fill to layer 2 vsk.fill(2) vsk.penWidth("1mm", 2) vsk.square(0, 0, 4) vsk.circle(2, 8, 4) vsk.geometry(p) vsk.translate(7, 0) # with thick stroke vsk.fill(2) vsk.penWidth("1mm", 2) vsk.strokeWeight(4) vsk.square(0, 0, 4) vsk.circle(2, 8, 4) vsk.geometry(p) vsk.translate(7, 0) # remove stroke and set fill to layer 3 with a thicker pen vsk.fill(3) vsk.penWidth("2mm", 3) vsk.noStroke() vsk.square(0, 0, 4) vsk.circle(2, 8, 4) vsk.geometry(p)
def test_square_arg(vsk: vsketch.Vsketch) -> None: # vsk.square() expects exactly 6 args with pytest.raises(TypeError): # noinspection PyArgumentList vsk.square(0.5, 2) # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker vsk.square("hey", 3, 5) # type: ignore with pytest.raises(ValueError): vsk.square(2, 2, 2.5, mode="jumbo")