Shape Renderers

This section documents all available shape renderers and the factory system.

Shape Factory

Shape renderer factory for managing and creating shape renderers.

This module provides a centralized factory for creating shape renderers and managing the registry of available shapes.

The factory pattern allows:

  • Dynamic registration of new shape renderers

  • Centralized management of shape types

  • Easy extension with custom shapes

  • Consistent renderer instantiation

Example

Using the factory to create renderers:

factory = get_shape_factory()
renderer = factory.create_renderer('star', {})
element = renderer.render(0, 0, 10)

Registering a custom renderer:

register_custom_renderer('my-shape', MyShapeRenderer)
class segnomms.shapes.factory.ShapeRendererFactory[source]

Bases: RendererFactory

Factory for creating and managing shape renderers.

This factory maintains a registry of available shape renderers and provides methods to create appropriate renderers based on shape type names.

_renderers

Internal registry mapping shape names to renderer classes

__init__()[source]

Initialize factory and register all default renderers.

Return type:

None

register_renderer(shape_type, renderer_class)[source]

Register a custom shape renderer.

Parameters:
  • shape_type (str) – Name of the shape type

  • renderer_class (Type[ShapeRenderer]) – Renderer class to register

Return type:

None

Example

>>> factory.register_renderer('my-shape', MyShapeRenderer)
create_renderer(shape_type, config)[source]

Create a renderer for the specified shape type.

Parameters:
  • shape_type (str) – Type of shape to render

  • config (Dict[str, Any]) – Configuration parameters (currently unused)

Returns:

Instance of appropriate renderer

Return type:

ShapeRenderer

Note

Falls back to ‘square’ renderer if shape type is not found, but logs a warning with available options.

list_supported_types()[source]

List all shape types supported by this factory.

Returns:

List of all registered shape type names

Return type:

List[str]

is_supported(shape_type)[source]

Check if a shape type is supported.

Parameters:

shape_type (str) – Shape type name to check

Returns:

True if shape type is registered

Return type:

bool

get_renderer_info(shape_type)[source]

Get information about a specific renderer.

Parameters:

shape_type (str) – Shape type to query

Returns:

Information including class name, supported types, and module # noqa: E501

Return type:

Dict[str, Any]

get_all_renderer_info()[source]

Get information about all registered renderers.

Returns:

Mapping of renderer class names to their info

Return type:

Dict[str, Dict[str, Any]]

segnomms.shapes.factory.get_shape_factory()[source]

Get the global shape factory instance.

Returns:

Singleton factory instance

Return type:

ShapeRendererFactory

Note

This function ensures only one factory instance exists globally.

segnomms.shapes.factory.register_custom_renderer(shape_type, renderer_class)[source]

Register a custom shape renderer with the global factory.

Parameters:
  • shape_type (str) – Name of the shape type

  • renderer_class (Type[ShapeRenderer]) – Renderer class to register

Return type:

None

Example

>>> from segnomms import register_custom_renderer
>>> register_custom_renderer('my-shape', MyShapeRenderer)
segnomms.shapes.factory.create_shape_renderer(shape_type, config=None)[source]

Create a shape renderer using the global factory.

Parameters:
  • shape_type (str) – Type of shape to render

  • config (Optional[Dict[str, Any]]) – Optional configuration parameters

Returns:

Instance of appropriate renderer

Return type:

ShapeRenderer

Example

>>> renderer = create_shape_renderer('star')
>>> element = renderer.render(0, 0, 10)
segnomms.shapes.factory.list_available_shapes()[source]

List all available shape types.

Returns:

List of all registered shape type names

Return type:

List[str]

Example

>>> shapes = list_available_shapes()
>>> print(shapes)
['square', 'circle', 'dot', 'diamond', ...]
segnomms.shapes.factory.is_shape_supported(shape_type)[source]

Check if a shape type is supported.

Parameters:

shape_type (str) – Shape type name to check

Returns:

True if shape type is available

Return type:

bool

Example

>>> is_shape_supported('star')
True
>>> is_shape_supported('invalid')
False

Basic Shapes

Basic shape renderers for QR code modules.

This module provides simple geometric shape renderers that don’t depend on neighboring modules. Each renderer creates a single SVG element for each QR code module.

Available shapes:
  • SquareRenderer: Traditional square modules

  • CircleRenderer: Circular modules

  • DotRenderer: Small circular dots

  • DiamondRenderer: Diamond/rhombus shapes

  • StarRenderer: Configurable star shapes

  • TriangleRenderer: Directional triangles

  • HexagonRenderer: Six-sided polygons

  • CrossRenderer: Plus/cross shapes

class segnomms.shapes.basic.BaseShapeRenderer[source]

Bases: ShapeRenderer

Abstract base class for basic shape renderers with common functionality.

Provides standardized implementations of common methods like supports_type() and shared constants. Subclasses should define shape_names to specify which shape types they support.

shape_names: List[str] = []
supports_type(shape_type)[source]

Check if this renderer supports the given shape type.

Parameters:

shape_type (str) – Name of the shape type to check

Returns:

True if shape_type is in the renderer’s shape_names list

Return type:

bool

segnomms.shapes.basic.apply_element_attributes(element, kwargs)[source]

Apply common attributes to an SVG element.

This helper function applies standard attributes like id, data-* attributes, and other interactive properties to SVG elements.

Parameters:
  • element (Element) – SVG element to modify

  • kwargs (Union[Dict[str, Any], Any]) – Dictionary of attributes, may include: - id: Element ID - data-row: Row position data attribute - data-col: Column position data attribute - data-type: Module type data attribute - Any other attribute to be applied

Return type:

None

segnomms.shapes.basic.create_svg_element(tag, attributes, kwargs)[source]

Create an SVG element with common attributes applied.

This helper function combines element creation with common attribute application, reducing boilerplate code across all renderers.

Parameters:
  • tag (str) – SVG element tag name (e.g., ‘rect’, ‘circle’, ‘polygon’)

  • attributes (Dict[str, Any]) – Dictionary of SVG-specific attributes

  • kwargs (Union[Dict[str, Any], Any]) – Additional parameters including css_class, id, data-* attributes

Returns:

SVG element with all attributes applied

Return type:

ET.Element

segnomms.shapes.basic.get_module_center(x, y, size)[source]

Calculate the center point of a module.

Parameters:
  • x (float) – Module’s top-left x coordinate

  • y (float) – Module’s top-left y coordinate

  • size (float) – Module size

Returns:

Center coordinates (cx, cy)

Return type:

tuple[float, float]

segnomms.shapes.basic.apply_size_ratio(size, kwargs, default=1.0)[source]

Apply size ratio from kwargs to a base size.

Parameters:
  • size (float) – Base size value

  • kwargs (Union[Dict[str, Any], Any]) – Parameters dictionary that may contain ‘size_ratio’

  • default (float) – Default ratio if not specified in kwargs

Returns:

Size multiplied by the ratio

Return type:

float

segnomms.shapes.basic.get_corner_radius(size, kwargs, param_name='roundness', default=0.3)[source]

Calculate corner radius from size and roundness parameter.

Parameters:
  • size (float) – Base size value

  • kwargs (Union[Dict[str, Any], Any]) – Parameters dictionary

  • param_name (str) – Name of the parameter to look for (default: ‘roundness’)

  • default (float) – Default roundness ratio if not specified

Returns:

Corner radius value

Return type:

float

segnomms.shapes.basic.generate_regular_polygon(center_x, center_y, radius, sides, start_angle=0.0)[source]

Generate points for a regular polygon.

Parameters:
  • center_x (float) – X coordinate of polygon center

  • center_y (float) – Y coordinate of polygon center

  • radius (float) – Distance from center to vertices

  • sides (int) – Number of polygon sides (must be >= 3)

  • start_angle (float) – Starting angle in radians (default: 0.0)

Returns:

List of point strings in “x,y” format for SVG polygon

Return type:

list[str]

Raises:

ValueError – If sides < 3

segnomms.shapes.basic.generate_star_polygon(center_x, center_y, outer_radius, inner_radius, points, start_angle=-1.5707963267948966)[source]

Generate points for a star polygon.

Parameters:
  • center_x (float) – X coordinate of star center

  • center_y (float) – Y coordinate of star center

  • outer_radius (float) – Distance from center to outer points

  • inner_radius (float) – Distance from center to inner points

  • points (int) – Number of star points (must be >= 3)

  • start_angle (float) – Starting angle in radians (default: -π/2 for upward point)

Returns:

List of point strings in “x,y” format for SVG polygon

Return type:

list[str]

Raises:

ValueError – If points < 3

segnomms.shapes.basic.generate_diamond_points(x, y, size)[source]

Generate points for a diamond (rotated square) shape.

Parameters:
  • x (float) – Top-left x coordinate of bounding box

  • y (float) – Top-left y coordinate of bounding box

  • size (float) – Size of the bounding box

Returns:

List of point strings for diamond polygon

Return type:

list[str]

segnomms.shapes.basic.generate_triangle_points(x, y, size, direction='up')[source]

Generate points for a triangle in the specified direction.

Parameters:
  • x (float) – Top-left x coordinate of bounding box

  • y (float) – Top-left y coordinate of bounding box

  • size (float) – Size of the bounding box

  • direction (str) – Triangle direction (‘up’, ‘down’, ‘left’, ‘right’)

Returns:

List of point strings for triangle polygon

Return type:

list[str]

Raises:

ValueError – If direction is not valid

class segnomms.shapes.basic.SquareRenderer[source]

Bases: BaseShapeRenderer

Renders traditional square QR code modules.

The most basic shape renderer, creating perfect squares for each module. This is the default shape for QR codes and provides maximum reliability for scanning while maintaining the classic QR code appearance.

Example

>>> renderer = SquareRenderer()
>>> square = renderer.render(0, 0, 10)
>>> # Creates a 10x10 square at position (0,0)
shape_names: List[str] = ['square']
render(x, y, size, **kwargs)[source]

Render a square module.

Parameters:
  • x (float) – X coordinate of the top-left corner

  • y (float) – Y coordinate of the top-left corner

  • size (float) – Width and height of the square

  • **kwargs (Any) – Additional parameters including: css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID

Returns:

SVG rect element

Return type:

ET.Element

class segnomms.shapes.basic.CircleRenderer[source]

Bases: BaseShapeRenderer

Renders circular QR code modules.

Creates perfect circles that fit within the module grid. This shape provides a softer, more organic appearance while maintaining good scannability due to the consistent module centers.

Example

>>> renderer = CircleRenderer()
>>> circle = renderer.render(5, 5, 10)
>>> # Creates a circle with radius 5 centered at (10,10)
shape_names: List[str] = ['circle']
render(x, y, size, **kwargs)[source]

Render a circular module.

Parameters:
  • x (float) – X coordinate of the module’s top-left corner

  • y (float) – Y coordinate of the module’s top-left corner

  • size (float) – Module size (circle diameter)

  • **kwargs (Any) – Additional parameters including: css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID

Returns:

SVG circle element centered in the module

Return type:

ET.Element

class segnomms.shapes.basic.RoundedRenderer[source]

Bases: BaseShapeRenderer

Renders square modules with rounded corners.

Creates modules with softly rounded corners for a more friendly, modern appearance. The corner radius can be controlled via the roundness parameter.

Example

>>> renderer = RoundedRenderer()
>>> rounded_rect = renderer.render(0, 0, 10, roundness=0.3)
>>> # Creates a square with 30% corner radius
shape_names: List[str] = ['rounded']
render(x, y, size, **kwargs)[source]

Render a rounded square module.

Parameters:
  • x (float) – X coordinate of the module’s top-left corner

  • y (float) – Y coordinate of the module’s top-left corner

  • size (float) – Module size

  • **kwargs (Any) – Additional parameters including: roundness: Corner radius as fraction of size (default: 0.3) css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID

Returns:

SVG rect element with rounded corners

Return type:

ET.Element

class segnomms.shapes.basic.DotRenderer[source]

Bases: BaseShapeRenderer

Renders small dot modules for a minimalist QR code style.

Creates smaller circles that leave more whitespace between modules, resulting in a lighter, more delicate appearance. The dot size can be controlled via the size_ratio parameter.

Example

>>> renderer = DotRenderer()
>>> dot = renderer.render(0, 0, 10, size_ratio=0.5)
>>> # Creates a 5-pixel diameter dot in a 10x10 module
shape_names: List[str] = ['dot']
render(x, y, size, **kwargs)[source]

Render a small dot module.

Parameters:
  • x (float) – X coordinate of the module’s top-left corner

  • y (float) – Y coordinate of the module’s top-left corner

  • size (float) – Module size

  • **kwargs (Any) – Additional parameters including: size_ratio: Dot size relative to module (default: 0.6) css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID

Returns:

SVG circle element smaller than the module size

Return type:

ET.Element

class segnomms.shapes.basic.DiamondRenderer[source]

Bases: BaseShapeRenderer

Renders diamond (rhombus) shaped modules.

Creates 45-degree rotated squares that form diamond patterns. This shape adds a geometric, crystalline quality to QR codes while maintaining good contrast for scanning.

Example

>>> renderer = DiamondRenderer()
>>> diamond = renderer.render(0, 0, 10)
>>> # Creates a diamond touching all edges of the 10x10 module
shape_names: List[str] = ['diamond']
render(x, y, size, **kwargs)[source]

Render a diamond shape module.

Parameters:
  • x (float) – X coordinate of the module’s top-left corner

  • y (float) – Y coordinate of the module’s top-left corner

  • size (float) – Module size

  • **kwargs (Any) – Additional parameters including: css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID

Returns:

SVG polygon element forming a diamond

Return type:

ET.Element

class segnomms.shapes.basic.StarRenderer[source]

Bases: BaseShapeRenderer

Renders star-shaped modules with configurable points.

Creates multi-pointed star shapes that add a decorative flair to QR codes. The number of points and the inner/outer radius ratio can be customized to create different star styles from sharp to more rounded.

Example

>>> renderer = StarRenderer()
>>> star = renderer.render(0, 0, 10, star_points=6, inner_ratio=0.4)
>>> # Creates a 6-pointed star with sharp points
shape_names: List[str] = ['star']
render(x, y, size, **kwargs)[source]

Render a star shape module.

Parameters:
  • x (float) – X coordinate of the module’s top-left corner

  • y (float) – Y coordinate of the module’s top-left corner

  • size (float) – Module size

  • **kwargs (Any) – Additional parameters including: star_points: Number of star points (default: 5) inner_ratio: Inner radius ratio 0-1 (default: 0.5) css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID

Returns:

SVG polygon element forming a star

Return type:

ET.Element

class segnomms.shapes.basic.TriangleRenderer[source]

Bases: BaseShapeRenderer

Renders triangular modules with directional orientation.

Creates equilateral triangles that can point in different directions. This shape adds a dynamic, directional quality to QR codes and can create interesting patterns when modules align.

Example

>>> renderer = TriangleRenderer()
>>> triangle = renderer.render(0, 0, 10, direction='up')
>>> # Creates an upward-pointing triangle
shape_names: List[str] = ['triangle']
render(x, y, size, **kwargs)[source]

Render a triangle shape module.

Parameters:
  • x (float) – X coordinate of the module’s top-left corner

  • y (float) – Y coordinate of the module’s top-left corner

  • size (float) – Module size

  • **kwargs (Any) – Additional parameters including: direction: Triangle direction (‘up’, ‘down’, ‘left’, ‘right’) css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID

Returns:

SVG polygon element forming a triangle

Return type:

ET.Element

class segnomms.shapes.basic.HexagonRenderer[source]

Bases: BaseShapeRenderer

Renders hexagonal modules for a honeycomb-like appearance.

Creates regular hexagons that can tessellate beautifully when adjacent modules are also hexagons. This shape provides an organic, nature-inspired look to QR codes.

Example

>>> renderer = HexagonRenderer()
>>> hexagon = renderer.render(0, 0, 10, size_ratio=0.95)
>>> # Creates a hexagon slightly smaller than the module
shape_names: List[str] = ['hexagon']
render(x, y, size, **kwargs)[source]

Render a hexagon shape module.

Parameters:
  • x (float) – X coordinate of the module’s top-left corner

  • y (float) – Y coordinate of the module’s top-left corner

  • size (float) – Module size

  • **kwargs (Any) – Additional parameters including: size_ratio: Hexagon size relative to module (default: 0.9) css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID

Returns:

SVG polygon element forming a regular hexagon

Return type:

ET.Element

class segnomms.shapes.basic.CrossRenderer[source]

Bases: BaseShapeRenderer

Renders cross (plus sign) shaped modules.

Creates cross or plus sign shapes that can vary in thickness and style. Supports both uniform width crosses and tapered crosses for a sharper appearance. This shape adds a technical, precise feel to QR codes.

Example

>>> renderer = CrossRenderer()
>>> cross = renderer.render(0, 0, 10, thickness=0.25, sharp=True)
>>> # Creates a sharp cross with tapered arms
shape_names: List[str] = ['cross']
render(x, y, size, **kwargs)[source]

Render a cross shape module.

Parameters:
  • x (float) – X coordinate of the module’s top-left corner

  • y (float) – Y coordinate of the module’s top-left corner

  • size (float) – Module size

  • **kwargs (Any) – Additional parameters including: thickness: Cross arm thickness ratio (default: 0.2) sharp: Use tapered arms for sharper look (default: False) css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID

Returns:

SVG path element forming a cross

Return type:

ET.Element

class segnomms.shapes.basic.SquircleRenderer[source]

Bases: BaseShapeRenderer

Renders superellipse (squircle) shaped QR code modules.

A squircle is a mathematical shape that’s between a square and a circle, providing a modern, smooth appearance while maintaining good scannability. The shape is defined by the superellipse equation with n=4.

Example

>>> renderer = SquircleRenderer()
>>> squircle = renderer.render(0, 0, 10)
>>> # Creates a 10x10 squircle at position (0,0)
shape_names: List[str] = ['squircle']
render(x, y, size, **kwargs)[source]

Render a squircle module.

Parameters:
  • x (float) – X coordinate of the top-left corner

  • y (float) – Y coordinate of the top-left corner

  • size (float) – Width and height of the module

  • **kwargs (Any) – Additional parameters including: css_class: CSS class for styling (default: ‘qr-module’) id: Optional element ID corner_radius: Override corner radius (0.0-1.0)

Returns:

SVG path element forming a squircle

Return type:

ET.Element

Connected Shapes

Connected shape renderers that create fluid, context-aware QR code modules.

These renderers analyze neighboring modules to create shapes that connect smoothly, inspired by qr-code-styling’s advanced rendering techniques.

The connected renderers use neighbor analysis to determine the appropriate shape for each module, creating smooth transitions and organic patterns.

Available connected renderers:

  • ConnectedRoundedRenderer: Basic connected style with rounded corners

  • ConnectedExtraRoundedRenderer: Extra smooth curves using quadratic beziers

  • AdvancedClassyRenderer: Boundary-focused styling with strategic rounding

  • AdvancedClassyRoundedRenderer: Classy style with extra-rounded corners

class segnomms.shapes.connected.Corner(*values)[source]

Bases: Enum

Enumeration for corner positions.

Used to specify which corner of a module should be rounded.

TOP_LEFT = 1
TOP_RIGHT = 2
BOTTOM_LEFT = 3
BOTTOM_RIGHT = 4
class segnomms.shapes.connected.Side(*values)[source]

Bases: Enum

Enumeration for side positions.

Used to specify which side of a module should be rounded.

TOP = 1
BOTTOM = 2
LEFT = 3
RIGHT = 4
class segnomms.shapes.connected.ConnectedRoundedRenderer[source]

Bases: ShapeRenderer

Renders modules that connect to their neighbors with rounded corners.

Creates fluid, organic-looking QR codes by analyzing module context. The renderer determines the appropriate shape based on the number and position of neighboring dark modules.

Shape selection logic:

  • 0 neighbors: Isolated dot

  • 1 neighbor: Rounded end cap

  • 2 neighbors (line): Straight module

  • 2 neighbors (corner): Rounded corner

  • 3+ neighbors: Straight module

render(x, y, size, **kwargs)[source]

Render a connected module based on its neighbors.

Parameters:
  • x (float) – X coordinate of module

  • y (float) – Y coordinate of module

  • size (float) – Module size in pixels

  • **kwargs (Any) – Additional parameters including: get_neighbor: Function to check neighbor existence css_class: CSS class for the element id: Optional element ID

Returns:

SVG element representing the module

Return type:

ET.Element

Note

Requires a ‘get_neighbor’ function in kwargs that returns whether a neighbor exists at the given offset (dx, dy).

supports_type(shape_type)[source]

Check if this renderer supports the given shape type.

Return type:

bool

Parameters:

shape_type (str)

class segnomms.shapes.connected.ConnectedExtraRoundedRenderer[source]

Bases: ConnectedRoundedRenderer

Renders modules with extra rounded corners for a softer appearance.

Similar to ConnectedRoundedRenderer but with more pronounced curves using quadratic Bezier curves instead of circular arcs.

Key differences from ConnectedRoundedRenderer:

  • Smaller isolated dots (0.375 vs 0.5 radius)

  • Quadratic Bezier curves for ultra-smooth corners

  • Full-size radius for side rounding

  • More organic, flowing appearance

Example

>>> renderer = ConnectedExtraRoundedRenderer()
>>> # Requires get_neighbor function
>>> element = renderer.render(0, 0, 10, get_neighbor=neighbor_func)
supports_type(shape_type)[source]

Check if this renderer supports the given shape type.

Return type:

bool

Parameters:

shape_type (str)

class segnomms.shapes.connected.AdvancedClassyRenderer[source]

Bases: ConnectedRoundedRenderer

Renders modules with advanced classy style focusing on shape boundaries.

This renderer implements a sophisticated boundary detection algorithm that only rounds specific corners of QR code shapes, creating a distinctive “classy” appearance.

The renderer follows these rules:

  1. Isolated modules: Get jewel-like appearance with opposite corners rounded

  2. Top-left outer corners: Modules with no neighbors above or left

  3. Bottom-right outer corners: Modules with no neighbors below or right

  4. All other modules: Rendered as solid squares

This creates an elegant look where only the outer boundaries of shapes have rounded corners, while internal modules remain square for stability.

Example

>>> renderer = AdvancedClassyRenderer()
>>> # Requires get_neighbor function
>>> element = renderer.render(0, 0, 10, get_neighbor=neighbor_func)

Note

Based on the TypeScript QRDot.ts _drawClassy logic from qr-code-styling.

render(x, y, size, **kwargs)[source]

Render a module using classy boundary rounding rules.

Applies rounded corners only on outer boundaries based on neighbor states to achieve a refined “classy” look.

Parameters:
  • x (float) – X coordinate in pixels.

  • y (float) – Y coordinate in pixels.

  • size (float) – Module size in pixels.

  • **kwargs (Any) –

    Additional rendering parameters. Recognized keys: - get_neighbor: Callable(dx, dy) -> bool indicating whether a

    neighbor exists at the given offset relative to the current module.

Return type:

Element

Returns:

ET.Element representing the rendered module.

supports_type(shape_type)[source]

Check if this renderer supports the given shape type.

Return type:

bool

Parameters:

shape_type (str)

class segnomms.shapes.connected.AdvancedClassyRoundedRenderer[source]

Bases: ConnectedExtraRoundedRenderer

Renders modules with classy rounded style using ultra-smooth curves.

Combines the boundary detection logic of AdvancedClassyRenderer with the extra-rounded drawing methods of ConnectedExtraRoundedRenderer.

Key features:

  • Same boundary detection rules as AdvancedClassyRenderer

  • Uses quadratic Bezier curves instead of circular arcs

  • Creates softer, more organic appearance

  • Isolated modules get jewel-like shapes with Bezier curves

The result is a highly polished look with smooth boundaries and flowing curves that enhance the QR code’s visual appeal.

Example

>>> renderer = AdvancedClassyRoundedRenderer()
>>> # Creates ultra-smooth classy style
>>> element = renderer.render(0, 0, 10, get_neighbor=neighbor_func)
render(x, y, size, **kwargs)[source]

Render a module using ultra-smooth classy rounding (Bezier curves).

Uses the same boundary detection rules as AdvancedClassyRenderer but renders with quadratic Bezier curves for softer transitions.

Parameters:
  • x (float) – X coordinate in pixels.

  • y (float) – Y coordinate in pixels.

  • size (float) – Module size in pixels.

  • **kwargs (Any) –

    Additional rendering parameters. Recognized keys: - get_neighbor: Callable(dx, dy) -> bool indicating whether a

    neighbor exists at the given offset relative to the current module.

Return type:

Element

Returns:

ET.Element representing the rendered module.

supports_type(shape_type)[source]

Check if this renderer supports the given shape type.

Return type:

bool

Parameters:

shape_type (str)

Shape Interface

All shape renderers implement the following interface:

class segnomms.core.interfaces.ShapeRenderer[source]

Bases: ABC

Interface for shape rendering implementations.

All shape renderers must implement this interface to ensure compatibility with the rendering pipeline.

Implementations should:

  1. Create SVG elements for individual modules

  2. Support configuration through kwargs

  3. Declare which shape types they handle

abstractmethod render(x, y, size, **kwargs)[source]

Render a shape at the specified position.

Parameters:
  • x (float) – X coordinate

  • y (float) – Y coordinate

  • size (float) – Size of the shape

  • **kwargs (Any) – Additional rendering parameters

Return type:

Element

Returns:

SVG element representing the rendered shape

abstractmethod supports_type(shape_type)[source]

Check if this renderer supports the given shape type.

Parameters:

shape_type (str) – Name of the shape type

Return type:

bool

Returns:

True if this renderer can handle the shape type

Creating Custom Shapes

To create a custom shape, inherit from ShapeRenderer:

from segnomms.core.interfaces import ShapeRenderer
import xml.etree.ElementTree as ET

class MyCustomShape(ShapeRenderer):
    def render(self, x, y, size, **kwargs):
        # Create and return an SVG element
        return ET.Element('rect', {
            'x': str(x),
            'y': str(y),
            'width': str(size),
            'height': str(size),
            'rx': str(size * 0.3)
        })

    def supports_type(self, shape_type):
        return shape_type == 'my-custom'

# Register the shape
from segnomms import register_custom_renderer
register_custom_renderer('my-custom', MyCustomShape)