import { shape_to_type } from "./shape_to_type.js";
import { type_adapters } from "./type_adapters.js";

/**
 *
 * @param {AbstractShape3D} shape
 * @returns {Object}
 */
export function shape_to_json(shape) {
    const type = shape_to_type(shape);

    const adapter = type_adapters[type];

    if (adapter === undefined) {
        throw new Error(`Unsupported shape type '${type}'`);
    }

    const shape_json = adapter.write(shape);

    return Object.assign({ type }, shape_json);
}
