or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-objects.mdindex.mdufo-tools.md
tile.json

tessl/pypi-mutator-math

Python library for piecewise linear interpolation in multiple dimensions with multiple, arbitrarily placed, masters.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/mutatormath@2.1.x

To install, run

npx @tessl/cli install tessl/pypi-mutator-math@2.1.0

index.mddocs/

MutatorMath

MutatorMath is a Python library that provides advanced mathematical tools for piecewise linear interpolation in n-dimensional design spaces with any number of masters. Originally developed for font interpolation, it can handle any arithmetic objects that support basic mathematical operations. The library enables complex interpolation scenarios including on-axis and off-axis calculations, anisotropic coordinates, and multi-dimensional design spaces with named axes.

Package Information

  • Package Name: MutatorMath
  • Package Type: pypi
  • Language: Python
  • Installation: pip install MutatorMath
  • Dependencies: fonttools>=3.32.0, defcon>=0.3.5, fontMath>=0.4.8

Core Imports

from mutatorMath import Location, Mutator

For advanced functionality:

from mutatorMath.objects.location import Location
from mutatorMath.objects.mutator import Mutator, buildMutator
from mutatorMath.objects.bender import Bender

Basic Usage

from mutatorMath import Location, Mutator
from mutatorMath.objects.mutator import buildMutator

# Create locations in design space
master1_loc = Location(weight=100, width=75)
master2_loc = Location(weight=900, width=75) 
master3_loc = Location(weight=100, width=125)
master4_loc = Location(weight=900, width=125)

# Create sample objects (can be any arithmetic objects)
master1_obj = 50    # thin, narrow
master2_obj = 200   # bold, narrow  
master3_obj = 60    # thin, wide
master4_obj = 180   # bold, wide

# Build mutator from (location, object) pairs
items = [
    (master1_loc, master1_obj),
    (master2_loc, master2_obj), 
    (master3_loc, master3_obj),
    (master4_loc, master4_obj)
]

bias, mutator = buildMutator(items)

# Interpolate at any location in design space
target = Location(weight=500, width=100)
result = mutator.makeInstance(target)
print(result)  # Interpolated value

Architecture

MutatorMath is organized into two main subpackages:

  • objects: General calculation tools for location-based interpolation that work with any arithmetic objects
  • ufo: Specialized tools for processing UFO (Unified Font Object) data with designspace document support

The core design uses Location objects to represent n-dimensional coordinates and Mutator objects to perform interpolation calculations based on master-instance relationships.

Capabilities

Core Objects

Foundation classes for multi-dimensional interpolation including Location objects for coordinate representation, Mutator objects for interpolation calculations, and Bender objects for non-linear transformations.

class Location(dict):
    """N-dimensional location object with arithmetic operations."""
    def __init__(self, **kwargs): ...
    def isOrigin(self) -> bool: ...
    def expand(self, other): ...

class Mutator(dict):
    """Main interpolation class for calculating instances from masters."""
    def __init__(self): ...
    def makeInstance(self, location) -> any: ...
    def setNeutral(self, obj): ...
    def setBias(self, location): ...

def buildMutator(items, axes=None, bias=None) -> tuple[Location, Mutator]:
    """Build a mutator with (location, obj) pairs. Returns (bias, mutator) tuple."""

class Bender(object):
    """Non-linear transformation object for warping design spaces."""
    def __init__(self, axes): ...
    def __call__(self, location) -> Location: ...

Core Objects

UFO Tools

Specialized tools for font interpolation including designspace document processing, UFO instance generation, and XML-based design space descriptions.

def build(documentPath, outputUFOFormatVersion=2, roundGeometry=True, 
          verbose=True, logPath=None, progressFunc=None) -> list:
    """Simple builder for UFO designspaces."""

class DesignSpaceDocumentWriter(object):
    """Writer for designspace XML documents."""
    def __init__(self, path, toolVersion=3, verbose=False): ...
    def save(self, pretty=True): ...

class DesignSpaceDocumentReader(object):
    """Reader and processor for designspace XML documents."""
    def __init__(self, path, ufoVersion=2, roundGeometry=True, 
                 verbose=True, logPath=None, progressFunc=None): ...
    def process(self): ...

UFO Tools

Types

class MutatorError(Exception):
    """Exception class for MutatorMath-specific errors."""
    def __init__(self, msg, obj=None): ...