Repository: pixijs/pixijs
File: src/scene/graphics/shared/utils/buildGeometryFromPath.ts (TypeScript)

Code before:
import { buildSimpleUvs, buildUvs } from '../../../../rendering/renderers/shared/geometry/utils/buildUvs';
import { transformVertices } from '../../../../rendering/renderers/shared/geometry/utils/transformVertices';
import { MeshGeometry } from '../../../mesh/shared/MeshGeometry';
import { buildCircle } from '../buildCommands/buildCircle';
import { buildPolygon } from '../buildCommands/buildPolygon';
import { buildRectangle } from '../buildCommands/buildRectangle';
import { buildTriangle } from '../buildCommands/buildTriangle';
import { GraphicsPath } from '../path/GraphicsPath';

import type { Matrix } from '../../../../maths/matrix/Matrix';
import type { ShapeBuildCommand } from '../buildCommands/ShapeBuildCommand';

const buildMap: Record<string, ShapeBuildCommand> = {
    rectangle: buildRectangle,
    polygon: buildPolygon,
    triangle: buildTriangle,
    circle: buildCircle,
    ellipse: buildCircle,
    roundedRectangle: buildCircle,
};

/**
 * Options for building geometry from a graphics path.
 * Provides a possibility to specify a transformation Matrix for the texture's UVs and output mesh geometry.
 * @example
 * ```ts
 * const options: GeometryPathOptions = {
 *     path: new GraphicsPath().rect(0, 0, 64, 64),
 *     textureMatrix: new Matrix()
 *         .scale(2, 2)
 *         .rotate(Math.PI / 4),
 *     out: meshGeometry
 * };
 * const geometry:MeshGeometry = buildGeometryFromPath(options);
 * const mesh = new Mesh({
 *     geometry: meshGeometry,
 *     texture: bunnyTexture
 * });
 * ```
 * @category scene
 * @advanced
 */
export interface GeometryPathOptions
{
    /** the path to build the geometry from */

Review comment (performance):
I think we need to use `shapeBuilders` from [here](https://github.com/pixijs/pixijs/blob/cd6b0d28877bcbd240760eb5f447c93291acfa6d/src/scene/graphics/shared/utils/buildContextBatches.ts#L31) as users can create there own shape command

Code after:
import { buildSimpleUvs, buildUvs } from '../../../../rendering/renderers/shared/geometry/utils/buildUvs';
import { transformVertices } from '../../../../rendering/renderers/shared/geometry/utils/transformVertices';
import { MeshGeometry } from '../../../mesh/shared/MeshGeometry';
import { GraphicsPath } from '../path/GraphicsPath';
import { shapeBuilders } from './buildContextBatches';

import type { Matrix } from '../../../../maths/matrix/Matrix';

/**
 * Options for building geometry from a graphics path.
 * Provides a possibility to specify a transformation Matrix for the texture's UVs and output mesh geometry.
 * @example
 * ```ts
 * const options: GeometryPathOptions = {
 *     path: new GraphicsPath().rect(0, 0, 64, 64),
 *     textureMatrix: new Matrix()
 *         .scale(2, 2)
 *         .rotate(Math.PI / 4),
 *     out: meshGeometry
 * };
 * const geometry:MeshGeometry = buildGeometryFromPath(options);
 * const mesh = new Mesh({
 *     geometry: meshGeometry,
 *     texture: bunnyTexture
 * });
 * ```
 * @category scene
 * @advanced
 */
export interface GeometryPathOptions
{
    /** the path to build the geometry from */
    path: GraphicsPath
    /** a `Matrix` that can be used to modify the texture UVs of the path being built */
    textureMatrix?: Matrix
    /** an optional `MeshGeometry` to write too instead of creating a new one*/
    out?: MeshGeometry
}

/**
 * When building a mesh, it helps to leverage the simple API we have in `GraphicsPath` as it can often be easier to
 * define the geometry in a more human-readable way. This function takes a `GraphicsPath` and returns a `MeshGeometry`.
 * @example
 * ```ts
 *