Interface ContextGeometryUtils

Utility methods for geometric calculations in Penpot.

const centerPoint = geometryUtils.center(shapes);
console.log(centerPoint);
interface ContextGeometryUtils {
    center(shapes: Shape[]): null | {
        x: number;
        y: number;
    };
}

Methods

Methods

  • Calculates the center point of a given array of shapes. This method computes the geometric center (centroid) of the bounding boxes of the provided shapes.

    Parameters

    • shapes: Shape[]

      The array of shapes to calculate the center for.

    Returns null | {
        x: number;
        y: number;
    }

    Returns the center point as an object with x and y coordinates, or null if the array is empty.

    const centerPoint = geometryUtils.center(shapes);
    console.log(centerPoint);