The FOLD API consists of several modules under the FOLD namespace:
FOLD.viewer: Visualize FOLD format in browser in SVGFOLD.filter: Select existing parts of, or compute new features of, a given FOLD object.FOLD.convert: Augment an existing FOLD object with additional fields, and convert between FOLD and other file formats.FOLD.file: Load/save/convert files on file system (Node only, not browser)FOLD.geom: Basic geometry tools (manipulation of vectors, angles, lines, segments, etc.). Basically whatever we needed to implement other features, but which you might find helpful too.
See source code for details.
These operations all modify a FOLD object in-place. See source code for details.
FOLD.filter.subdivideCrossingEdges_vertices(fold, epsilon): Given a FOLD object with 2Dvertices_coordsandedges_vertices, subdivides all crossing/touching edges to form a planar graph. All duplicate and loop edges are also removed.FOLD.filter.maybeAddVertex(fold, coords, epsilon): Given a FOLD object withvertices_coords, adds a new vertex with coordinatescoordsand returns its (last) index, unless there is already such a vertex within distanceepsilon, in which case return the closest such vertex's index. The new vertex has no new properties exceptvertex_coords.FOLD.filter.addVertexAndSubdivide(fold, coords, epsilon): Given a FOLD object with 2Dvertices_coordsandedges_vertices, maybe adds a new vertex likeFOLD.filter.maybeAddVertex, and then subdivides if necessary (via an efficient use ofFOLD.filter.subdivideCrossingEdges_vertices).FOLD.filter.addVertexLike(fold, oldVertexIndex): Given a FOLD object, adds a new vertex and copy allvertex_...attributes to be like the existing vertexoldVertexIndex. Returns the new vertex index.FOLD.filter.addEdgeLike(fold, oldEdgeIndex, [v1, v2]): Given a FOLD object withedges_vertices, adds a new edge connecting verticesv1andv2, and copy all otheredges_...attributes to be like the existing edgeoldEdgeIndex. Returns the new edge index. Ifv1and/orv2are unspecified, the new edge inherits the same vertex connections as the old edge.FOLD.filter.addEdgeAndSubdivide(fold, v1, v2, epsilon): Given a FOLD object with 2Dvertices_coordsandedges_vertices, adds an edge between vertex indices or pointsv1andv2(callingFOLD.filter.addVertexAndSubdividewhen they are points), subdividing if necessary (via an efficient use ofFOLD.filter.subdivideCrossingEdges_vertices). Returns two arrays: one with the indices of all the subdivided parts of the added edge, and the other with the indices of all other changed edges. The new edge(s) have no properties exceptedges_vertices, so the first array tells you which edges to set the properties of. If the edge is a loop, the returned arrays are empty. If the edge is a duplicate, the first array has the old edge index and the second array is empty.FOLD.filter.cutEdges(fold, es): Given a FOLD object withedges_vertices,edges_assignment, and counterclockwise-sortedvertices_edges(seeFOLD.convert.edges_vertices_to_vertices_edges_sorted), cuts apart ("unwelds") all edges inesinto pairs of boundary edges. When an endpoint of a cut edge ends up on n boundaries, it splits into n vertices. Preserves above-mentioned properties (so you can then compute faces viaFOLD.convert.edges_vertices_to_faces_vertices_edges), but ignores face properties and discardsvertices_verticesif present.FOLD.filter.transform(fold, matrix): Transforms a FOLD object by a given transformationmatrix(generated byFOLD.geom.matrix...), in particular transformingvertices_coords(and any fields ending in_coords) andfaces_flatFoldTransform(and any fields ending inFoldTransform).
See source code for details.
FOLD.convert.edges_vertices_to_vertices_vertices_unsorted(fold): Given a FOLD object withedges_verticesproperty (defining edge endpoints), automatically computes thevertices_verticesproperty. However, note that thevertices_verticesarrays will not be sorted in counterclockwise order.FOLD.convert.edges_vertices_to_vertices_vertices_sorted(fold): Given a FOLD object with 2Dvertices_coordsandedges_verticesproperty (defining edge endpoints), automatically computes thevertices_verticesproperty and sorts them counterclockwise by angle in the plane.FOLD.convert.edges_vertices_to_vertices_edges_sorted(fold): Given a FOLD object with 2Dvertices_coordsandedges_verticesproperty (defining edge endpoints), automatically computes thevertices_edgesandvertices_verticesproperty and sorts them counterclockwise by angle in the plane.FOLD.convert.sort_vertices_vertices(fold): Given a FOLD object with 2Dvertices_coordsandvertices_verticesproperties, sorts eachvertices_verticesarray in counterclockwise order around the vertex in the plane.FOLD.convert.vertices_vertices_to_faces_vertices(fold): Given a FOLD object with counterclockwise-sortedvertices_verticesproperty, constructs the implicitly defined faces, settingfaces_verticesproperty.FOLD.convert.vertices_edges_to_faces_vertices_edges(fold): Given a FOLD object with counterclockwise-sortedvertices_edgesproperty, constructs the implicitly defined faces, setting bothfaces_verticesandfaces_edgesproperties. Handles multiple edges to the same vertex (unlikeFOLD.convert.vertices_vertices_to_faces_vertices).FOLD.convert.edges_vertices_to_faces_vertices(fold): Given a FOLD object with 2Dvertices_coordsandedges_vertices, computes a counterclockwise-sortedvertices_verticesproperty and constructs the implicitly defined faces, settingfaces_verticesproperty.FOLD.convert.edges_vertices_to_faces_vertices_edges(fold): Given a FOLD object with 2Dvertices_coordsandedges_vertices, computes counterclockwise-sortedvertices_verticesandvertices_edgesproperties and constructs the implicitly defined faces, setting bothfaces_verticesandfaces_edgesproperty.FOLD.convert.vertices_vertices_to_vertices_edges(fold): Given a FOLD object withvertices_verticesandedges_vertices, fills in the correspondingvertices_edgesproperty (preserving order).FOLD.convert.faces_vertices_to_faces_edges(fold): Given a FOLD object withfaces_verticesandedges_vertices, fills in the correspondingfaces_edgesproperty (preserving order).FOLD.convert.faces_vertices_to_edges(fold): Given a FOLD object with justfaces_vertices, automatically fills inedges_vertices,edges_faces,faces_edges, andedges_assignment.
Basic fold/JSON conversion:
FOLD.convert.toJSON(fold): Given a FOLD object, convert into a nicely formatted JSON string.FOLD.convert.deepCopy(fold): Given a FOLD object, make a copy that shares no pointers with the original.
File format conversion (supported formats are "fold" and "opx"):
FOLD.convert.convertFromTo(data, fromFormat, toFormat): Convert the specified data from one format to another.FOLD.convert.convertFrom(data, fromFormat): Convert the specified data from one format to FOLD.FOLD.convert.convertTo(data, toFormat): Convert the specified data from FOLD to another format.- The
FOLD.convert.oripasubmodule implements the conversion between FOLD and ORIPA.opxformat. See source code for details.
See source code for details.
The following functions are available in Node only, not in the browser (where filenames don't really make sense).
FOLD.file.toFile(fold, filename): Save FOLD object to specified filename, which can end in a supported extension (.foldor.opx).FOLD.file.fileToFile(inFilename, outFilename): Convert one filename to another, using extensions to determine format. Alternatively,outFilenamecan be just an extension, in which case it will be combined withinFilenameto form a full filename.
See source code for details.
See source code for details.