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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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.
    """
    # TODO: Add some of this as attributes to the Arrow class
    angle = 90  # TODO: Determine if a direction should be added to the arrow
    end = (arrow.x + arrow.size * math.cos(angle),
           arrow.y + arrow.size * math.sin(angle))
    # TODO: Get stroke and fill from the shape or config
    dwg.add(dwg.line((arrow.x, arrow.y), end, stroke='black'))
    dwg.add(dwg.polygon(
        [end,
         (end[0] - 10 * math.cos(angle + math.pi / 6), end[1] - 10 * math.sin(angle + math.pi / 6)),
         (end[0] - 10 * math.cos(angle - math.pi / 6),
          end[1] - 10 * math.sin(angle - math.pi / 6))],
        fill='none', stroke='black'))