mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-17 19:23:02 +00:00
Fix strict mode parse error and other style issues
This commit is contained in:
@@ -15,17 +15,58 @@
|
||||
iD.actions.Split = function(nodeId, newWayIds) {
|
||||
var wayIds;
|
||||
|
||||
// if the way is closed, we need to search for a partner node
|
||||
// to split the way at.
|
||||
//
|
||||
// The following looks for a node that is both far away from
|
||||
// the initial node in terms of way segment length and nearby
|
||||
// in terms of beeline-distance. This assures that areas get
|
||||
// split on the most "natural" points (independent of the number
|
||||
// of nodes).
|
||||
// For example: bone-shaped areas get split across their waist
|
||||
// line, circles across the diameter.
|
||||
function splitArea(nodes, idxA, graph) {
|
||||
var lengths = new Array(nodes.length),
|
||||
length,
|
||||
i,
|
||||
best = 0,
|
||||
idxB;
|
||||
|
||||
function wrap(index) {
|
||||
return iD.util.wrap(index, nodes.length);
|
||||
}
|
||||
|
||||
function dist(nA, nB) {
|
||||
return iD.geo.sphericalDistance(graph.entity(nA).loc, graph.entity(nB).loc);
|
||||
}
|
||||
|
||||
// calculate lengths
|
||||
length = 0;
|
||||
for (i = wrap(idxA+1); i != idxA; i = wrap(i+1)) {
|
||||
length += dist(nodes[i], nodes[wrap(i-1)]);
|
||||
lengths[i] = length;
|
||||
}
|
||||
|
||||
length = 0;
|
||||
for (i = wrap(idxA-1); i != idxA; i = wrap(i-1)) {
|
||||
length += dist(nodes[i], nodes[wrap(i+1)]);
|
||||
if (length < lengths[i])
|
||||
lengths[i] = length;
|
||||
}
|
||||
|
||||
// determine best opposite node to split
|
||||
for (i = 0; i < nodes.length; i++) {
|
||||
var cost = lengths[i] / dist(nodes[idxA], nodes[i]);
|
||||
if (cost > best) {
|
||||
idxB = i;
|
||||
best = cost;
|
||||
}
|
||||
}
|
||||
|
||||
return idxB;
|
||||
}
|
||||
|
||||
function split(graph, wayA, newWayId) {
|
||||
// if the way is closed, we need to search for a partner node
|
||||
// to split the way at.
|
||||
//
|
||||
// The following looks for a node that is both far away from
|
||||
// the initial node in terms of way segment length and nearby
|
||||
// in terms of beeline-distance. This assures that areas get
|
||||
// split on the most "natural" points (independent of the number
|
||||
// of nodes).
|
||||
// For example: bone-shaped areas get split across their waist
|
||||
// line, circles across the diameter.
|
||||
var wayB = iD.Way({id: newWayId, tags: wayA.tags}),
|
||||
nodesA,
|
||||
nodesB,
|
||||
@@ -35,39 +76,7 @@ iD.actions.Split = function(nodeId, newWayIds) {
|
||||
if (wayA.isClosed()) {
|
||||
var nodes = wayA.nodes.slice(0, -1),
|
||||
idxA = _.indexOf(nodes, nodeId),
|
||||
idxB,
|
||||
lengths = Array(nodes.length),
|
||||
cum_length,
|
||||
i,
|
||||
best = 0.0;
|
||||
|
||||
function _wrap(index) {
|
||||
return iD.util.wrap(index,nodes.length);
|
||||
}
|
||||
function _dist(nA, nB) {
|
||||
return iD.geo.sphericalDistance(graph.entity(nA).loc, graph.entity(nB).loc);
|
||||
}
|
||||
|
||||
// calculate lengths
|
||||
cum_length = 0.0;
|
||||
for (i = _wrap(idxA+1); i != idxA; i = _wrap(i+1)) {
|
||||
cum_length += _dist(nodes[i], nodes[_wrap(i-1)]);
|
||||
lengths[i] = cum_length;
|
||||
}
|
||||
cum_length = 0.0;
|
||||
for (i = _wrap(idxA-1); i != idxA; i = _wrap(i-1)) {
|
||||
cum_length += _dist(nodes[i], nodes[_wrap(i+1)]);
|
||||
if (cum_length < lengths[i])
|
||||
lengths[i] = cum_length;
|
||||
}
|
||||
// determine best opposite node to split
|
||||
for (i = 0; i < nodes.length; i++) {
|
||||
var cost = lengths[i] / _dist(nodes[idxA], nodes[i]);
|
||||
if (cost > best) {
|
||||
idxB = i;
|
||||
best = cost;
|
||||
}
|
||||
}
|
||||
idxB = splitArea(nodes, idxA, graph);
|
||||
|
||||
if (idxB < idxA) {
|
||||
nodesA = nodes.slice(idxA).concat(nodes.slice(0, idxB + 1));
|
||||
|
||||
Reference in New Issue
Block a user