Do not repeat first vertex when closed is true

This commit is contained in:
Andreas Hocevar
2016-09-12 23:42:54 +02:00
parent 51776ed79e
commit 129757578d
2 changed files with 48 additions and 7 deletions

View File

@@ -169,6 +169,12 @@ describe('ol.render.canvas.Replay', function() {
expect(replay.coordinates).to.eql(flat);
});
it('appends polygon coordinates that are within the max extent', function() {
var flat = [-110, 45, 110, 45, 110, -45, -110, -45, -110, 45];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, true);
expect(replay.coordinates).to.eql(flat);
});
it('works with a single coordinate (inside)', function() {
var flat = [-110, 45];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, false);
@@ -183,6 +189,14 @@ describe('ol.render.canvas.Replay', function() {
expect(replay.coordinates).to.eql(flat);
});
it('always appends first polygon vertex (even if outside)', function() {
// this could be changed, but to make the code simpler for properly
// closing rings, we always add the first point
var flat = [-110, 145, -110, 145];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, true);
expect(replay.coordinates).to.eql(flat);
});
it('appends points when segments cross (top to bottom)', function() {
// this means we get a few extra points when coordinates are not
// part of a linestring or ring, but only a few extra
@@ -205,18 +219,50 @@ describe('ol.render.canvas.Replay', function() {
expect(replay.coordinates).to.eql(flat);
});
it('always appends the first polygon segment (even when outside)', function() {
// this could be changed, but to make the code simpler for properly
// closing rings, we always add the first segment
var flat = [-10, 200, 10, 200, -10, 200];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, true);
expect(replay.coordinates).to.eql(flat);
});
it('eliminates segments outside (and not changing rel)', function() {
var flat = [0, 0, 0, 200, 5, 200, 10, 200];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, false);
expect(replay.coordinates).to.eql([0, 0, 0, 200]);
});
it('eliminates polygon segments outside (and not changing rel)', function() {
var flat = [0, 0, 0, 200, 5, 200, 10, 200, 0, 0];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, true);
expect(replay.coordinates).to.eql([0, 0, 0, 200, 10, 200, 0, 0]);
});
it('eliminates segments outside (and not changing rel)', function() {
var flat = [0, 0, 0, 200, 10, 200];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, false);
expect(replay.coordinates).to.eql([0, 0, 0, 200]);
});
it('includes polygon segments outside (and not changing rel) when on last segment', function() {
var flat = [0, 0, 0, 200, 10, 200, 0, 0];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, true);
expect(replay.coordinates).to.eql(flat);
});
it('includes outside segments that change relationship', function() {
var flat = [0, 0, 0, 200, 200, 200, 250, 200];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, false);
expect(replay.coordinates).to.eql([0, 0, 0, 200, 200, 200]);
});
it('includes outside polygon segments that change relationship when on last segment', function() {
var flat = [0, 0, 0, 200, 200, 200, 250, 200, 0, 0];
replay.appendFlatCoordinates(flat, 0, flat.length, 2, true);
expect(replay.coordinates).to.eql(flat);
});
});
});