Sha256: 71b5a9070da5880d47b234386c9a90899748b3900b2f5389000ffe67eec9da74

Contents?: true

Size: 1.41 KB

Versions: 10

Compression:

Stored size: 1.41 KB

Contents

/*
 * L.PolyUtil contains utility functions for polygons (clipping, etc.).
 */

/*jshint bitwise:false */ // allow bitwise operations here

L.PolyUtil = {};

/*
 * Sutherland-Hodgeman polygon clipping algorithm.
 * Used to avoid rendering parts of a polygon that are not currently visible.
 */
L.PolyUtil.clipPolygon = function (points, bounds) {
	var clippedPoints,
	    edges = [1, 4, 2, 8],
	    i, j, k,
	    a, b,
	    len, edge, p,
	    lu = L.LineUtil;

	for (i = 0, len = points.length; i < len; i++) {
		points[i]._code = lu._getBitCode(points[i], bounds);
	}

	// for each edge (left, bottom, right, top)
	for (k = 0; k < 4; k++) {
		edge = edges[k];
		clippedPoints = [];

		for (i = 0, len = points.length, j = len - 1; i < len; j = i++) {
			a = points[i];
			b = points[j];

			// if a is inside the clip window
			if (!(a._code & edge)) {
				// if b is outside the clip window (a->b goes out of screen)
				if (b._code & edge) {
					p = lu._getEdgeIntersection(b, a, edge, bounds);
					p._code = lu._getBitCode(p, bounds);
					clippedPoints.push(p);
				}
				clippedPoints.push(a);

			// else if b is inside the clip window (a->b enters the screen)
			} else if (!(b._code & edge)) {
				p = lu._getEdgeIntersection(b, a, edge, bounds);
				p._code = lu._getBitCode(p, bounds);
				clippedPoints.push(p);
			}
		}
		points = clippedPoints;
	}

	return points;
};

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
leaflet-js-0.7.9 vendor/assets/Leaflet/src/geometry/PolyUtil.js
leaflet-js-0.7.8 vendor/assets/Leaflet/src/geometry/PolyUtil.js
leaflet-js-0.7.7 vendor/assets/Leaflet/src/geometry/PolyUtil.js
leaflet-js-0.8.dev2 lib/leaflet/src/geometry/PolyUtil.js
leaflet-js-0.7.0.4 lib/leaflet/src/geometry/PolyUtil.js
leaflet-js-0.7.0.3 lib/leaflet/src/geometry/PolyUtil.js
leaflet-js-0.7.0.2 lib/leaflet/src/geometry/PolyUtil.js
leaflet-js-0.7.0.1 lib/leaflet/src/geometry/PolyUtil.js
leaflet-js-0.7.0 lib/leaflet/src/geometry/PolyUtil.js
leaflet-js-0.6.beta4 lib/leaflet/src/geometry/PolyUtil.js