mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 13:18:15 +02:00
Transitionable actionMoveNode
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MoveNodeAction.as
|
||||
export function actionMoveNode(nodeId, loc) {
|
||||
return function(graph) {
|
||||
return graph.replace(graph.entity(nodeId).move(loc));
|
||||
import { geoInterp } from '../geo';
|
||||
|
||||
export function actionMoveNode(nodeID, toLoc) {
|
||||
|
||||
var action = function(graph, t) {
|
||||
if (t === null || !isFinite(t)) t = 1;
|
||||
t = Math.min(Math.max(+t, 0), 1);
|
||||
|
||||
var node = graph.entity(nodeID);
|
||||
return graph.replace(
|
||||
node.move(geoInterp(node.loc, toLoc, t))
|
||||
);
|
||||
};
|
||||
|
||||
action.transitionable = true;
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,46 @@
|
||||
describe('iD.actionMoveNode', function () {
|
||||
it('changes a node\'s location', function () {
|
||||
var node = iD.Node(),
|
||||
loc = [2, 3],
|
||||
graph = iD.actionMoveNode(node.id, loc)(iD.Graph([node]));
|
||||
expect(graph.entity(node.id).loc).to.eql(loc);
|
||||
var node = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var toLoc = [2, 3];
|
||||
var graph = iD.coreGraph([node]);
|
||||
|
||||
graph = iD.actionMoveNode('a', toLoc)(graph);
|
||||
expect(graph.entity('a').loc).to.eql(toLoc);
|
||||
});
|
||||
|
||||
describe('transitions', function () {
|
||||
it('is transitionable', function() {
|
||||
expect(iD.actionMoveNode().transitionable).to.be.true;
|
||||
});
|
||||
|
||||
it('move node at t = 0', function() {
|
||||
var node = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var toLoc = [2, 3];
|
||||
var graph = iD.coreGraph([node]);
|
||||
|
||||
graph = iD.actionMoveNode('a', toLoc)(graph, 0);
|
||||
expect(graph.entity('a').loc[0]).to.be.closeTo(0, 1e-6);
|
||||
expect(graph.entity('a').loc[1]).to.be.closeTo(0, 1e-6);
|
||||
});
|
||||
|
||||
it('move node at t = 0.5', function() {
|
||||
var node = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var toLoc = [2, 3];
|
||||
var graph = iD.coreGraph([node]);
|
||||
|
||||
graph = iD.actionMoveNode('a', toLoc)(graph, 0.5);
|
||||
expect(graph.entity('a').loc[0]).to.be.closeTo(1, 1e-6);
|
||||
expect(graph.entity('a').loc[1]).to.be.closeTo(1.5, 1e-6);
|
||||
});
|
||||
|
||||
it('move node at t = 1', function() {
|
||||
var node = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var toLoc = [2, 3];
|
||||
var graph = iD.coreGraph([node]);
|
||||
|
||||
graph = iD.actionMoveNode('a', toLoc)(graph, 1);
|
||||
expect(graph.entity('a').loc[0]).to.be.closeTo(2, 1e-6);
|
||||
expect(graph.entity('a').loc[1]).to.be.closeTo(3, 1e-6);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user