Files
iD/test/spec/lib/d3.clip.js
John Firebaugh 60a290282c Clip lines with Cohen-Sutherland algorithm
This yields a 10x paint performance increase at
#map=18.88/38.85208/-76.72632, as measured with
Chrome Canary's "Continuous Page Repainting" mode.

Fixes #885.
2013-03-03 18:25:42 -08:00

42 lines
1.2 KiB
JavaScript

describe('d3.clip.cohenSutherland', function() {
var clip;
beforeEach(function() {
clip = d3.clip.cohenSutherland()
.bounds([0, 0, 10, 10]);
});
it('clips an empty array', function() {
expect(clip([])).to.eql([]);
});
it('clips a point inside bounds', function() {
expect(clip([[0, 0]])).to.eql([[[0, 0]]]);
});
it('clips a point outside bounds', function() {
expect(clip([[-1, -1]])).to.eql([]);
});
it('clips a single segment inside bounds', function() {
expect(clip([[0, 0], [10, 10]])).to.eql([[[0, 0], [10, 10]]]);
});
it('clips a single segment leaving bounds', function() {
expect(clip([[5, 5], [15, 15]])).to.eql([[[5, 5], [10, 10]]]);
});
it('clips a single segment entering bounds', function() {
expect(clip([[15, 15], [5, 5]])).to.eql([[[10, 10], [5, 5]]]);
});
it('clips a single segment entering and leaving bounds', function() {
expect(clip([[0, 15], [15, 0]])).to.eql([[[5, 10], [10, 5]]]);
});
it('clips multiple segments', function() {
expect(clip([[15, 15], [5, 5], [15, 15], [5, 5]])).to.
eql([[[10, 10], [5, 5], [10, 10]], [[10, 10], [5, 5]]]);
});
});