def test_marked_angles(): """Check Angle's instanciation.""" pointO = Point(0, 0, 'O') pointI = Point(1, 0, 'I') pointJ = Point(0, 1, 'J') required.tikz_library['angles'] = False theta = Angle(pointI, pointO, pointJ) assert theta.tikz_decorations() == '' theta.decoration = AngleDecoration(color='red', thickness='ultra thick', radius=Number(2)) assert theta.tikz_decorations() \ == 'pic [draw, ultra thick, angle radius = 2, red] {angle = I--O--J}' assert required.tikz_library['angles'] required.tikz_library['angles'] = False theta.mark_right = True theta.decoration = AngleDecoration() assert theta.label is None assert theta.tikz_decorations() == '' assert not required.tikz_library['angles'] assert theta.tikz_rightangle_mark() == \ '\draw[thick, cm={cos(0), sin(0), -sin(0), cos(0), (O)}]' \ ' (0.25 cm, 0) -- (0.25 cm, 0.25 cm) -- (0, 0.25 cm);' assert theta.tikz_rightangle_mark(winding='clockwise') == \ '\draw[thick, cm={cos(0), sin(0), -sin(0), cos(0), (O)}]' \ ' (0.25 cm, 0) -- (0.25 cm, -0.25 cm) -- (0, -0.25 cm);' with pytest.raises(ValueError) as excinfo: theta.tikz_rightangle_mark(winding=None) assert str(excinfo.value) == 'Expect \'clockwise\' or \'anticlockwise\'. '\ 'Found \'None\' instead.'
def test_drawing_double_decorated_angles(): P = Point(0, 0, 'P') L = Point(0, 2, 'L') E = Point('-1.84', '0.8', 'E') α = Angle(L, P, E, label_vertex=True, draw_vertex=True, label_endpoints=True, draw_endpoints=True, label=Number(39, unit=r'\textdegree')) α.decoration = AngleDecoration(radius=Number('0.7', unit='cm'), eccentricity=Number('1.6')) α.decoration2 = AngleDecoration(radius=Number('1.6', unit='cm'), eccentricity=Number('1.3'), label=Number(42, unit=r'\textdegree'), color='NavyBlue', do_draw=False, thickness=None) assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (L) at (0,2); \coordinate (P) at (0,0); \coordinate (E) at (-1.84,0.8); % Draw Angle \draw[thick] (L) -- (P) -- (E) pic ["\ang{39}", angle eccentricity=1.6, draw, thick, angle """\ r"""radius = 0.7 cm] {angle = L--P--E} pic ["\ang{42}", angle eccentricity=1.3, angle radius = 1.6 cm, """\ r"""NavyBlue] {angle = L--P--E};
def test_instanciation(): """Check Angle's instanciation.""" pointO = Point(0, 0, 'O') pointI = Point(1, 0, 'I') pointJ = Point(0, 1, 'J') pointA = Point(1, 1, 'A') theta = Angle(pointI, pointO, pointJ, mark_right=True) assert repr(theta) == 'Angle(I, O, J)' assert theta.measure == Number('90') assert isinstance(theta.decoration, AngleDecoration) assert theta.decoration.label is None assert theta.decoration.variety is None assert theta.mark_right assert theta.vertex == pointO assert theta.points == [pointI, pointO, pointJ] theta = Angle(pointA, pointO, pointI, decoration=AngleDecoration()) assert theta.measure == Number('315') assert Angle(pointI, pointO, pointA).measure == Number('45') assert not theta.mark_right assert theta.vertex == pointO assert theta.points == [pointA, pointO, pointI] theta = Angle(pointI, pointO, 60) assert theta.vertex == pointO assert theta.points[2] == Point('0.5', '0.866', 'I\'') A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(3, 5, 'Y') α = Angle(X, A, Y) assert α.winding == 'anticlockwise' assert α.arms[0] == Bipoint(A, X) assert α.arms[1] == Bipoint(A, Y)
def test_drawing_angles_with_arrowtips(): """Check drawing standalone Angles.""" A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(3, 5, 'Y') α = Angle(X, A, Y) α.decoration = AngleDecoration(arrow_tips='<->') assert α.drawn == r"""
def test_drawing_marked_rightangles(): """Check drawing standalone Angles.""" A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(-1, 6, 'Y') α = Angle(X, A, Y) α.decoration = AngleDecoration(radius=Number('0.5', unit='cm')) α.mark_right = True assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (-1,6); % Draw Angle \draw[thick] (X) -- (A) -- (Y); % Mark right angle \draw[thick, cm={cos(9.46), sin(9.46), -sin(9.46), cos(9.46), (A)}]"""\ r""" (0.5 cm, 0) -- (0.5 cm, 0.5 cm) -- (0, 0.5 cm);
def __init__(self, start_vertex=None, name=None, leg1_length=Number(2), leg2_length=Number(1), mark_right_angle=True, draw_vertices=False, label_vertices=True, thickness='thick', color=None, rotation_angle=0, winding=None, sloped_sides_labels=True): r""" Initialize Right Triangle :param start_vertex: the vertex to start to draw the Right Triangle (default (0; 0)) :type start_vertex: Point :param name: the name of the Triangle, like ABC. Can be either None (the names will be automatically created), or a string of the letters to use to name the vertices. Only single letters are supported as Points' names so far (at Polygon's creation). See issue #3. :type name: None or str :param leg1_length: the leg1's length that will be used to calculate the coordinates of the vertices used to build the RightTriangle :type leg1_length: a number :param leg2_length: the leg2's length that will be used to calculate the coordinates of the vertices used to build the RightTriangle :type leg2_length: a number :param mark_right_angle: if True (default), the right angle will be automatically marked as right angle. :type mark_right_angle: bool :param draw_vertices: whether to actually draw, or not, the vertices :type draw_vertices: bool :param label_vertices: whether to label, or not, the vertices :type label_vertices: bool :param thickness: the thickness of the Triangle's sides :type thickness: str :param color: the color of the Triangle's sides :type color: str :param rotate: the angle of rotation around isobarycenter :type rotate: int """ if start_vertex is None: start_vertex = Point(0, 0) # Accepted type for leg1's and leg2's lengths is number, will be # checked at vertices' instanciations. v1 = Point(leg1_length + start_vertex.x, start_vertex.y) v2 = Point(leg1_length + start_vertex.x, leg2_length + start_vertex.y) if (winding == 'clockwise' or (winding is None and config.polygons.DEFAULT_WINDING == 'clockwise')): start_vertex, v2 = v2, start_vertex Triangle.__init__(self, start_vertex, v1, v2, name=name, draw_vertices=draw_vertices, label_vertices=label_vertices, thickness=thickness, color=color, rotation_angle=rotation_angle, winding=winding, sloped_sides_labels=sloped_sides_labels) self._type = 'RightTriangle' if mark_right_angle: self.right_angle.decoration = AngleDecoration(thickness=thickness) self.right_angle.mark_right = True
def test_drawing_AnglesSets_of_same_vertex(): """Check drawing AnglesSets.""" A = Point(0, 0, 'A') X1 = Point(6, 1, 'X1') Y1 = Point(3, 5, 'Y1') Z1 = Point(1, '6.5', 'Z1') α = Angle(X1, A, Y1) β = Angle(Y1, A, Z1) S = AnglesSet(α, β) assert S.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (A) at (0,0); \coordinate (X1) at (6,1); \coordinate (Y1) at (3,5); \coordinate (Z1) at (1,6.5); % Draw Angles \draw[thick] (X1) -- (A) -- (Y1); \draw[thick] (Y1) -- (A) -- (Z1); % Label Points \end{tikzpicture} """ α.armspoints = [('X', ), ('Y', )] α.label_vertex = True α.draw_vertex = True β.armspoints = [('Y', ), ('Z', )] assert S.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (A) at (0,0); \coordinate (X1) at (6,1); \coordinate (Y1) at (3,5); \coordinate (X) at (4.8,0.8); \coordinate (Y) at (2.4,4); \coordinate (Z1) at (1,6.5); \coordinate (Z) at (0.8,5.2); % Draw Angles \draw[thick] (X1) -- (A) -- (Y1); \draw[thick] (Y1) -- (A) -- (Z1); % Draw Vertex \draw (A) node[scale=0.67] {$\times$}; % Draw Arms' Points \draw (X) node[scale=0.67] {$\times$}; \draw (Y) node[scale=0.67] {$\times$}; \draw (Z) node[scale=0.67] {$\times$}; % Label Points \draw (A) node[below] {A}; \draw (X) node[below right] {X}; \draw (Y) node[above left] {Y}; \draw (Z) node[above left] {Z}; \end{tikzpicture} """ A = Point(0, 0, 'A') X1 = Point(6, 1, 'X1') Y1 = Point(3, 5, 'Y1') Z1 = Point(1, '6.5', 'Z1') α = Angle(X1, A, Y1, armspoints=[('X', ), ('Y', )], label_vertex=True, draw_vertex=True, decoration=AngleDecoration(color='RoyalBlue', radius=Number('0.5', unit='cm')), label=Number(38, unit=r'\textdegree')) β = Angle(Y1, A, Z1, armspoints=[('Y', ), ('Z', )], decoration=AngleDecoration(color='BurntOrange', variety='double', radius=Number('0.5', unit='cm')), label=Number(9, unit=r'\textdegree')) γ = Angle(X1, A, Z1, label='?', decoration=AngleDecoration(color='BrickRed', radius=Number('2', unit='cm'), eccentricity=Number('1.15'))) S = AnglesSet(α, β, γ) assert S.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (A) at (0,0); \coordinate (X1) at (6,1); \coordinate (Y1) at (3,5); \coordinate (X) at (4.8,0.8); \coordinate (Y) at (2.4,4); \coordinate (Z1) at (1,6.5); \coordinate (Z) at (0.8,5.2); % Draw Angles \draw[thick] (X1) -- (A) -- (Y1) pic ["\ang{38}", angle eccentricity=1.8, draw, thick, """\ r"""angle radius = 0.5 cm, RoyalBlue] {angle = X1--A--Y1}; \draw[thick] (Y1) -- (A) -- (Z1) pic [draw, thick, angle radius = 0.5 cm, BurntOrange] {angle = Y1--A--Z1} pic ["\ang{9}", angle eccentricity=1.8, draw, thick, """\ r"""angle radius = 0.58 cm, BurntOrange] {angle = Y1--A--Z1}; \draw[thick] (X1) -- (A) -- (Z1) pic ["?", angle eccentricity=1.15, draw, thick, """\ r"""angle radius = 2 cm, BrickRed] {angle = X1--A--Z1};
def test_instanciation_errors(): """Check Angle's instanciation exceptions.""" pointO = Point(0, 0, 'O') pointI = Point(1, 0, 'I') pointJ = Point(0, 1, 'J') with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI) assert str(excinfo.value) == '__init__() missing 1 required positional ' \ 'argument: \'point_or_measure\'' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, 'J') assert str(excinfo.value) == 'Three Points, or two Points and the ' \ 'measure of the angle are required to build an Angle. ' \ 'Found instead: <class \'mathmakerlib.geometry.point.Point\'>, ' \ '<class \'mathmakerlib.geometry.point.Point\'> and ' \ '<class \'str\'>.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, mark_right=1) assert str(excinfo.value) == '\'mark_right\' must be a boolean' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, decoration='right') assert str(excinfo.value) == 'An angle decoration must be None or belong '\ 'to the AngleDecoration class. Got <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, decoration2='right') assert str(excinfo.value) == 'An angle decoration must be None or belong '\ 'to the AngleDecoration class. Got <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, decoration=AngleDecoration(variety='unknown')) assert str(excinfo.value) == 'AngleDecoration\'s variety can be None, ' \ '\'single\', \'double\' or \'triple\'. Found \'unknown\' instead '\ '(type: <class \'str\'>).' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, draw_vertex='a') assert str(excinfo.value) == 'draw_vertex must be a boolean; ' \ 'got <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, label_vertex='a') assert str(excinfo.value) == 'label_vertex must be a boolean; ' \ 'got <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, draw_endpoints='a') assert str(excinfo.value) == 'draw_endpoints must be a boolean; ' \ 'got <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, label_endpoints='a') assert str(excinfo.value) == 'label_endpoints must be a boolean; ' \ 'got <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, draw_armspoints='a') assert str(excinfo.value) == 'draw_armspoints must be a boolean; ' \ 'got <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, label_armspoints='a') assert str(excinfo.value) == 'label_armspoints must be a boolean; ' \ 'got <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, armspoints='X') assert str(excinfo.value) == 'A list must be provided to setup ' \ 'armspoints. Found <class \'str\'> instead.' with pytest.raises(ValueError) as excinfo: Angle(pointO, pointI, pointJ, armspoints=['1', '2', '3']) assert str(excinfo.value) == 'More values are provided (3) then ' \ 'available arms (2).' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, armspoints=['1', '2']) assert str(excinfo.value) == 'Each arm\'s point must be defined by a ' \ 'tuple. Found <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: Angle(pointO, pointI, pointJ, armspoints=[('1', '2', '3'), ('2', )]) assert str(excinfo.value) == 'Each arm\'s point must be defined by a ' \ 'tuple of 1 or 2 elements. Found 3 elements instead.' with pytest.raises(ValueError) as excinfo: Angle( pointO, pointI, pointJ, label=Number(38, unit=r'\textdegree'), decoration=AngleDecoration(label=Number(37, unit=r'\textdegree'))) assert str(excinfo.value) == r"The label has been set twice, as Angle's "\ r"keyword argument (Number('38 \textdegree')) and as its "\ r"AngleDecoration's keyword argument (Number('37 \textdegree'))."
def test_drawing_marked_labeled_angles(): """Check drawing standalone Angles.""" A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(3, 5, 'Y') α = Angle(X, A, Y, label=Number(38, unit=r'\textdegree')) α.decoration = AngleDecoration(radius=Number('0.5', unit='cm')) assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic ["\ang{38}", angle eccentricity=1.8, draw, thick, """\ r"""angle radius = 0.5 cm] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ α.decoration.variety = 'double' assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic [draw, thick, angle radius = 0.5 cm] {angle = X--A--Y} pic ["\ang{38}", angle eccentricity=1.8, draw, thick, """\ r"""angle radius = 0.58 cm] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ A = Point(0, 0, 'A') X1 = Point(6, 1, 'X1') Y1 = Point(3, 5, 'Y1') α = Angle(X1, A, Y1, armspoints=[('X', ), ('Y', )], label_vertex=True, draw_vertex=True, label=Number(38, unit=r'\textdegree')) α.decoration = AngleDecoration(radius=Number('0.5', unit='cm'), variety='double', hatchmark='singledash') assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X1) at (6,1); \coordinate (A) at (0,0); \coordinate (Y1) at (3,5); \coordinate (X) at (4.8,0.8); \coordinate (Y) at (2.4,4); % Draw Angle \draw[thick] (X1) -- (A) -- (Y1) pic [draw, thick, angle radius = 0.5 cm, singledash] {angle = X1--A--Y1} pic ["\ang{38}", angle eccentricity=1.8, draw, thick, """\ r"""angle radius = 0.58 cm, singledash] {angle = X1--A--Y1};
def test_drawing_marked_angles(): """Check drawing standalone Angles.""" A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(3, 5, 'Y') α = Angle(X, A, Y) α.decoration = AngleDecoration(radius=Number('0.5', unit='cm')) assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic [draw, thick, angle radius = 0.5 cm] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ α.decoration.variety = 'double' assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic [draw, thick, angle radius = 0.5 cm] {angle = X--A--Y} pic [draw, thick, angle radius = 0.58 cm] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ α.decoration.variety = 'triple' assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic [draw, thick, angle radius = 0.5 cm] {angle = X--A--Y} pic [draw, thick, angle radius = 0.58 cm] {angle = X--A--Y} pic [draw, thick, angle radius = 0.66 cm] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ α.decoration.variety = 'single' α.decoration.hatchmark = 'singledash' assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic [draw, thick, angle radius = 0.5 cm, singledash] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ assert required.tikz_library['decorations.markings'] assert required.tikzset['singledash_hatchmark'] assert not required.tikzset['doubledash_hatchmark'] assert not required.tikzset['tripledash_hatchmark'] required.tikz_library['decorations.markings'] = False required.tikzset['singledash_hatchmark'] = False α.decoration.hatchmark = 'doubledash' assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic [draw, thick, angle radius = 0.5 cm, doubledash] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ assert required.tikz_library['decorations.markings'] assert not required.tikzset['singledash_hatchmark'] assert required.tikzset['doubledash_hatchmark'] assert not required.tikzset['tripledash_hatchmark'] required.tikz_library['decorations.markings'] = False required.tikzset['doubledash_hatchmark'] = False α.decoration.hatchmark = 'tripledash' assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic [draw, thick, angle radius = 0.5 cm, tripledash] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ assert required.tikz_library['decorations.markings'] assert not required.tikzset['singledash_hatchmark'] assert not required.tikzset['doubledash_hatchmark'] assert required.tikzset['tripledash_hatchmark'] α.decoration.variety = 'triple' α.decoration.hatchmark = 'doubledash' assert α.drawn == r"""
def test_drawing_labeled_angles(): """Check drawing standalone Angles.""" A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(3, 5, 'Y') α = Angle(X, A, Y, label=Number(38, unit=r'\textdegree')) required.tikz_library['quotes'] = False assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic ["\ang{38}", angle eccentricity=2.6] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ assert required.tikz_library['quotes'] assert α.label == r'\ang{38}' α.decoration = None assert α.label == r'\ang{38}' assert α.decoration is not None assert repr(α.decoration) == r'AngleDecoration(variety=None; '\ r'hatchmark=None; label=\ang{38}; color=None; thickness=thick; '\ r'radius=0.25 cm; eccentricity=2.6)' α = Angle(X, A, Y, decoration=AngleDecoration(label=Number(38, unit=r'\textdegree'), variety=None)) assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic ["\ang{38}", angle eccentricity=2.6] {angle = X--A--Y}; % Label Points \end{tikzpicture} """ α = Angle(X, A, Y, label=Number(38, unit=r'\textdegree'), decoration=AngleDecoration(radius=Number('0.9', unit='cm'))) assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y) pic ["\ang{38}", angle eccentricity=1.44, draw, thick, """\ r"""angle radius = 0.9 cm] {angle = X--A--Y};
def test_AngleDecoration(): assert repr(AngleDecoration()) == 'AngleDecoration(variety=single; '\ 'hatchmark=None; label=default; color=None; thickness=thick; '\ 'radius=0.25 cm; eccentricity=2.6)' ad = AngleDecoration(radius=Number(1, unit='cm')) assert ad.arrow_tips is None assert repr(ad) == \ 'AngleDecoration(variety=single; '\ 'hatchmark=None; label=default; color=None; thickness=thick; '\ 'radius=1 cm; eccentricity=1.4)' ad.radius = Number(2, unit='cm') assert repr(ad) == \ 'AngleDecoration(variety=single; '\ 'hatchmark=None; label=default; color=None; thickness=thick; '\ 'radius=2 cm; eccentricity=1.2)' assert AngleDecoration().tikz_attributes() \ == '[draw, thick, angle radius = 0.25 cm]' assert AngleDecoration(color='green', thickness='thin').tikz_attributes() \ == '[draw, thin, angle radius = 0.25 cm, green]' assert AngleDecoration(radius=Number('0.5', unit=Unit('cm'))) \ .tikz_attributes() == '[draw, thick, angle radius = 0.5 cm]' with pytest.raises(ValueError) as excinfo: AngleDecoration(radius=Number(2, unit='cm'), gap=None) assert str(excinfo.value) == 'Cannot calculate the eccentricity if gap '\ 'is None.' with pytest.raises(TypeError) as excinfo: AngleDecoration(radius='2 cm') assert str(excinfo.value) == 'Expected a number as radius. Got ' \ '<class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: AngleDecoration(gap='2 cm') assert str(excinfo.value) == 'The gap value must be None or a number. '\ 'Found \'2 cm\' instead (type: <class \'str\'>).' with pytest.raises(TypeError) as excinfo: AngleDecoration().tikz_attributes(radius_coeff='a') assert str(excinfo.value) == 'radius_coeff must be a number, '\ 'found <class \'str\'> instead.' with pytest.raises(TypeError) as excinfo: AngleDecoration(hatchmark='unknown') assert str(excinfo.value) == 'AngleDecoration\'s hatchmark can be None, '\ '\'singledash\', \'doubledash\' or \'tripledash\'. ' \ 'Found \'unknown\' instead (type: <class \'str\'>).' with pytest.raises(TypeError) as excinfo: AngleDecoration(eccentricity='a') assert str(excinfo.value) == 'The eccentricity of an AngleDecoration '\ 'must be None or a Number. Found <class \'str\'> instead.' with pytest.raises(RuntimeError) as excinfo: AngleDecoration().generate_tikz('A', 'B') assert str(excinfo.value) == 'Three Points\' names must be provided to '\ 'generate the AngleDecoration. Found 2 arguments instead.' with pytest.raises(TypeError) as excinfo: AngleDecoration(do_draw='a') assert str(excinfo.value) == 'do_draw must be a boolean; '\ 'got <class \'str\'> instead.'
def __init__(self, *points, start_vertex=None, name=None, width=Number(1), length=Number(2), mark_right_angles=True, draw_vertices=False, label_vertices=True, thickness='thick', color=None, rotation_angle=0, winding=None, sloped_sides_labels=True): r""" Initialize Rectangle. This will be done either using the points (if provided) of the points parameter or using the keyword arguments start_vertex, width... :param points: a list of 4 points that will be the vertices of the Rectangle. It is possible to provide no Point at all. :type points: a list of Points :param start_vertex: the vertex to start to draw the Rectangle (default (0; 0)) :type start_vertex: Point :param name: the name of the Rectangle, like ABCD. Can be either None (the names will be automatically created), or a string of the letters to use to name the vertices. Only single letters are supported as Points' names so far (at Polygon's creation). See issue #3. :type name: None or str :param width: the width that will be used to calculate the coordinates of the vertices used to build the Rectangle :type width: a number :param length: the length that will be used to calculate the coordinates of the vertices used to build the Rectangle :type length: a number :param mark_right_angles: if True (default), all four angles will be automatically marked as right angles. :type mark_right_angles: bool :param draw_vertices: whether to actually draw, or not, the vertices :type draw_vertices: bool :param label_vertices: whether to label, or not, the vertices :type label_vertices: bool :param thickness: the thickness of the Polygon's sides :type thickness: str :param color: the color of the Polygon's sides :type color: str :param rotate: the angle of rotation around isobarycenter :type rotate: int """ if points: (v0, v1, v2, v3) = points self._length = Bipoint(v0, v1).length self._width = Bipoint(v1, v2).length else: # 2D Rectangles only (so far) if start_vertex is None: start_vertex = Point(0, 0) # Accepted type for width and length is number, will be checked at # vertices' instanciations. self._width = width self._length = length v0 = start_vertex v1 = Point(length + start_vertex.x, start_vertex.y) v2 = Point(length + start_vertex.x, width + start_vertex.y) v3 = Point(start_vertex.x, width + start_vertex.y) Quadrilateral.__init__(self, v0, v1, v2, v3, name=name, draw_vertices=draw_vertices, label_vertices=label_vertices, thickness=thickness, color=color, rotation_angle=rotation_angle, winding=winding, sloped_sides_labels=sloped_sides_labels) self._type = 'Rectangle' if mark_right_angles: for a in self.angles: a.decoration = AngleDecoration(thickness=thickness) a.mark_right = True