2013-11-08 05:54:33 +08:00
|
|
|
describe("Point", function () {
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('constructor', function () {
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
it("creates a point with the given x and y", function () {
|
2010-09-02 23:23:53 +08:00
|
|
|
var p = new L.Point(1.5, 2.5);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(p.x).to.eql(1.5);
|
|
|
|
expect(p.y).to.eql(2.5);
|
2010-09-02 23:23:53 +08:00
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
it("rounds the given x and y if the third argument is true", function () {
|
2010-09-02 23:23:53 +08:00
|
|
|
var p = new L.Point(1.3, 2.7, true);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(p.x).to.eql(1);
|
|
|
|
expect(p.y).to.eql(3);
|
2010-09-02 23:23:53 +08:00
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#subtract', function () {
|
|
|
|
it('subtracts the given point from this one', function () {
|
2010-09-13 19:58:03 +08:00
|
|
|
var a = new L.Point(50, 30),
|
2015-09-25 18:55:37 +08:00
|
|
|
b = new L.Point(20, 10);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.subtract(b)).to.eql(new L.Point(30, 20));
|
2010-09-13 19:58:03 +08:00
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#add', function () {
|
|
|
|
it('adds given point to this one', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(new L.Point(50, 30).add(new L.Point(20, 10))).to.eql(new L.Point(70, 40));
|
2010-09-13 19:58:03 +08:00
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#divideBy', function () {
|
|
|
|
it('divides this point by the given amount', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(new L.Point(50, 30).divideBy(5)).to.eql(new L.Point(10, 6));
|
2010-09-13 19:58:03 +08:00
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#multiplyBy', function () {
|
|
|
|
it('multiplies this point by the given amount', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(new L.Point(50, 30).multiplyBy(2)).to.eql(new L.Point(100, 60));
|
2010-09-15 21:45:02 +08:00
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
|
|
|
describe('#floor', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns a new point with floored coordinates', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(new L.Point(50.56, 30.123).floor()).to.eql(new L.Point(50, 30));
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#distanceTo', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('calculates distance between two points', function () {
|
2013-02-05 19:51:27 +08:00
|
|
|
var p1 = new L.Point(0, 30);
|
|
|
|
var p2 = new L.Point(40, 0);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(p1.distanceTo(p2)).to.eql(50.0);
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#equals', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if points are equal', function () {
|
2013-02-05 19:51:27 +08:00
|
|
|
var p1 = new L.Point(20.4, 50.12);
|
|
|
|
var p2 = new L.Point(20.4, 50.12);
|
|
|
|
var p3 = new L.Point(20.5, 50.13);
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(p1.equals(p2)).to.be(true);
|
|
|
|
expect(p1.equals(p3)).to.be(false);
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-02-22 23:28:55 +08:00
|
|
|
describe('#contains', function () {
|
|
|
|
it('returns true if the point is bigger in absolute dimensions than the passed one', function () {
|
|
|
|
var p1 = new L.Point(50, 30),
|
2015-09-25 18:55:37 +08:00
|
|
|
p2 = new L.Point(-40, 20),
|
|
|
|
p3 = new L.Point(60, -20),
|
|
|
|
p4 = new L.Point(-40, -40);
|
2013-02-22 23:28:55 +08:00
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(p1.contains(p2)).to.be(true);
|
|
|
|
expect(p1.contains(p3)).to.be(false);
|
|
|
|
expect(p1.contains(p4)).to.be(false);
|
2013-02-22 23:28:55 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-02-05 19:51:27 +08:00
|
|
|
describe('#toString', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('formats a string out of point coordinates', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(new L.Point(50, 30) + '').to.eql('Point(50, 30)');
|
2017-10-03 00:36:59 +08:00
|
|
|
expect(new L.Point(50.1234567, 30.1234567) + '').to.eql('Point(50.123457, 30.123457)');
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('L.point factory', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('leaves L.Point instances as is', function () {
|
2013-02-05 19:51:27 +08:00
|
|
|
var p = new L.Point(50, 30);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.point(p)).to.be(p);
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
2013-02-20 04:41:48 +08:00
|
|
|
it('creates a point out of three arguments', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.point(50.1, 30.1, true)).to.eql(new L.Point(50, 30));
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
2013-02-20 04:41:48 +08:00
|
|
|
it('creates a point from an array of coordinates', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.point([50, 30])).to.eql(new L.Point(50, 30));
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
2016-04-20 23:05:31 +08:00
|
|
|
it("creates a point from an object with x and y properties", function () {
|
|
|
|
expect(L.point({x: 50, y: 30})).to.eql(new L.Point(50, 30));
|
|
|
|
});
|
2013-02-20 04:41:48 +08:00
|
|
|
it('does not fail on invalid arguments', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.point(undefined)).to.be(undefined);
|
|
|
|
expect(L.point(null)).to.be(null);
|
2013-02-05 19:51:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|