Skip to content

triangle_strategy

TriangleDrawingStrategy

Bases: ShapeDrawingStrategy

Drawing strategy for Triangle shapes.

draw(dwg, triangle)

Draws a Triangle shape on the given Drawing object.

Parameters:

Name Type Description Default
dwg Drawing

The Drawing object to draw the shape on.

required
triangle Triangle

The Triangle shape to draw.

required

Returns:

Type Description
None
Source code in layerforge/svg/drawing/strategies/triangle_strategy.py
13
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
def draw(self, dwg: Drawing, triangle: Triangle) -> None:
    """Draws a Triangle shape on the given Drawing object.

    Parameters
    ----------
    dwg : Drawing
        The Drawing object to draw the shape on.
    triangle : Triangle
        The Triangle shape to draw.

    Returns
    -------
    None
    """
    color = triangle.color or 'green'
    verts = triangle.vertices
    if triangle.angle:
        verts = []
        cx, cy = triangle.x, triangle.y
        for x, y in triangle.vertices:
            dx, dy = x - cx, y - cy
            r = math.hypot(dx, dy)
            theta = math.atan2(dy, dx) + triangle.angle
            verts.append((cx + r * math.cos(theta), cy + r * math.sin(theta)))

    dwg.add(dwg.polygon(verts, stroke=color, fill='none'))