zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils module

SVG triangle detection and elongation utilities.

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils._load_svg_tree(svg_input)[source]

Load SVG XML tree from either file path or cache hash.

Parameters:

svg_input – Either a file path or cache hash (starting with 'svg_')

Returns:

ElementTree object

Raises:
  • FileNotFoundError – If file doesn’t exist

  • ValueError – If cache hash not found

  • ET.ParseError – If XML parsing fails

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils._create_backup(svg_path)[source]

Create a backup copy of the SVG file.

Returns:

Path to backup file or None on failure

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils._restore_from_backup(svg_path, backup_path)[source]

Restore SVG file from backup.

Returns:

True if successful, False otherwise

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils._cleanup_backup(backup_path)[source]

Remove backup file if it exists.

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils._parse_polygon_points(points_str)[source]

Parse SVG polygon points string into list of (x,y) tuples.

Parameters:

points_str – SVG polygon points attribute value

Returns:

List of (x, y) coordinate tuples

Raises:

ValueError – If points string is malformed

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils._calculate_triangle_centroid(points)[source]

Calculate triangle centroid (center of mass).

Parameters:

points – List of 3 (x, y) coordinate tuples

Returns:

(centroid_x, centroid_y) tuple

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils._scale_points_from_center(points, center, scale_x, scale_y)[source]

Scale points relative to center with separate X/Y scaling.

Parameters:
  • points – List of (x, y) coordinate tuples

  • center – (center_x, center_y) tuple

  • scale_x – X-axis scaling factor

  • scale_y – Y-axis scaling factor

Returns:

List of scaled (x, y) coordinate tuples

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils.is_triangle_svg(svg_path)[source]

Check if SVG contains a single triangle polygon element.

Returns:

True if SVG contains exactly one <polygon> element with 3 points, False otherwise

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils.get_triangle_bounds(svg_path)[source]

Get triangle bounds: (min_x, min_y, width, height).

Returns:

Tuple of (min_x, min_y, width, height) or None if not a triangle

zooui.objects.mediaobjects.mediaobjectsutils.svg.utils.svgtriangleutils.elongate_triangle(svg_path, scale_x, scale_y)[source]

Elongate triangle by scaling from center with separate X/Y scaling.

Stores modified SVG in cache and returns cache hash.

Parameters:
  • svg_path – Path to SVG file (will be read but not modified)

  • scale_x – Multiplier for X-axis (minimum 0.2)

  • scale_y – Multiplier for Y-axis (minimum 0.2)

Returns:

svg_{8_char_hex})

Return type:

Cache hash of modified SVG (format

Raises:
  • ValueError – If scale_x < 0.2 or scale_y < 0.2

  • Exception – If SVG parsing or modification fails

See Also

  • zooui/objects/mediaobjects/svgmediaobject - SVGMediaObject class

  • zooui/objects/mediaobjects/mediaobjectsutils/svg/svgcache/svgcache - SVG caching system