Cache geometry

This commit is contained in:
John Firebaugh
2013-05-17 14:31:36 -07:00
parent 6b511ff45a
commit 2e4207f99b
7 changed files with 21 additions and 11 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) {
var way = context.entity(wayId),
isArea = way.geometry() === 'area',
isArea = context.geometry(wayId) === 'area',
finished = false,
annotation = t((way.isDegenerate() ?
'operations.start.annotation.' :
+3 -1
View File
@@ -16,7 +16,9 @@ _.extend(iD.Node.prototype, {
},
geometry: function(graph) {
return graph.isPoi(this) ? 'point' : 'vertex';
return graph.transient(this, 'geometry', function() {
return graph.isPoi(this) ? 'point' : 'vertex';
});
},
move: function(loc) {
+4 -2
View File
@@ -25,8 +25,10 @@ _.extend(iD.Relation.prototype, {
});
},
geometry: function() {
return this.isMultipolygon() ? 'area' : 'relation';
geometry: function(graph) {
return graph.transient(this, 'geometry', function() {
return this.isMultipolygon() ? 'area' : 'relation';
});
},
// Return the first member with the given role. A copy of the member object
+4 -2
View File
@@ -70,8 +70,10 @@ _.extend(iD.Way.prototype, {
return false;
},
geometry: function() {
return this.isArea() ? 'area' : 'line';
geometry: function(graph) {
return graph.transient(this, 'geometry', function() {
return this.isArea() ? 'area' : 'line';
});
},
addNode: function(id, index) {
+1 -1
View File
@@ -8,7 +8,7 @@ iD.operations.Rotate = function(selection, context) {
operation.available = function() {
return selection.length === 1 &&
context.entity(entityId).type === 'way' &&
context.entity(entityId).geometry() === 'area';
context.geometry(entityId) === 'area';
};
operation.disabled = function() {
+6 -2
View File
@@ -47,8 +47,12 @@ describe('iD.Relation', function () {
});
describe("#geometry", function () {
it("returns 'relation'", function () {
expect(iD.Relation().geometry()).to.equal('relation');
it("returns 'area' for multipolygons", function () {
expect(iD.Relation({tags: {type: 'multipolygon'}}).geometry(iD.Graph())).to.equal('area');
});
it("returns 'relation' for other relations", function () {
expect(iD.Relation().geometry(iD.Graph())).to.equal('relation');
});
});
+2 -2
View File
@@ -176,11 +176,11 @@ describe('iD.Way', function() {
describe("#geometry", function() {
it("returns 'line' when the way is not an area", function () {
expect(iD.Way().geometry()).to.equal('line');
expect(iD.Way().geometry(iD.Graph())).to.equal('line');
});
it("returns 'area' when the way is an area", function () {
expect(iD.Way({tags: { area: 'yes' }}).geometry()).to.equal('area');
expect(iD.Way({tags: { area: 'yes' }}).geometry(iD.Graph())).to.equal('area');
});
});