mapshaper 0.5.85 → 0.5.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/www/mapshaper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function () {
2
2
 
3
- var VERSION = "0.5.83";
3
+ var VERSION = "0.5.85";
4
4
 
5
5
 
6
6
  var utils = /*#__PURE__*/Object.freeze({
@@ -20121,10 +20121,10 @@ ${svg}
20121
20121
  // TODO: removed (replaced by flipped and rotated)
20122
20122
  // describe: 'use orientation=b for a rotated or flipped orientation'
20123
20123
  })
20124
- .option('flipped', {
20125
- type: 'flag',
20126
- describe: 'symbol is vertically flipped'
20127
- })
20124
+ // .option('flipped', {
20125
+ // type: 'flag',
20126
+ // describe: 'symbol is vertically flipped'
20127
+ // })
20128
20128
  .option('rotated', {
20129
20129
  type: 'flag',
20130
20130
  describe: 'symbol is rotated to a different orientation'
@@ -38231,71 +38231,31 @@ ${svg}
38231
38231
  return coords;
38232
38232
  }
38233
38233
 
38234
- function getMinorRadius(points) {
38235
- var innerAngle = 360 / points;
38236
- var pointAngle = getDefaultPointAngle(points);
38237
- var thetaA = Math.PI / 180 * innerAngle / 2;
38238
- var thetaB = Math.PI / 180 * pointAngle / 2;
38239
- var a = Math.tan(thetaB) / (Math.tan(thetaB) + Math.tan(thetaA));
38240
- var c = a / Math.cos(thetaA);
38241
- return c;
38242
- }
38243
-
38244
-
38245
- function getPointAngle(points, skip) {
38246
- var unitAngle = 360 / points;
38247
- var centerAngle = unitAngle * (skip + 1);
38248
- return 180 - centerAngle;
38249
- }
38250
-
38251
- function getDefaultPointAngle(points) {
38252
- var minSkip = 1;
38253
- var maxSkip = Math.ceil(points / 2) - 2;
38254
- var skip = Math.floor((maxSkip + minSkip) / 2);
38255
- return getPointAngle(points, skip);
38256
- }
38257
-
38258
- // sides: e.g. 5-pointed star has 10 sides
38259
- // radius: distance from center to point
38260
- //
38261
38234
  function getPolygonCoords(d) {
38262
- var radius = d.radius || d.length || d.r;
38235
+ var radius = d.radius || d.length || d.r,
38236
+ sides = +d.sides || getSidesByType(d.type),
38237
+ rotated = sides % 2 == 1,
38238
+ coords = [],
38239
+ angle, b;
38240
+
38263
38241
  if (radius > 0 === false) return null;
38264
- var type = d.type;
38265
- var sides = +d.sides || getDefaultSides(type);
38266
- var isStar = type == 'star';
38267
- if (isStar && d.points > 0) {
38268
- sides = d.points * 2;
38269
- }
38270
- var starRatio = isStar ? d.star_ratio || getMinorRadius(sides / 2) : 0;
38271
- if (isStar && (sides < 10 || sides % 2 !== 0)) {
38272
- stop(`Invalid number of points for a star (${sides / 2})`);
38273
- } else if (sides >= 3 === false) {
38242
+ if (sides >= 3 === false) {
38274
38243
  stop(`Invalid number of sides (${sides})`);
38275
38244
  }
38276
- var coords = [],
38277
- angle = 360 / sides,
38278
- b = isStar ? 1 : 0.5,
38279
- theta, even, len;
38280
38245
  if (d.orientation == 'b' || d.flipped || d.rotated) {
38281
- b = 0;
38246
+ rotated = !rotated;
38282
38247
  }
38248
+ b = rotated ? 0 : 0.5;
38283
38249
  for (var i=0; i<sides; i++) {
38284
- even = i % 2 == 0;
38285
- len = radius;
38286
- if (isStar && even) {
38287
- len *= starRatio;
38288
- }
38289
- theta = (i + b) * angle % 360;
38290
- coords.push(getPlanarSegmentEndpoint(0, 0, theta, len));
38250
+ angle = (i + b) / sides * 360;
38251
+ coords.push(getPlanarSegmentEndpoint(0, 0, angle, radius));
38291
38252
  }
38292
38253
  coords.push(coords[0].concat());
38293
38254
  return [coords];
38294
38255
  }
38295
38256
 
38296
- function getDefaultSides(type) {
38257
+ function getSidesByType(type) {
38297
38258
  return {
38298
- star: 10,
38299
38259
  circle: 72,
38300
38260
  triangle: 3,
38301
38261
  square: 4,
@@ -38308,6 +38268,52 @@ ${svg}
38308
38268
  }[type] || 4;
38309
38269
  }
38310
38270
 
38271
+ function getStarCoords(d) {
38272
+ var radius = d.radius || d.length || d.r,
38273
+ points = d.points || d.sides && d.sides / 2 || 5,
38274
+ sides = points * 2,
38275
+ minorRadius = getMinorRadius(points) * radius,
38276
+ b = d.orientation == 'b' || d.flipped || d.rotated ? 0 : 1,
38277
+ coords = [],
38278
+ angle, len;
38279
+
38280
+ if (radius > 0 === false) return null;
38281
+ if (points < 5) {
38282
+ stop(`Invalid number of points for a star (${points})`);
38283
+ }
38284
+ for (var i=0; i<sides; i++) {
38285
+ len = i % 2 == 0 ? minorRadius : radius;
38286
+ angle = (i + b) / sides * 360;
38287
+ coords.push(getPlanarSegmentEndpoint(0, 0, angle, len));
38288
+ }
38289
+ coords.push(coords[0].concat());
38290
+ return [coords];
38291
+ }
38292
+
38293
+ function getMinorRadius(points) {
38294
+ var innerAngle = 360 / points;
38295
+ var pointAngle = getDefaultPointAngle(points);
38296
+ var thetaA = Math.PI / 180 * innerAngle / 2;
38297
+ var thetaB = Math.PI / 180 * pointAngle / 2;
38298
+ var a = Math.tan(thetaB) / (Math.tan(thetaB) + Math.tan(thetaA));
38299
+ var c = a / Math.cos(thetaA);
38300
+ return c;
38301
+ }
38302
+
38303
+ function getDefaultPointAngle(points) {
38304
+ var minSkip = 1;
38305
+ var maxSkip = Math.ceil(points / 2) - 2;
38306
+ var skip = Math.floor((maxSkip + minSkip) / 2);
38307
+ return getPointAngle(points, skip);
38308
+ }
38309
+
38310
+ // skip: number of adjacent points to skip when drawing a segment
38311
+ function getPointAngle(points, skip) {
38312
+ var unitAngle = 360 / points;
38313
+ var centerAngle = unitAngle * (skip + 1);
38314
+ return 180 - centerAngle;
38315
+ }
38316
+
38311
38317
  // Returns GeoJSON MultiPolygon coords
38312
38318
  function getRingCoords(d) {
38313
38319
  var radii = parseRings(d.radii || '2');
@@ -38362,6 +38368,8 @@ ${svg}
38362
38368
  } else if (d.type == 'ring') {
38363
38369
  coords = getRingCoords(d);
38364
38370
  geojsonType = 'MultiPolygon';
38371
+ } else if (d.type == 'star') {
38372
+ coords = getStarCoords(d);
38365
38373
  } else {
38366
38374
  coords = getPolygonCoords(d);
38367
38375
  }