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_coords
andedges_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 coordinatescoords
and 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_coords
andedges_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 verticesv1
andv2
, and copy all otheredges_...
attributes to be like the existing edgeoldEdgeIndex
. Returns the new edge index. Ifv1
and/orv2
are 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_coords
andedges_vertices
, adds an edge between vertex indices or pointsv1
andv2
(callingFOLD.filter.addVertexAndSubdivide
when 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.splitCuts(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 ines
into 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
), and recomputesvertices_vertices
if present, but ignores face properties. Ifes
is unspecified, cuts all edges with an assignment of"C"
, effectively switching from FOLD 1.2's"C"
assignments to FOLD 1.1's"B"
assignments.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_vertices
property (defining edge endpoints), automatically computes thevertices_vertices
property. However, note that thevertices_vertices
arrays will not be sorted in counterclockwise order.FOLD.convert.edges_vertices_to_vertices_edges_unsorted(fold)
: Given a FOLD object withedges_vertices
property (defining edge endpoints), automatically computes the inversevertices_edges
property. However, note that thevertices_edges
arrays will not be sorted in counterclockwise order.FOLD.convert.edges_vertices_to_vertices_vertices_sorted(fold)
: Given a FOLD object with 2Dvertices_coords
andedges_vertices
property (defining edge endpoints), automatically computes thevertices_vertices
property and sorts them counterclockwise by angle in the plane.FOLD.convert.edges_vertices_to_vertices_edges_sorted(fold)
: Given a FOLD object with 2Dvertices_coords
andedges_vertices
property (defining edge endpoints), automatically computes thevertices_edges
andvertices_vertices
property and sorts them counterclockwise by angle in the plane.FOLD.convert.sort_vertices_vertices(fold)
: Given a FOLD object with 2Dvertices_coords
andvertices_vertices
properties, sorts eachvertices_vertices
array in counterclockwise order around the vertex in the plane.FOLD.convert.vertices_vertices_to_faces_vertices(fold)
: Given a FOLD object with counterclockwise-sortedvertices_vertices
property, constructs the implicitly defined faces, settingfaces_vertices
property.FOLD.convert.vertices_edges_to_faces_vertices_edges(fold)
: Given a FOLD object with counterclockwise-sortedvertices_edges
property, constructs the implicitly defined faces, setting bothfaces_vertices
andfaces_edges
properties. 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_coords
andedges_vertices
, computes a counterclockwise-sortedvertices_vertices
property and constructs the implicitly defined faces, settingfaces_vertices
property.FOLD.convert.edges_vertices_to_faces_vertices_edges(fold)
: Given a FOLD object with 2Dvertices_coords
andedges_vertices
, computes counterclockwise-sortedvertices_vertices
andvertices_edges
properties and constructs the implicitly defined faces, setting bothfaces_vertices
andfaces_edges
property.FOLD.convert.vertices_vertices_to_vertices_edges(fold)
: Given a FOLD object withvertices_vertices
andedges_vertices
, fills in the correspondingvertices_edges
property (preserving order).FOLD.convert.faces_vertices_to_faces_edges(fold)
: Given a FOLD object withfaces_vertices
andedges_vertices
, fills in the correspondingfaces_edges
property (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.oripa
submodule implements the conversion between FOLD and ORIPA.opx
format. 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 (.fold
or.opx
).FOLD.file.fileToFile(inFilename, outFilename)
: Convert one filename to another, using extensions to determine format. Alternatively,outFilename
can be just an extension, in which case it will be combined withinFilename
to form a full filename.
See source code for details.
See source code for details.