Ejemplo n.º 1
0
def stat(document: Document):
    """Print human-readable statistics on the current geometries."""

    print("========= Stats ========= ")
    print(f"Current page size: {document.page_size}")
    length_tot = 0.0
    pen_up_length_tot = 0.0
    for layer_id in sorted(document.layers.keys()):
        layer = document.layers[layer_id]
        length = layer.length()
        pen_up_length, pen_up_mean, pen_up_median = layer.pen_up_length()
        length_tot += length
        pen_up_length_tot += pen_up_length
        print(f"Layer {layer_id}")
        print(f"  Length: {length}")
        print(f"  Pen-up length: {pen_up_length}")
        print(f"  Total length: {length + pen_up_length}")
        print(f"  Mean pen-up length: {pen_up_mean}")
        print(f"  Median pen-up length: {pen_up_median}")
        print(f"  Path count: {len(layer)}")
        print(f"  Segment count: {layer.segment_count()}")
        print(
            f"  Mean segment length:",
            str(length /
                layer.segment_count() if layer.segment_count() else "n/a"),
        )
        print(f"  Bounds: {layer.bounds()}")
    print(f"Totals")
    print(f"  Layer count: {len(document.layers)}")
    print(f"  Length: {length_tot}")
    print(f"  Pen-up length: {pen_up_length_tot}")
    print(f"  Total length: {length_tot + pen_up_length_tot}")
    print(
        f"  Path count: {sum(len(layer) for layer in document.layers.values())}"
    )
    print(f"  Segment count: {document.segment_count()}")

    print(
        f"  Mean segment length:",
        str(length_tot /
            document.segment_count() if document.segment_count() else "n/a"),
    )
    print(f"  Bounds: {document.bounds()}")
    print("========================= ")

    return document
Ejemplo n.º 2
0
def _all_document_ops(doc: Document):
    doc.bounds()
    doc.length()
    doc.segment_count()