2013-11-08 05:54:33 +08:00
|
|
|
describe('Bounds', function () {
|
2012-09-04 06:22:24 +08:00
|
|
|
var a, b, c;
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
beforeEach(function () {
|
2010-09-13 19:58:28 +08:00
|
|
|
a = new L.Bounds(
|
|
|
|
new L.Point(14, 12),
|
|
|
|
new L.Point(30, 40));
|
|
|
|
b = new L.Bounds([
|
2012-09-04 06:22:24 +08:00
|
|
|
new L.Point(20, 12),
|
|
|
|
new L.Point(14, 20),
|
|
|
|
new L.Point(30, 40)
|
|
|
|
]);
|
|
|
|
c = new L.Bounds();
|
2010-09-13 19:58:28 +08:00
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('constructor', function () {
|
|
|
|
it('creates bounds with proper min & max on (Point, Point)', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.min).to.eql(new L.Point(14, 12));
|
|
|
|
expect(a.max).to.eql(new L.Point(30, 40));
|
2010-09-13 19:58:28 +08:00
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
it('creates bounds with proper min & max on (Point[])', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(b.min).to.eql(new L.Point(14, 12));
|
|
|
|
expect(b.max).to.eql(new L.Point(30, 40));
|
2010-09-13 19:58:28 +08:00
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#extend', function () {
|
|
|
|
it('extends the bounds to contain the given point', function () {
|
2010-09-13 19:58:28 +08:00
|
|
|
a.extend(new L.Point(50, 20));
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.min).to.eql(new L.Point(14, 12));
|
|
|
|
expect(a.max).to.eql(new L.Point(50, 40));
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2010-09-13 19:58:28 +08:00
|
|
|
b.extend(new L.Point(25, 50));
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(b.min).to.eql(new L.Point(14, 12));
|
|
|
|
expect(b.max).to.eql(new L.Point(30, 50));
|
2010-09-13 19:58:28 +08:00
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#getCenter', function () {
|
|
|
|
it('returns the center point', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getCenter()).to.eql(new L.Point(22, 26));
|
2010-09-13 19:58:28 +08:00
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#contains', function () {
|
|
|
|
it('contains other bounds or point', function () {
|
2012-09-04 06:22:24 +08:00
|
|
|
a.extend(new L.Point(50, 10));
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.contains(b)).to.be.ok();
|
|
|
|
expect(b.contains(a)).to.not.be.ok();
|
|
|
|
expect(a.contains(new L.Point(24, 25))).to.be.ok();
|
|
|
|
expect(a.contains(new L.Point(54, 65))).to.not.be.ok();
|
2012-09-04 06:22:24 +08:00
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#isValid', function () {
|
|
|
|
it('returns true if properly set up', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.isValid()).to.be.ok();
|
2012-09-04 06:22:24 +08:00
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns false if is invalid', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(c.isValid()).to.not.be.ok();
|
2012-09-04 06:22:24 +08:00
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns true if extended', function () {
|
2012-09-04 06:22:24 +08:00
|
|
|
c.extend([0, 0]);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(c.isValid()).to.be.ok();
|
2012-09-04 06:22:24 +08:00
|
|
|
});
|
2011-07-13 19:13:35 +08:00
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
|
|
|
describe('#getSize', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns the size of the bounds as point', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getSize()).to.eql(new L.Point(16, 28));
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#intersects', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if bounds intersect', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.intersects(b)).to.be(true);
|
|
|
|
expect(a.intersects(new L.Bounds(new L.Point(100, 100), new L.Point(120, 120)))).to.eql(false);
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('L.bounds factory', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('creates bounds from array of number arrays', function () {
|
2013-02-05 19:51:27 +08:00
|
|
|
var bounds = L.bounds([[14, 12], [30, 40]]);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(bounds).to.eql(a);
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|