Skip to content

Prototile validity

isotile.check_prototile

check_prototile(
    tiling_type: int | TilingType,
    parameters: ArrayLike | None = None,
    *,
    edge_curves: Mapping[int, ArrayLike] | None = None,
    edge_curve_modes: Mapping[int, str] | None = None,
) -> PrototileReport

Report whether the prototile of a type at the given parameters, and with edge curves, is valid.

The straight prototile is valid when it is a simple polygon with nonzero edge lengths and area. With edge_curves the outline with the edges replaced by their curves must in addition be a simple closed curve with positive area, and parts of it that are not directly consecutive must be at least 1e-6 times the diameter of the outline apart (the larger side of its bounding box); touching or nearly touching curves are invalid. The edge shapes make the copies fit along the shared edges, so this is the complete condition. The test is exact for the curve (a spline is tested as its cubic pieces, see interpolate), so it does not depend on the number of samples used to draw the outline. In the report of a curved outline, bad_edges are the edges whose curves cross, touch, come closer than the clearance, fold back (turn by 180 degrees or more) or have zero length.

This is the test the IsohedralTiling constructor applies; it builds no tiling, so an editor can call it for every intermediate state. The prototile is checked in the type's native coordinates (a frame does not change validity).

Parameters:

  • tiling_type (int or TilingType) –
  • parameters (array - like, default: None ) –

    n_params values; the defaults when omitted.

  • edge_curves (mapping of int to (m, 2) array-like, default: None ) –

    Curve control points for edge shape ids, as in IsohedralTiling. The symmetry of the shape is enforced before the test.

  • edge_curve_modes (mapping of int to str, default: None ) –

    "spline" (default) or "linear" per shape id.

Raises:

  • ValueError –

    If the type number is invalid, the number of parameters is wrong, or the curves are malformed (a shape id that does not exist or is an I edge, a mode without a curve, points that are not a finite array of shape (m, 2) or do not run from (0, 0) to (1, 0)). Curves that are well formed but make the outline invalid are reported, not raised.

isotile.PrototileReport dataclass

PrototileReport(
    valid: bool, bad_edges: tuple[int, ...], message: str
)

Result of check_prototile.

Attributes:

  • valid (bool) –

    True if the straight prototile is a simple polygon with nonzero edge lengths and area and, when edge curves are checked, its outline with the curves is a simple closed curve with positive area whose non-consecutive parts are at least 1e-6 times its diameter apart.

  • bad_edges (tuple of int) –

    Sorted indices of the edges at fault (edge i joins vertex i to vertex i + 1): zero-length edges, edges of every pair that crosses or touches without being neighbors, and neighboring edges that fold back onto each other. All edges when the polygon has zero area without another fault. Empty if valid.

  • message (str) –

    Description of the problem; "valid" if there is none.

isotile.InvalidPrototileError

InvalidPrototileError(
    message: str, report: PrototileReport
)

Bases: ValueError

A prototile that is not valid, see check_prototile.

Raised by the IsohedralTiling constructor, with_parameters, with_edge_curves and the parameters setter. It is a ValueError.

Attributes:

  • report (PrototileReport) –

    The report of the check; report.bad_edges are the edges at fault.