aboutsummaryrefslogtreecommitdiffstats
path: root/extlib/leaflet/src/geometry/PolyUtil.js
diff options
context:
space:
mode:
authorJoar Wandborg <git@wandborg.com>2012-01-28 18:47:01 +0100
committerJoar Wandborg <git@wandborg.com>2012-01-28 18:47:01 +0100
commit3d0d3bc97270095fae5f9a2508068631c46a5e61 (patch)
tree76778fcacaae35fc5662f276dab512a07bcee186 /extlib/leaflet/src/geometry/PolyUtil.js
parentd7bec8577ea1b4d83df097f586324445fed1ef50 (diff)
parent9542a2ba076b7e00e79d7adb1a4e90a095427645 (diff)
downloadmediagoblin-3d0d3bc97270095fae5f9a2508068631c46a5e61.tar.lz
mediagoblin-3d0d3bc97270095fae5f9a2508068631c46a5e61.tar.xz
mediagoblin-3d0d3bc97270095fae5f9a2508068631c46a5e61.zip
Merge remote-tracking branch 'joar/exif-rebase'
Diffstat (limited to 'extlib/leaflet/src/geometry/PolyUtil.js')
-rw-r--r--extlib/leaflet/src/geometry/PolyUtil.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/extlib/leaflet/src/geometry/PolyUtil.js b/extlib/leaflet/src/geometry/PolyUtil.js
new file mode 100644
index 00000000..c5460709
--- /dev/null
+++ b/extlib/leaflet/src/geometry/PolyUtil.js
@@ -0,0 +1,55 @@
+/*
+ * L.PolyUtil contains utilify functions for polygons (clipping, etc.).
+ */
+
+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 min = bounds.min,
+ max = bounds.max,
+ 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;
+}; \ No newline at end of file