Comparing version 0.10.0 to 0.10.1
@@ -30,3 +30,3 @@ # FOLD API | ||
All duplicate and loop edges are also removed. | ||
* `FOLD.filter.addVertex(fold, coords, epsilon)`: | ||
* `FOLD.filter.maybeAddVertex(fold, coords, epsilon)`: | ||
Given a FOLD object with `vertices_coords`, adds a new vertex with | ||
@@ -37,6 +37,6 @@ coordinates `coords` and returns its (last) index, unless there is already | ||
`vertex_coords`. | ||
* `FOLD.filter.addEdge(fold, v1, v2, epsilon)`: | ||
* `FOLD.filter.addEdgeAndSubdivide(fold, v1, v2, epsilon)`: | ||
Given a FOLD object with `vertices_coords` and `edges_vertices`, | ||
adds an edge between vertex indices or points `v1` and `v2` | ||
(calling `FOLD.filter.addVertex` when they are points), | ||
(calling `FOLD.filter.maybeAddVertex` when they are points), | ||
subdividing if necessary (via an efficient use of | ||
@@ -43,0 +43,0 @@ `FOLD.filter.subdivideCrossingEdges_vertices`), |
@@ -130,3 +130,4 @@ var RepeatedPointsDS, filter, geom, | ||
})(); | ||
return filter.remapField(fold, field, old2new); | ||
filter.remapField(fold, field, old2new); | ||
return old2new; | ||
}; | ||
@@ -198,3 +199,4 @@ | ||
})(); | ||
return filter.remapField(fold, 'edges', old2new); | ||
filter.remapField(fold, 'edges', old2new); | ||
return old2new; | ||
}; | ||
@@ -215,3 +217,3 @@ | ||
function RepeatedPointsDS(vertices_coords, epsilon1) { | ||
var coord, k, key, len, ref, v; | ||
var base, coord, k, len, name, ref, v; | ||
this.vertices_coords = vertices_coords; | ||
@@ -223,7 +225,3 @@ this.epsilon = epsilon1; | ||
coord = ref[v]; | ||
key = this.key(coord); | ||
if (!(key in this.hash)) { | ||
this.hash[key] = []; | ||
} | ||
this.hash[key].push(v); | ||
((base = this.hash)[name = this.key(coord)] != null ? base[name] : base[name] = []).push(v); | ||
} | ||
@@ -266,3 +264,3 @@ null; | ||
RepeatedPointsDS.prototype.insert = function(coord) { | ||
var key, v; | ||
var base, name, v; | ||
v = this.lookup(coord); | ||
@@ -272,7 +270,3 @@ if (v != null) { | ||
} | ||
key = this.key(coord); | ||
if (!(key in this.hash)) { | ||
this.hash[key] = []; | ||
} | ||
this.hash[key].push(v = this.vertices_coords.length); | ||
((base = this.hash)[name = this.key(coord)] != null ? base[name] : base[name] = []).push(v = this.vertices_coords.length); | ||
this.vertices_coords.push(coord); | ||
@@ -302,3 +296,3 @@ return v; | ||
filter.addVertex = function(fold, coords, epsilon) { | ||
filter.maybeAddVertex = function(fold, coords, epsilon) { | ||
@@ -352,6 +346,6 @@ /* | ||
subdivides all crossing/touching edges to form a planar graph. | ||
In particular, all duplicate and loop edges are also removed. | ||
If called without `involvingEdgesFrom`, does all subdivision in quadratic | ||
time. xxx Should be O(n log n) via plane sweep. | ||
In this case, all duplicate and loop edges are also removed. | ||
In this case, returns an array of indices of all edges that were subdivided | ||
@@ -364,4 +358,2 @@ (both modified old edges and new edges). | ||
edges_vertices.length - 1`; then this will run in linear time. | ||
In this case, there should already be no duplicate or loop edges; see | ||
`filter.removeDuplicateEdges_vertices` and `filter.removeLoopEdges`. | ||
In this case, returns two arrays of edges: the first array are all subdivided | ||
@@ -371,3 +363,3 @@ from the "involved" edges, while the second array is the remaining subdivided | ||
*/ | ||
var addEdge, changedEdges, cross, crossI, e, e1, e2, i, i1, i2, k, l, len, len1, len2, len3, m, n, p, ref, ref1, ref2, ref3, s, s1, s2, u, v, vertices; | ||
var addEdge, changedEdges, cross, crossI, e, e1, e2, i, i1, i2, k, l, len, len1, len2, len3, m, n, old2new, p, ref, ref1, ref2, ref3, s, s1, s2, u, v, vertices; | ||
changedEdges = [[], []]; | ||
@@ -394,19 +386,16 @@ addEdge = function(v1, v2, oldEdgeIndex, which) { | ||
}; | ||
ref = fold.vertices_coords; | ||
for (v = k = 0, len = ref.length; k < len; v = ++k) { | ||
p = ref[v]; | ||
ref1 = fold.edges_vertices.slice(involvingEdgesFrom != null ? involvingEdgesFrom : 0); | ||
for (i = l = 0, len1 = ref1.length; l < len1; i = ++l) { | ||
e = ref1[i]; | ||
i = involvingEdgesFrom != null ? involvingEdgesFrom : 0; | ||
while (i < fold.edges_vertices.length) { | ||
e = fold.edges_vertices[i]; | ||
ref = fold.vertices_coords; | ||
for (v = k = 0, len = ref.length; k < len; v = ++k) { | ||
p = ref[v]; | ||
if (indexOf.call(e, v) >= 0) { | ||
continue; | ||
} | ||
if (involvingEdgesFrom != null) { | ||
i += involvingEdgesFrom; | ||
} | ||
s = (function() { | ||
var len2, m, results; | ||
var l, len1, results; | ||
results = []; | ||
for (m = 0, len2 = e.length; m < len2; m++) { | ||
u = e[m]; | ||
for (l = 0, len1 = e.length; l < len1; l++) { | ||
u = e[l]; | ||
results.push(fold.vertices_coords[u]); | ||
@@ -421,19 +410,13 @@ } | ||
} | ||
i++; | ||
} | ||
if (involvingEdgesFrom == null) { | ||
filter.removeDuplicateEdges_vertices(fold); | ||
filter.removeLoopEdges(fold); | ||
} | ||
vertices = new RepeatedPointsDS(fold.vertices_coords, epsilon); | ||
ref2 = fold.edges_vertices.slice(involvingEdgesFrom != null ? involvingEdgesFrom : 0); | ||
for (i1 = m = 0, len2 = ref2.length; m < len2; i1 = ++m) { | ||
e1 = ref2[i1]; | ||
if (involvingEdgesFrom != null) { | ||
i1 += involvingEdgesFrom; | ||
} | ||
i1 = involvingEdgesFrom != null ? involvingEdgesFrom : 0; | ||
while (i1 < fold.edges_vertices.length) { | ||
e1 = fold.edges_vertices[i1]; | ||
s1 = (function() { | ||
var len3, n, results; | ||
var l, len1, results; | ||
results = []; | ||
for (n = 0, len3 = e1.length; n < len3; n++) { | ||
v = e1[n]; | ||
for (l = 0, len1 = e1.length; l < len1; l++) { | ||
v = e1[l]; | ||
results.push(fold.vertices_coords[v]); | ||
@@ -443,10 +426,10 @@ } | ||
})(); | ||
ref3 = fold.edges_vertices.slice(0, i1); | ||
for (i2 = n = 0, len3 = ref3.length; n < len3; i2 = ++n) { | ||
e2 = ref3[i2]; | ||
ref1 = fold.edges_vertices.slice(0, i1); | ||
for (i2 = l = 0, len1 = ref1.length; l < len1; i2 = ++l) { | ||
e2 = ref1[i2]; | ||
s2 = (function() { | ||
var len4, o, results; | ||
var len2, m, results; | ||
results = []; | ||
for (o = 0, len4 = e2.length; o < len4; o++) { | ||
v = e2[o]; | ||
for (m = 0, len2 = e2.length; m < len2; m++) { | ||
v = e2[m]; | ||
results.push(fold.vertices_coords[v]); | ||
@@ -458,2 +441,5 @@ } | ||
cross = geom.lineIntersectLine(s1, s2); | ||
if (cross == null) { | ||
continue; | ||
} | ||
crossI = vertices.insert(cross); | ||
@@ -464,2 +450,3 @@ if (!(indexOf.call(e1, crossI) >= 0 && indexOf.call(e2, crossI) >= 0)) { | ||
e1[1] = crossI; | ||
s1[1] = fold.vertices_coords[crossI]; | ||
} | ||
@@ -473,3 +460,38 @@ if (indexOf.call(e2, crossI) < 0) { | ||
} | ||
i1++; | ||
} | ||
old2new = filter.removeDuplicateEdges_vertices(fold); | ||
ref2 = [0, 1]; | ||
for (m = 0, len2 = ref2.length; m < len2; m++) { | ||
i = ref2[m]; | ||
changedEdges[i] = (function() { | ||
var len3, n, ref3, results; | ||
ref3 = changedEdges[i]; | ||
results = []; | ||
for (n = 0, len3 = ref3.length; n < len3; n++) { | ||
e = ref3[n]; | ||
if (old2new[e] != null) { | ||
results.push(old2new[e]); | ||
} | ||
} | ||
return results; | ||
})(); | ||
} | ||
old2new = filter.removeLoopEdges(fold); | ||
ref3 = [0, 1]; | ||
for (n = 0, len3 = ref3.length; n < len3; n++) { | ||
i = ref3[n]; | ||
changedEdges[i] = (function() { | ||
var len4, o, ref4, results; | ||
ref4 = changedEdges[i]; | ||
results = []; | ||
for (o = 0, len4 = ref4.length; o < len4; o++) { | ||
e = ref4[o]; | ||
if (old2new[e] != null) { | ||
results.push(old2new[e]); | ||
} | ||
} | ||
return results; | ||
})(); | ||
} | ||
if (involvingEdgesFrom != null) { | ||
@@ -482,3 +504,3 @@ return changedEdges; | ||
filter.addEdge = function(fold, v1, v2, epsilon) { | ||
filter.addEdgeAndSubdivide = function(fold, v1, v2, epsilon) { | ||
@@ -492,6 +514,6 @@ /* | ||
if (v1.length != null) { | ||
v1 = filter.addVertex(fold, v1, epsilon); | ||
v1 = filter.maybeAddVertex(fold, v1, epsilon); | ||
} | ||
if (v2.length != null) { | ||
v2 = filter.addVertex(fold, v2, epsilon); | ||
v2 = filter.maybeAddVertex(fold, v2, epsilon); | ||
} | ||
@@ -498,0 +520,0 @@ if (v1 === v2) { |
/* BASIC GEOMETRY */ | ||
var EPS, geom, | ||
var geom, | ||
modulo = function(a, b) { return (+a % (b = +b) + b) % b; }; | ||
@@ -13,3 +13,3 @@ | ||
EPS = 0.000001; | ||
geom.EPS = 0.000001; | ||
@@ -100,3 +100,3 @@ geom.sum = function(a, b) { | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -112,3 +112,3 @@ length = geom.magsq(a); | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -228,3 +228,3 @@ if (geom.magsq(a) < eps) { | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -289,3 +289,3 @@ ref = (function() { | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -384,3 +384,3 @@ return geom.unit(((function() { | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -399,3 +399,3 @@ v0 = geom.sub(p, s[0]); | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -478,3 +478,3 @@ if (((function() { | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -511,3 +511,3 @@ ref = (function() { | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -540,3 +540,3 @@ ref = [t1, t2]; | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -579,3 +579,3 @@ ref = [[t1, t2], [t2, t1]]; | ||
if (eps == null) { | ||
eps = EPS; | ||
eps = geom.EPS; | ||
} | ||
@@ -582,0 +582,0 @@ b1 = Math.cos(a) + Math.cos(b); |
{ | ||
"name": "fold", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "FOLD file format for origami models, crease patterns, etc.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
190610
4902