Skip to content

Commit

Permalink
filter.splitCuts splits "C" edges into "B" edges (fix #46)
Browse files Browse the repository at this point in the history
* Renamed from `filter.cutEdges`.
* New default of cutting all edges assigned `"C"`.
* `filter.cutEdges` and `filter.joinEdges` now return arrays of all
  edges assigned `"C"` and `"B"` respectively.
  • Loading branch information
edemaine committed Jun 25, 2023
1 parent ae2c183 commit 15eb75e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
15 changes: 14 additions & 1 deletion dist/fold.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ convert.faces_vertices_to_edges = function(mesh) {
Given a FOLD object with just `faces_vertices`, automatically fills in
`edges_vertices`, `edges_faces`, `faces_edges`, and `edges_assignment`
(indicating which edges are boundary with 'B').
This code currently assumes an orientable manifold, and uses nulls to
represent missing neighbor faces in `edges_faces` (for boundary edges).
*/
mesh.edges_vertices = [];
mesh.edges_faces = [];
Expand Down Expand Up @@ -676,6 +678,14 @@ filter.unassignedEdges = function(fold) {
return filter.edgesAssigned(fold, 'U');
};

filter.cutEdges = function(fold) {
return filter.edgesAssigned(fold, 'C');
};

filter.joinEdges = function(fold) {
return filter.edgesAssigned(fold, 'J');
};

filter.keysStartingWith = function(fold, prefix) {
var key, results;
results = [];
Expand Down Expand Up @@ -1306,7 +1316,7 @@ filter.addEdgeAndSubdivide = function(fold, v1, v2, epsilon) {
return changedEdges;
};

filter.cutEdges = function(fold, es) {
filter.splitCuts = function(fold, es = filter.cutEdges(fold)) {
var b, b1, b2, boundaries, e, e1, e2, ev, i, i1, i2, ie, ie1, ie2, k, l, len, len1, len2, len3, len4, len5, len6, len7, len8, m, n, neighbor, neighbors, o, q, r, ref, ref1, ref10, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, t, u1, u2, v, v1, v2, ve, vertices_boundaries, z;
if (!es.length) {
/*
Expand All @@ -1320,6 +1330,9 @@ filter.cutEdges = function(fold, es) {
`FOLD.convert.edges_vertices_to_faces_vertices_edges`),
and recomputes `vertices_vertices` if present,
but ignores face properties.
`es` 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.
*/
return fold;
}
Expand Down
5 changes: 4 additions & 1 deletion doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ for details.
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)`:
* `FOLD.filter.splitCuts(fold, [es])`:
Given a FOLD object with `edges_vertices`, `edges_assignment`, and
counterclockwise-sorted `vertices_edges`
(see `FOLD.convert.edges_vertices_to_vertices_edges_sorted`),
Expand All @@ -72,6 +72,9 @@ for details.
`FOLD.convert.edges_vertices_to_faces_vertices_edges`),
and recomputes `vertices_vertices` if present,
but ignores face properties.
If `es` 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 transformation `matrix` (generated by
`FOLD.geom.matrix...`), in particular transforming `vertices_coords`
Expand Down
9 changes: 8 additions & 1 deletion src/filter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ filter.boundaryEdges = (fold) ->
filter.edgesAssigned fold, 'B'
filter.unassignedEdges = (fold) ->
filter.edgesAssigned fold, 'U'
filter.cutEdges = (fold) ->
filter.edgesAssigned fold, 'C'
filter.joinEdges = (fold) ->
filter.edgesAssigned fold, 'J'

filter.keysStartingWith = (fold, prefix) ->
key for key of fold when key[...prefix.length] == prefix
Expand Down Expand Up @@ -338,7 +342,7 @@ filter.addEdgeAndSubdivide = (fold, v1, v2, epsilon) ->
changedEdges[1].push changedEdges2... if changedEdges2?
changedEdges

filter.cutEdges = (fold, es) ->
filter.splitCuts = (fold, es = filter.cutEdges(fold)) ->
###
Given a FOLD object with `edges_vertices`, `edges_assignment`, and
counterclockwise-sorted `vertices_edges`
Expand All @@ -350,6 +354,9 @@ filter.cutEdges = (fold, es) ->
`FOLD.convert.edges_vertices_to_faces_vertices_edges`),
and recomputes `vertices_vertices` if present,
but ignores face properties.
`es` 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.
###
return fold unless es.length
## Maintain map from every vertex to array of incident boundary edges
Expand Down

0 comments on commit 15eb75e

Please sign in to comment.