|
19 | 19 |
|
20 | 20 |
|
21 | 21 | (function() {
|
22 |
| - var $, Aitoff, Azimuthal, BBox, Balthasart, Behrmann, BlurFilter, Bubble, CEA, CantersModifiedSinusoidalI, Circle, CohenSutherland, Conic, Cylindrical, EckertIV, EquidistantAzimuthal, Equirectangular, Filter, GallPeters, GlowFilter, GoodeHomolosine, Hatano, HoboDyer, HtmlLabel, Icon, K, Kartograph, LAEA, LCC, LabeledBubble, LatLon, Line, LinearScale, LogScale, LonLat, Loximuthal, MapLayer, MapLayerPath, Mercator, Mollweide, NaturalEarth, Nicolosi, Orthographic, Path, PieChart, Proj, PseudoConic, PseudoCylindrical, QuantileScale, REbraces, REcomment_string, REfull, REmunged, Robinson, Satellite, Scale, Sinusoidal, SqrtScale, StackedBarChart, Stereographic, SvgLabel, Symbol, SymbolGroup, View, WagnerIV, WagnerV, Winkel3, drawPieChart, filter, hex2rgb, kartograph, log, map_layer_path_uid, munge, munged, parsedeclarations, resolve, restore, root, uid, warn, __point_in_polygon, __proj, __type, _base, _base1, _ref, _ref1, _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _ref16, _ref17, _ref18, _ref19, _ref2, _ref20, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, |
| 22 | + var $, Aitoff, Azimuthal, BBox, Balthasart, Behrmann, BlurFilter, Bubble, CEA, CantersModifiedSinusoidalI, Circle, CohenSutherland, Conic, Cylindrical, EckertIV, EquidistantAzimuthal, Equirectangular, Filter, GallPeters, GlowFilter, GoodeHomolosine, Hatano, HoboDyer, HtmlLabel, Icon, K, Kartograph, LAEA, LCC, LabeledBubble, LatLon, Line, LinearScale, LogScale, LonLat, Loximuthal, MapLayer, MapLayerPath, Mercator, Mollweide, NaturalEarth, Nicolosi, Orthographic, Path, PieChart, Proj, PseudoConic, PseudoCylindrical, QuantileScale, REbraces, REcomment_string, REfull, REmunged, Robinson, Satellite, Scale, Sinusoidal, SqrtScale, StackedBarChart, Stereographic, SvgLabel, Symbol, SymbolGroup, View, WagnerIV, WagnerV, Winkel3, drawPieChart, filter, hex2rgb, kartograph, log, map_layer_path_uid, munge, munged, parsedeclarations, resolve, restore, root, uid, warn, __area, __is_clockwise, __point_in_polygon, __proj, __type, _base, _base1, _ref, _ref1, _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _ref16, _ref17, _ref18, _ref19, _ref2, _ref20, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, |
23 | 23 | __hasProp = {}.hasOwnProperty,
|
24 | 24 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
25 | 25 | __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
1597 | 1597 | represents complex polygons (aka multi-polygons)
|
1598 | 1598 | */
|
1599 | 1599 | function Path(type, contours, closed) {
|
1600 |
| - var self; |
| 1600 | + var cnt, self, _i, _len; |
1601 | 1601 |
|
1602 | 1602 | if (closed == null) {
|
1603 | 1603 | closed = true;
|
1604 | 1604 | }
|
1605 | 1605 | self = this;
|
1606 | 1606 | self.type = type;
|
1607 |
| - self.contours = contours; |
| 1607 | + self.contours = []; |
| 1608 | + for (_i = 0, _len = contours.length; _i < _len; _i++) { |
| 1609 | + cnt = contours[_i]; |
| 1610 | + if (!__is_clockwise(cnt)) { |
| 1611 | + cnt.reverse(); |
| 1612 | + } |
| 1613 | + self.contours.push(cnt); |
| 1614 | + } |
1608 | 1615 | self.closed = closed;
|
1609 | 1616 | }
|
1610 | 1617 |
|
|
1649 | 1656 | };
|
1650 | 1657 |
|
1651 | 1658 | Path.prototype.area = function() {
|
1652 |
| - var area, cnt, i, me, _i, _j, _len, _ref5, _ref6; |
| 1659 | + var area, cnt, me, _i, _len, _ref5; |
1653 | 1660 |
|
1654 | 1661 | me = this;
|
1655 | 1662 | if (me.areas != null) {
|
|
1660 | 1667 | _ref5 = me.contours;
|
1661 | 1668 | for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
|
1662 | 1669 | cnt = _ref5[_i];
|
1663 |
| - area = 0; |
1664 |
| - for (i = _j = 0, _ref6 = cnt.length - 2; 0 <= _ref6 ? _j <= _ref6 : _j >= _ref6; i = 0 <= _ref6 ? ++_j : --_j) { |
1665 |
| - area += cnt[i][0] * cnt[i + 1][1] - cnt[i + 1][0] * cnt[i][1]; |
1666 |
| - } |
1667 |
| - area *= .5; |
1668 |
| - area = area; |
| 1670 | + area = __area(cnt); |
1669 | 1671 | me.areas.push(area);
|
1670 | 1672 | me._area += area;
|
1671 | 1673 | }
|
|
1685 | 1687 | cnt_orig = me.contours[i];
|
1686 | 1688 | cnt = [];
|
1687 | 1689 | l = cnt_orig.length;
|
| 1690 | + a = me.areas[i]; |
| 1691 | + k = a / area; |
| 1692 | + if (k === 0) { |
| 1693 | + continue; |
| 1694 | + } |
1688 | 1695 | for (j = _j = 0, _ref6 = l - 1; 0 <= _ref6 ? _j <= _ref6 : _j >= _ref6; j = 0 <= _ref6 ? ++_j : --_j) {
|
1689 | 1696 | p0 = cnt_orig[j];
|
1690 | 1697 | p1 = cnt_orig[(j + 1) % l];
|
|
1704 | 1711 | }
|
1705 | 1712 | }
|
1706 | 1713 | }
|
1707 |
| - a = me.areas[i]; |
1708 | 1714 | x = y = x_ = y_ = 0;
|
1709 | 1715 | l = cnt.length;
|
1710 | 1716 | _lengths = [];
|
|
1724 | 1730 | x += w * p0[0];
|
1725 | 1731 | y += w * p0[1];
|
1726 | 1732 | }
|
1727 |
| - k = a / area; |
1728 | 1733 | cx += x * k;
|
1729 | 1734 | cy += y * k;
|
1730 | 1735 | }
|
|
1929 | 1934 | return Math.abs(angle) >= pi;
|
1930 | 1935 | };
|
1931 | 1936 |
|
| 1937 | + __is_clockwise = function(contour) { |
| 1938 | + return __area(contour) > 0; |
| 1939 | + }; |
| 1940 | + |
| 1941 | + __area = function(contour) { |
| 1942 | + var i, n, s, x1, x2, y1, y2, _i; |
| 1943 | + |
| 1944 | + s = 0; |
| 1945 | + n = contour.length; |
| 1946 | + for (i = _i = 0; 0 <= n ? _i < n : _i > n; i = 0 <= n ? ++_i : --_i) { |
| 1947 | + x1 = contour[i][0]; |
| 1948 | + y1 = contour[i][1]; |
| 1949 | + x2 = contour[(i + 1) % n][0]; |
| 1950 | + y2 = contour[(i + 1) % n][1]; |
| 1951 | + s += x1 * y2 - x2 * y1; |
| 1952 | + } |
| 1953 | + return s *= 0.5; |
| 1954 | + }; |
| 1955 | + |
1932 | 1956 | /*
|
1933 | 1957 | kartograph - a svg mapping library
|
1934 | 1958 | Copyright (C) 2011 Gregor Aisch
|
|
0 commit comments