Skip to content

arrow_strategy

ArrowDrawingStrategy

Bases: ShapeDrawingStrategy

Drawing strategy for Arrow shapes.

draw(dwg, arrow)

Draws an Arrow shape on the given Drawing object.

Parameters:

Name Type Description Default
dwg Drawing

The Drawing object to draw the shape on.

required
arrow Arrow

The Arrow shape to draw.

required
Source code in layerforge/svg/drawing/strategies/arrow_strategy.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def draw(self, dwg: Drawing, arrow: Arrow):
    """Draws an Arrow shape on the given Drawing object.

    Parameters
    ----------
    dwg : Drawing
        The Drawing object to draw the shape on.
    arrow : Arrow
        The Arrow shape to draw.
    """
    angle = arrow.angle
    if abs(angle) > 2 * math.pi:
        angle = math.radians(angle)

    end = (
        arrow.x + arrow.size * math.cos(angle),
        arrow.y + arrow.size * math.sin(angle),
    )

    head = arrow.size * 0.2

    stroke_color = arrow.color or 'black'
    dwg.add(dwg.line((arrow.x, arrow.y), end, stroke=stroke_color))
    dwg.add(
        dwg.polygon(
            [
                end,
                (
                    end[0] - head * math.cos(angle + math.pi / 6),
                    end[1] - head * math.sin(angle + math.pi / 6),
                ),
                (
                    end[0] - head * math.cos(angle - math.pi / 6),
                    end[1] - head * math.sin(angle - math.pi / 6),
                ),
            ],
            fill="none",
            stroke=stroke_color,
        )
    )