edemaine / fold

FOLD file format for origami models, crease patterns, etc.
MIT License
313 stars 48 forks source link

FOLD typescript definition #49

Closed mayakraft closed 5 months ago

mayakraft commented 5 months ago

Hello! Would you like a type definition for the FOLD format itself? This is not exactly #25 or #45, nothing to do with the API, only a type definition for a FOLD object. I imagine it could live inside of its own file, like fold.d.ts? Or, feel free to use it in any way you like!

I think this is valid for versions 1.2 and 1.1, but not 1.0.

The logic behind this structure arises from how a FOLD object can contain itself in file_frames. FOLD is the intended export. FOLDFrame is the intersection of the inner and top level frames, then the inner frames and top level frame contain inheritance info and file_ keys respectively.

fold.d.ts

type FOLDFrame = {
    frame_author?: string;
    frame_title?: string;
    frame_description?: string;
    frame_classes?: string[];
    frame_attributes?: string[];
    frame_unit?: string;
    vertices_coords?: [number, number][] | [number, number, number][];
    vertices_vertices?: number[][];
    vertices_edges?: number[][];
    vertices_faces?: (number | null | undefined)[][];
    edges_vertices?: [number, number][];
    edges_faces?: (number | null | undefined)[][];
    edges_assignment?: string[];
    edges_foldAngle?: number[];
    edges_length?: number[];
    faces_vertices?: number[][];
    faces_edges?: number[][];
    faces_faces?: (number | null | undefined)[][];
    faceOrders?: [number, number, number][];
    edgeOrders?: [number, number, number][];
};

type FOLDChildFrame = FOLDFrame & {
    frame_parent?: number;
    frame_inherit?: boolean;
};

type FOLD = FOLDFrame & {
    file_spec?: number;
    file_creator?: string;
    file_author?: string;
    file_title?: string;
    file_description?: string;
    file_classes?: string[];
    file_frames?: FOLDChildFrame[];
};
edemaine commented 5 months ago

Thank you! There is a definition along these lines in #47 which I really need to finish reviewing; I'll diff against this one. I agree it'll be nice to get a type definition in the exports.

mayakraft commented 5 months ago

sounds great :) also, somebody ported it! very happy to see. I'll close this then so as not to clutter.