2013-02-05 19:51:27 +08:00
|
|
|
describe('PolyUtil', function () {
|
|
|
|
|
|
|
|
describe('#clipPolygon', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('clips polygon by bounds', function () {
|
2013-02-05 19:51:27 +08:00
|
|
|
var bounds = L.bounds([0, 0], [10, 10]);
|
|
|
|
|
|
|
|
var points = [
|
|
|
|
new L.Point(5, 5),
|
|
|
|
new L.Point(15, 10),
|
|
|
|
new L.Point(10, 15)
|
|
|
|
];
|
|
|
|
|
2014-09-30 13:57:53 +08:00
|
|
|
//check clip without rounding
|
2013-02-05 19:51:27 +08:00
|
|
|
var clipped = L.PolyUtil.clipPolygon(points, bounds);
|
|
|
|
|
|
|
|
for (var i = 0, len = clipped.length; i < len; i++) {
|
|
|
|
delete clipped[i]._code;
|
|
|
|
}
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(clipped).to.eql([
|
2014-09-30 13:57:53 +08:00
|
|
|
new L.Point(7.5, 10),
|
|
|
|
new L.Point(5, 5),
|
|
|
|
new L.Point(10, 7.5),
|
|
|
|
new L.Point(10, 10)
|
|
|
|
]);
|
|
|
|
|
|
|
|
//check clip with rounding
|
|
|
|
var clippedRounded = L.PolyUtil.clipPolygon(points, bounds, true);
|
|
|
|
|
|
|
|
for (i = 0, len = clippedRounded.length; i < len; i++) {
|
|
|
|
delete clippedRounded[i]._code;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(clippedRounded).to.eql([
|
2013-12-19 03:56:23 +08:00
|
|
|
new L.Point(8, 10),
|
2013-02-05 19:51:27 +08:00
|
|
|
new L.Point(5, 5),
|
2013-12-19 03:56:23 +08:00
|
|
|
new L.Point(10, 8),
|
2013-02-05 19:51:27 +08:00
|
|
|
new L.Point(10, 10)
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|