mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 13:38:26 +02:00
Expand tests, move way logic into entity.js and test it.
This commit is contained in:
@@ -45,7 +45,6 @@
|
||||
<script src='js/id/format/xml.js'></script>
|
||||
|
||||
<script src='js/id/graph/entity.js'></script>
|
||||
<script src='js/id/graph/way.js'></script>
|
||||
<script src='js/id/graph/graph.js'></script>
|
||||
<script src='js/id/graph/history.js'></script>
|
||||
<script src='js/id/connection.js'></script>
|
||||
|
||||
+14
-2
@@ -34,11 +34,23 @@ iD.Entity.prototype = {
|
||||
};
|
||||
|
||||
iD.Node = function(attrs) {
|
||||
return iD.Entity(_.extend({}, attrs || {}, {type: 'node'}));
|
||||
return iD.Entity(_.extend({}, attrs || {}, {type: 'node', tags: {}}));
|
||||
};
|
||||
|
||||
iD.Way = function(attrs) {
|
||||
return iD.Entity(_.extend({}, attrs || {}, {type: 'way', nodes: []}));
|
||||
return iD.Entity(_.extend({}, attrs || {}, {type: 'way', nodes: [], tags: {}}));
|
||||
};
|
||||
|
||||
iD.Way.isOneWay = function(d) {
|
||||
return !!(d.tags.oneway && d.tags.oneway === 'yes');
|
||||
};
|
||||
|
||||
iD.Way.isClosed = function(d) {
|
||||
return (!d.nodes.length) || d.nodes[d.nodes.length - 1].id === d.nodes[0].id;
|
||||
};
|
||||
|
||||
iD.Way.isArea = function(d) {
|
||||
return iD.Way.isClosed(d) || (d.tags.area && d.tags.area === 'yes');
|
||||
};
|
||||
|
||||
iD.Relation = function(attrs) {
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
// Way
|
||||
// wiki: http://wiki.openstreetmap.org/wiki/Way
|
||||
//
|
||||
// Ways can either be open or closed. A closed way is such that the
|
||||
// last node is the first node.
|
||||
//
|
||||
// If a a way is _closed_, it is assumed to be an area unless it has a
|
||||
// `highway` or `barrier` tag and is not also tagged `area`.
|
||||
|
||||
iD.Way.isClosed = function(w) {
|
||||
return (!w.nodes.length) || w.nodes[w.nodes.length - 1].id === w.nodes[0].id;
|
||||
};
|
||||
@@ -133,10 +133,6 @@ iD.Map = function() {
|
||||
|
||||
function classActive(d) { return d.id === selection; }
|
||||
|
||||
function isArea(a) {
|
||||
return iD.Way.isClosed(a) || (a.tags.area && a.tags.area === 'yes');
|
||||
}
|
||||
|
||||
function drawVector(only) {
|
||||
if (surface.style(transformProp) != 'none') return;
|
||||
var all = [], ways = [], areas = [], points = [], waynodes = [],
|
||||
@@ -160,7 +156,7 @@ iD.Map = function() {
|
||||
var a = all[i];
|
||||
if (a.type === 'way') {
|
||||
a._line = nodeline(a);
|
||||
if (isArea(a)) areas.push(a);
|
||||
if (iD.Way.isArea(a)) areas.push(a);
|
||||
else ways.push(a);
|
||||
} else if (a._poi) {
|
||||
points.push(a);
|
||||
@@ -256,7 +252,6 @@ iD.Map = function() {
|
||||
markers.select('image').attr('xlink:href', iD.Style.markerimage);
|
||||
}
|
||||
|
||||
function isOneWay(d) { return d.tags.oneway && d.tags.oneway === 'yes'; }
|
||||
function drawStrokes(ways, filter) {
|
||||
var strokes = g.stroke.selectAll('path')
|
||||
.filter(filter)
|
||||
@@ -273,7 +268,7 @@ iD.Map = function() {
|
||||
|
||||
// Determine the lengths of oneway paths
|
||||
var lengths = {},
|
||||
oneways = strokes.filter(isOneWay).each(function(d) {
|
||||
oneways = strokes.filter(iD.Way.isOneWay).each(function(d) {
|
||||
lengths[d.id] = Math.floor(this.getTotalLength() / alength);
|
||||
}).data();
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
<script src='../js/id/format/xml.js'></script>
|
||||
|
||||
<script src='../js/id/graph/entity.js'></script>
|
||||
<script src='../js/id/graph/way.js'></script>
|
||||
<script src='../js/id/graph/graph.js'></script>
|
||||
<script src='../js/id/graph/history.js'></script>
|
||||
<script src='../js/id/connection.js'></script>
|
||||
|
||||
+21
-11
@@ -1,14 +1,24 @@
|
||||
describe('Way', function() {
|
||||
var way;
|
||||
describe('#isClosed', function() {
|
||||
it('is not closed with two distinct nodes', function() {
|
||||
var open_way = { type: 'way', nodes: [{id: 'n1'}, {id: 'n2'}] };
|
||||
expect(iD.Way.isClosed(open_way)).to.equal(false);
|
||||
});
|
||||
it('is not closed with a node loop', function() {
|
||||
var closed_way = { type: 'way', nodes: [{id: 'n1'}, {id: 'n2'}, {id: 'n1'}] };
|
||||
expect(iD.Way.isClosed(closed_way)).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
way = { type: 'way', nodes: [{id: 'n1'}, {id: 'n2'}] };
|
||||
});
|
||||
|
||||
|
||||
describe('#isClosed', function() {
|
||||
it('is not closed with two distinct nodes ', function() {
|
||||
expect(iD.Way.isClosed(way)).to.equal(false);
|
||||
});
|
||||
});
|
||||
describe('#isOneWay', function() {
|
||||
it('is not oneway without any tags', function() {
|
||||
expect(iD.Way.isOneWay(iD.Way())).to.eql(false);
|
||||
});
|
||||
it('is not oneway oneway=no', function() {
|
||||
expect(iD.Way.isOneWay(iD.Way({ tags: { oneway: 'no' } }))).to.eql(false);
|
||||
});
|
||||
it('is oneway oneway=yes', function() {
|
||||
expect(iD.Way.isOneWay(iD.Way({ tags: { oneway: 'yes' } }))).to.eql(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user