mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-23 00:29:50 +02:00
b9e48d1682
This is more work to further isolate the layers that entities draw to. It makes it easier to debug what is going on, and can eventually lead to deferred drawing, if each draw function is in its own place and not dependant on anything else. I've started to replace the vertex-hover with an explicit layer for touch targets. Also had to change a lot of the svg tests, which are really brittle. Things would happen like - the surface would be created, it would kick of a deferred redraw, which would notice that the zoom was 0 and call editOff, which would remove the osm layers that were just created and that the tests were trying to draw to. These tests need proper zoom and projection otherwise nothing works.
107 lines
4.2 KiB
JavaScript
107 lines
4.2 KiB
JavaScript
describe('iD.svgMidpoints', function () {
|
|
var TAU = 2 * Math.PI;
|
|
function ztok(z) { return 256 * Math.pow(2, z) / TAU; }
|
|
|
|
var context, surface;
|
|
var _selectedIDs = [];
|
|
var filter = function() { return true; };
|
|
var projection = d3.geoProjection(function(x, y) { return [x, -y]; })
|
|
.translate([0, 0])
|
|
.scale(ztok(17))
|
|
.clipExtent([[0, 0], [Infinity, Infinity]]);
|
|
|
|
|
|
beforeEach(function () {
|
|
context = iD.coreContext();
|
|
context.enter({
|
|
id: 'select',
|
|
enter: function() { },
|
|
exit: function() { },
|
|
selectedIDs: function() { return _selectedIDs; }
|
|
});
|
|
|
|
var map = d3.select(document.createElement('div'))
|
|
.attr('id', 'map')
|
|
.call(context.map().centerZoom([0, 0], 17));
|
|
|
|
surface = context.surface();
|
|
});
|
|
|
|
|
|
it('creates midpoint on segment completely within the extent', function () {
|
|
var a = iD.osmNode({loc: [0, 0]});
|
|
var b = iD.osmNode({loc: [1, 0]});
|
|
var line = iD.osmWay({nodes: [a.id, b.id]});
|
|
var graph = iD.coreGraph([a, b, line]);
|
|
var extent = iD.geoExtent([0, 0], [1, 1]);
|
|
|
|
_selectedIDs = [line.id];
|
|
context.entity = function(id) { return graph.entity(id); };
|
|
context.hasEntity = function(id) { return graph.entities[id]; };
|
|
|
|
surface.call(iD.svgMidpoints(projection, context), graph, [line], filter, extent);
|
|
expect(surface.selectAll('.midpoint').datum().loc).to.eql([0.5, 0]);
|
|
});
|
|
|
|
it('doesn\'t create midpoint on segment with pixel length less than 40', function () {
|
|
var a = iD.osmNode({loc: [0, 0]});
|
|
var b = iD.osmNode({loc: [0.0001, 0]});
|
|
var line = iD.osmWay({nodes: [a.id, b.id]});
|
|
var graph = iD.coreGraph([a, b, line]);
|
|
var extent = iD.geoExtent([0, 0], [1, 1]);
|
|
|
|
_selectedIDs = [line.id];
|
|
context.entity = function(id) { return graph.entity(id); };
|
|
context.hasEntity = function(id) { return graph.entities[id]; };
|
|
|
|
surface.call(iD.svgMidpoints(projection, context), graph, [line], filter, extent);
|
|
expect(surface.selectAll('.midpoint').nodes()).to.have.length(0);
|
|
});
|
|
|
|
it('doesn\'t create midpoint on segment completely outside of the extent', function () {
|
|
var a = iD.osmNode({loc: [-1, 0]});
|
|
var b = iD.osmNode({loc: [-0.5, 0]});
|
|
var line = iD.osmWay({nodes: [a.id, b.id]});
|
|
var graph = iD.coreGraph([a, b, line]);
|
|
var extent = iD.geoExtent([0, 0], [1, 1]);
|
|
|
|
_selectedIDs = [line.id];
|
|
context.entity = function(id) { return graph.entity(id); };
|
|
context.hasEntity = function(id) { return graph.entities[id]; };
|
|
|
|
surface.call(iD.svgMidpoints(projection, context), graph, [line], filter, extent);
|
|
expect(surface.selectAll('.midpoint').nodes()).to.have.length(0);
|
|
});
|
|
|
|
it('creates midpoint on extent edge for segment partially outside of the extent', function () {
|
|
var a = iD.osmNode({loc: [0.5, 0]});
|
|
var b = iD.osmNode({loc: [2, 0]});
|
|
var line = iD.osmWay({nodes: [a.id, b.id]});
|
|
var graph = iD.coreGraph([a, b, line]);
|
|
var extent = iD.geoExtent([0, 0], [1, 1]);
|
|
|
|
_selectedIDs = [line.id];
|
|
context.entity = function(id) { return graph.entity(id); };
|
|
context.hasEntity = function(id) { return graph.entities[id]; };
|
|
|
|
surface.call(iD.svgMidpoints(projection, context), graph, [line], filter, extent);
|
|
expect(surface.selectAll('.midpoint').datum().loc).to.eql([1, 0]);
|
|
});
|
|
|
|
it('doesn\'t create midpoint on extent edge for segment with pixel length less than 20', function () {
|
|
var a = iD.osmNode({loc: [0.9999, 0]});
|
|
var b = iD.osmNode({loc: [2, 0]});
|
|
var line = iD.osmWay({nodes: [a.id, b.id]});
|
|
var graph = iD.coreGraph([a, b, line]);
|
|
var extent = iD.geoExtent([0, 0], [1, 1]);
|
|
|
|
_selectedIDs = [line.id];
|
|
context.entity = function(id) { return graph.entity(id); };
|
|
context.hasEntity = function(id) { return graph.entities[id]; };
|
|
|
|
surface.call(iD.svgMidpoints(projection, context), graph, [line], filter, extent);
|
|
expect(surface.selectAll('.midpoint').nodes()).to.have.length(0);
|
|
});
|
|
|
|
});
|