@antv/l7-layers 2.9.23 → 2.9.25

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.
Files changed (166) hide show
  1. package/es/Geometry/models/plane.d.ts +1 -0
  2. package/es/citybuliding/building.js +1 -1
  3. package/es/core/BaseLayer.js +10 -3
  4. package/es/core/interface.d.ts +26 -48
  5. package/es/core/interface.js +3 -0
  6. package/es/core/schema.d.ts +3 -3
  7. package/es/core/triangulation.d.ts +4 -3
  8. package/es/core/triangulation.js +54 -39
  9. package/es/heatmap/models/heatmap.js +1 -1
  10. package/es/image/models/image.js +7 -1
  11. package/es/line/index.js +4 -1
  12. package/es/line/models/arc.js +1 -1
  13. package/es/line/models/simpleLine.js +1 -1
  14. package/es/line/shaders/line_arc_vert.glsl +5 -3
  15. package/es/line/shaders/simple/simpleline_vert.glsl +1 -0
  16. package/es/plugins/FeatureScalePlugin.js +0 -1
  17. package/es/point/index.js +3 -1
  18. package/es/point/models/fill.js +5 -2
  19. package/es/point/models/fillmage.js +9 -3
  20. package/es/point/models/image.js +8 -2
  21. package/es/point/models/radar.js +2 -3
  22. package/es/point/models/tile.js +1 -1
  23. package/es/point/shaders/fill_vert.glsl +13 -6
  24. package/es/point/shaders/image/fillImage_vert.glsl +13 -5
  25. package/es/point/shaders/image_vert.glsl +17 -8
  26. package/es/polygon/index.js +4 -1
  27. package/es/raster/index.js +3 -1
  28. package/es/tile/manager/tileLayerManager.d.ts +3 -2
  29. package/es/tile/manager/tileLayerManager.js +5 -2
  30. package/es/tile/models/tileModel.js +4 -3
  31. package/es/tile/tileFactory/base.d.ts +1 -1
  32. package/es/tile/tileFactory/base.js +32 -5
  33. package/es/tile/tileFactory/vectorLayer.d.ts +3 -1
  34. package/es/tile/tileFactory/vectorLayer.js +22 -1
  35. package/es/tile/tileLayer/baseTileLayer.d.ts +1 -1
  36. package/es/tile/tileLayer/baseTileLayer.js +3 -2
  37. package/es/tile/utils.d.ts +2 -0
  38. package/es/tile/utils.js +5 -1
  39. package/lib/Geometry/index.js +114 -77
  40. package/lib/Geometry/models/billboard.js +232 -181
  41. package/lib/Geometry/models/index.js +18 -34
  42. package/lib/Geometry/models/plane.js +407 -278
  43. package/lib/Geometry/models/sprite.js +291 -189
  44. package/lib/canvas/index.js +101 -66
  45. package/lib/canvas/models/canvas.js +207 -140
  46. package/lib/canvas/models/index.js +12 -30
  47. package/lib/citybuliding/building.js +98 -63
  48. package/lib/citybuliding/models/build.js +192 -146
  49. package/lib/core/BaseLayer.js +1331 -809
  50. package/lib/core/BaseModel.js +457 -279
  51. package/lib/core/interface.js +40 -53
  52. package/lib/core/schema.js +21 -39
  53. package/lib/core/shape/Path.js +67 -79
  54. package/lib/core/shape/extrude.js +132 -91
  55. package/lib/core/triangulation.js +412 -213
  56. package/lib/earth/index.js +100 -62
  57. package/lib/earth/models/atmosphere.js +146 -112
  58. package/lib/earth/models/base.js +210 -150
  59. package/lib/earth/models/bloomsphere.js +146 -112
  60. package/lib/earth/utils.js +111 -91
  61. package/lib/heatmap/index.js +149 -92
  62. package/lib/heatmap/models/grid.js +118 -91
  63. package/lib/heatmap/models/grid3d.js +155 -123
  64. package/lib/heatmap/models/heatmap.js +475 -338
  65. package/lib/heatmap/models/hexagon.js +121 -92
  66. package/lib/heatmap/models/index.js +22 -37
  67. package/lib/heatmap/triangulation.js +31 -47
  68. package/lib/image/index.js +111 -74
  69. package/lib/image/models/dataImage.js +232 -174
  70. package/lib/image/models/image.js +175 -123
  71. package/lib/image/models/index.js +15 -32
  72. package/lib/index.js +263 -97
  73. package/lib/line/index.js +131 -83
  74. package/lib/line/models/arc.js +352 -237
  75. package/lib/line/models/arc_3d.js +334 -228
  76. package/lib/line/models/earthArc_3d.js +336 -228
  77. package/lib/line/models/great_circle.js +291 -200
  78. package/lib/line/models/half.js +286 -201
  79. package/lib/line/models/index.js +42 -50
  80. package/lib/line/models/line.js +428 -299
  81. package/lib/line/models/linearline.js +277 -203
  82. package/lib/line/models/simpleLine.js +239 -175
  83. package/lib/line/models/tile.js +348 -237
  84. package/lib/line/models/wall.js +327 -235
  85. package/lib/line/shaders/line_arc_vert.glsl +5 -3
  86. package/lib/line/shaders/simple/simpleline_vert.glsl +1 -0
  87. package/lib/mask/index.js +92 -59
  88. package/lib/mask/models/fill.js +134 -82
  89. package/lib/mask/models/index.js +12 -30
  90. package/lib/plugins/DataMappingPlugin.js +342 -224
  91. package/lib/plugins/DataSourcePlugin.js +102 -87
  92. package/lib/plugins/FeatureScalePlugin.js +330 -241
  93. package/lib/plugins/LayerAnimateStylePlugin.js +61 -55
  94. package/lib/plugins/LayerModelPlugin.js +80 -73
  95. package/lib/plugins/LayerStylePlugin.js +48 -51
  96. package/lib/plugins/LightingPlugin.js +80 -68
  97. package/lib/plugins/MultiPassRendererPlugin.js +91 -65
  98. package/lib/plugins/PixelPickingPlugin.js +150 -109
  99. package/lib/plugins/RegisterStyleAttributePlugin.js +110 -110
  100. package/lib/plugins/ShaderUniformPlugin.js +118 -99
  101. package/lib/plugins/UpdateModelPlugin.js +40 -47
  102. package/lib/plugins/UpdateStyleAttributePlugin.js +93 -75
  103. package/lib/point/index.js +226 -148
  104. package/lib/point/models/earthExtrude.js +279 -201
  105. package/lib/point/models/earthFill.js +287 -202
  106. package/lib/point/models/extrude.js +299 -203
  107. package/lib/point/models/fill.js +406 -273
  108. package/lib/point/models/fillmage.js +365 -252
  109. package/lib/point/models/image.js +241 -164
  110. package/lib/point/models/index.js +46 -52
  111. package/lib/point/models/normal.js +183 -134
  112. package/lib/point/models/radar.js +304 -212
  113. package/lib/point/models/simplePoint.js +194 -142
  114. package/lib/point/models/text.js +608 -385
  115. package/lib/point/models/tile.js +314 -223
  116. package/lib/point/shaders/fill_vert.glsl +13 -6
  117. package/lib/point/shaders/image/fillImage_vert.glsl +13 -5
  118. package/lib/point/shaders/image_vert.glsl +17 -8
  119. package/lib/point/shape/extrude.js +56 -52
  120. package/lib/polygon/index.js +154 -100
  121. package/lib/polygon/models/extrude.js +311 -223
  122. package/lib/polygon/models/fill.js +215 -153
  123. package/lib/polygon/models/index.js +46 -52
  124. package/lib/polygon/models/ocean.js +244 -173
  125. package/lib/polygon/models/tile.js +144 -100
  126. package/lib/polygon/models/water.js +222 -153
  127. package/lib/raster/buffers/triangulation.js +27 -40
  128. package/lib/raster/index.js +115 -74
  129. package/lib/raster/models/index.js +16 -33
  130. package/lib/raster/models/raster.js +178 -135
  131. package/lib/raster/raster.js +187 -132
  132. package/lib/tile/interface.js +4 -16
  133. package/lib/tile/manager/tileConfigManager.js +125 -86
  134. package/lib/tile/manager/tileLayerManager.js +314 -227
  135. package/lib/tile/manager/tilePickerManager.js +192 -123
  136. package/lib/tile/models/tileModel.js +71 -51
  137. package/lib/tile/tileFactory/base.js +433 -292
  138. package/lib/tile/tileFactory/index.js +51 -49
  139. package/lib/tile/tileFactory/line.js +65 -50
  140. package/lib/tile/tileFactory/point.js +65 -50
  141. package/lib/tile/tileFactory/polygon.js +65 -50
  142. package/lib/tile/tileFactory/raster.js +66 -54
  143. package/lib/tile/tileFactory/rasterData.js +88 -76
  144. package/lib/tile/tileFactory/rasterDataLayer.js +97 -62
  145. package/lib/tile/tileFactory/vectorLayer.js +169 -95
  146. package/lib/tile/tileLayer/baseTileLayer.js +420 -220
  147. package/lib/tile/tmsTileLayer.js +110 -67
  148. package/lib/tile/utils.js +113 -87
  149. package/lib/utils/blend.js +59 -79
  150. package/lib/utils/collision-index.js +107 -64
  151. package/lib/utils/dataMappingStyle.js +105 -60
  152. package/lib/utils/extrude_polyline.js +600 -398
  153. package/lib/utils/grid-index.js +163 -111
  154. package/lib/utils/layerData.js +130 -99
  155. package/lib/utils/multiPassRender.js +49 -41
  156. package/lib/utils/polylineNormal.js +148 -96
  157. package/lib/utils/simpleLine.js +100 -85
  158. package/lib/utils/symbol-layout.js +219 -116
  159. package/lib/utils/updateShape.js +15 -41
  160. package/lib/wind/index.js +109 -71
  161. package/lib/wind/models/index.js +12 -30
  162. package/lib/wind/models/utils.js +144 -105
  163. package/lib/wind/models/wind.js +333 -224
  164. package/lib/wind/models/windRender.js +329 -218
  165. package/lib/wind/models/windShader.js +23 -181
  166. package/package.json +7 -6
@@ -1,65 +1,96 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/utils/extrude_polyline.ts
20
- var extrude_polyline_exports = {};
21
- __export(extrude_polyline_exports, {
22
- computeMiter: () => computeMiter,
23
- computeNormal: () => computeNormal,
24
- default: () => ExtrudePolyline,
25
- direction: () => direction
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
26
7
  });
27
- module.exports = __toCommonJS(extrude_polyline_exports);
28
- var import_l7_utils = require("@antv/l7-utils");
29
- var import_gl_matrix = require("gl-matrix");
30
- var tmp = import_gl_matrix.vec2.create();
31
- var capEnd = import_gl_matrix.vec2.create();
32
- var lineA = import_gl_matrix.vec2.create();
33
- var lineB = import_gl_matrix.vec2.create();
34
- var tangent = import_gl_matrix.vec2.create();
8
+ exports.computeMiter = computeMiter;
9
+ exports.computeNormal = computeNormal;
10
+ exports.default = void 0;
11
+ exports.direction = direction;
12
+
13
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
14
+
15
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
16
+
17
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
18
+
19
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
20
+
21
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
22
+
23
+ var _l7Utils = require("@antv/l7-utils");
24
+
25
+ var _glMatrix = require("gl-matrix");
26
+
27
+ var tmp = _glMatrix.vec2.create();
28
+
29
+ var capEnd = _glMatrix.vec2.create();
30
+
31
+ var lineA = _glMatrix.vec2.create();
32
+
33
+ var lineB = _glMatrix.vec2.create();
34
+
35
+ var tangent = _glMatrix.vec2.create();
36
+
35
37
  function computeMiter(lineTangent, miter, start, end, halfThick) {
36
- import_gl_matrix.vec2.add(lineTangent, start, end);
37
- import_gl_matrix.vec2.normalize(lineTangent, lineTangent);
38
- miter = import_gl_matrix.vec2.fromValues(-lineTangent[1], lineTangent[0]);
39
- const tmpvec = import_gl_matrix.vec2.fromValues(-start[1], start[0]);
40
- return [halfThick / import_gl_matrix.vec2.dot(miter, tmpvec), miter];
38
+ _glMatrix.vec2.add(lineTangent, start, end);
39
+
40
+ _glMatrix.vec2.normalize(lineTangent, lineTangent);
41
+
42
+ miter = _glMatrix.vec2.fromValues(-lineTangent[1], lineTangent[0]);
43
+
44
+ var tmpvec = _glMatrix.vec2.fromValues(-start[1], start[0]);
45
+
46
+ return [halfThick / _glMatrix.vec2.dot(miter, tmpvec), miter];
41
47
  }
48
+
42
49
  function computeNormal(out, dir) {
43
- return import_gl_matrix.vec2.set(out, -dir[1], dir[0]);
50
+ return _glMatrix.vec2.set(out, -dir[1], dir[0]);
44
51
  }
52
+
45
53
  function direction(out, a, b) {
46
- import_gl_matrix.vec2.sub(out, a, b);
47
- import_gl_matrix.vec2.normalize(out, out);
54
+ _glMatrix.vec2.sub(out, a, b);
55
+
56
+ _glMatrix.vec2.normalize(out, out);
57
+
48
58
  return out;
49
59
  }
60
+
50
61
  function isPointEqual(a, b) {
51
62
  return a[0] === b[0] && a[1] === b[1];
52
63
  }
53
- var ExtrudePolyline = class {
54
- constructor(opts = {}) {
55
- this.lastFlip = -1;
56
- this.miter = import_gl_matrix.vec2.fromValues(0, 0);
57
- this.started = false;
58
- this.dash = false;
59
- this.totalDistance = 0;
60
- this.currentIndex = 0;
61
- this.join = opts.join || "miter";
62
- this.cap = opts.cap || "butt";
64
+
65
+ function getArrayUnique(matrix) {
66
+ var map = new Map();
67
+
68
+ for (var i = 0; i < matrix.length; i++) {
69
+ var key = matrix[0].toString() + '-' + matrix[1].toString();
70
+
71
+ if (map.get(key)) {
72
+ matrix.splice(i, 1);
73
+ i++;
74
+ } else {
75
+ map.set(key, key);
76
+ }
77
+ }
78
+
79
+ return matrix;
80
+ }
81
+
82
+ var ExtrudePolyline = /*#__PURE__*/function () {
83
+ function ExtrudePolyline() {
84
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
85
+ (0, _classCallCheck2.default)(this, ExtrudePolyline);
86
+ (0, _defineProperty2.default)(this, "lastFlip", -1);
87
+ (0, _defineProperty2.default)(this, "miter", _glMatrix.vec2.fromValues(0, 0));
88
+ (0, _defineProperty2.default)(this, "started", false);
89
+ (0, _defineProperty2.default)(this, "dash", false);
90
+ (0, _defineProperty2.default)(this, "totalDistance", 0);
91
+ (0, _defineProperty2.default)(this, "currentIndex", 0);
92
+ this.join = opts.join || 'miter';
93
+ this.cap = opts.cap || 'butt';
63
94
  this.miterLimit = opts.miterLimit || 10;
64
95
  this.thickness = opts.thickness || 1;
65
96
  this.dash = opts.dash || false;
@@ -71,381 +102,552 @@ var ExtrudePolyline = class {
71
102
  indexes: []
72
103
  };
73
104
  }
74
- simpleExtrude(points) {
75
- const complex = this.complex;
76
- if (points.length <= 1) {
77
- return complex;
78
- }
79
- this.lastFlip = -1;
80
- this.started = false;
81
- this.normal = null;
82
- this.totalDistance = 0;
83
- const total = points.length;
84
- let count = complex.startIndex;
85
- for (let i = 1; i < total; i++) {
86
- const last = points[i - 1];
87
- const cur = points[i];
88
- const next = i < points.length - 1 ? points[i + 1] : null;
89
- const amt = this.simpleSegment(complex, count, last, cur, next);
90
- count += amt;
91
- }
92
- if (this.dash) {
93
- for (let i = 0; i < complex.positions.length / 6; i++) {
94
- complex.positions[i * 6 + 5] = this.totalDistance;
105
+
106
+ (0, _createClass2.default)(ExtrudePolyline, [{
107
+ key: "simpleExtrude",
108
+ value: function simpleExtrude(points) {
109
+ var complex = this.complex;
110
+
111
+ if (points.length <= 1) {
112
+ return complex;
95
113
  }
96
- }
97
- complex.startIndex = complex.positions.length / 6;
98
- return complex;
99
- }
100
- simpleExtrude_gaode2(points, originPoints) {
101
- const complex = this.complex;
102
- if (points.length <= 1) {
114
+
115
+ this.lastFlip = -1;
116
+ this.started = false;
117
+ this.normal = null;
118
+ this.totalDistance = 0;
119
+ var total = points.length;
120
+ var count = complex.startIndex;
121
+
122
+ for (var i = 1; i < total; i++) {
123
+ var last = points[i - 1];
124
+ var cur = points[i];
125
+ var next = i < points.length - 1 ? points[i + 1] : null;
126
+ var amt = this.simpleSegment(complex, count, last, cur, next);
127
+ count += amt;
128
+ }
129
+
130
+ if (this.dash) {
131
+ for (var _i = 0; _i < complex.positions.length / 6; _i++) {
132
+ complex.positions[_i * 6 + 5] = this.totalDistance;
133
+ }
134
+ }
135
+
136
+ complex.startIndex = complex.positions.length / 6;
103
137
  return complex;
104
138
  }
105
- this.lastFlip = -1;
106
- this.started = false;
107
- this.normal = null;
108
- this.totalDistance = 0;
109
- const total = points.length;
110
- let count = complex.startIndex;
111
- for (let i = 1; i < total; i++) {
112
- const last = points[i - 1];
113
- last.push(originPoints[i - 1][2] ?? 0);
114
- const originLast = originPoints[i - 1];
115
- const cur = points[i];
116
- cur.push(originPoints[i][2] ?? 0);
117
- const originCur = originPoints[i];
118
- const next = i < points.length - 1 ? [...points[i + 1], originPoints[i + 1][2] ?? 0] : null;
119
- const originNext = i < originPoints.length - 1 ? originPoints[i + 1] : null;
120
- const amt = this.simpleSegment(complex, count, last, cur, next, originLast, originCur, originNext);
121
- count += amt;
122
- }
123
- if (this.dash) {
124
- for (let i = 0; i < complex.positions.length / 6; i++) {
125
- complex.positions[i * 6 + 5] = this.totalDistance;
139
+ }, {
140
+ key: "simpleExtrude_gaode2",
141
+ value: function simpleExtrude_gaode2(points, originPoints) {
142
+ var complex = this.complex;
143
+
144
+ if (points.length <= 1) {
145
+ return complex;
126
146
  }
127
- }
128
- complex.startIndex = complex.positions.length / 6;
129
- return complex;
130
- }
131
- extrude_gaode2(points, originPoints) {
132
- const complex = this.complex;
133
- if (points.length <= 1) {
147
+
148
+ this.lastFlip = -1;
149
+ this.started = false;
150
+ this.normal = null;
151
+ this.totalDistance = 0; // 去除数组里重复的点
152
+ // points = getArrayUnique(points);
153
+
154
+ var total = points.length;
155
+ var count = complex.startIndex;
156
+
157
+ for (var i = 1; i < total; i++) {
158
+ var _originPoints$, _originPoints$i$, _originPoints$2;
159
+
160
+ var last = points[i - 1];
161
+ last.push((_originPoints$ = originPoints[i - 1][2]) !== null && _originPoints$ !== void 0 ? _originPoints$ : 0); // @ts-ignore
162
+
163
+ var originLast = originPoints[i - 1];
164
+ var cur = points[i];
165
+ cur.push((_originPoints$i$ = originPoints[i][2]) !== null && _originPoints$i$ !== void 0 ? _originPoints$i$ : 0); // @ts-ignore
166
+
167
+ var originCur = originPoints[i];
168
+ var next = i < points.length - 1 ? [].concat((0, _toConsumableArray2.default)(points[i + 1]), [(_originPoints$2 = originPoints[i + 1][2]) !== null && _originPoints$2 !== void 0 ? _originPoints$2 : 0]) : null;
169
+ var originNext = i < originPoints.length - 1 ? originPoints[i + 1] : null;
170
+ var amt = this.simpleSegment(complex, count, // @ts-ignore
171
+ last, // @ts-ignore
172
+ cur, // @ts-ignore
173
+ next, // @ts-ignore
174
+ originLast, originCur, // @ts-ignore
175
+ originNext);
176
+ count += amt;
177
+ }
178
+
179
+ if (this.dash) {
180
+ for (var _i2 = 0; _i2 < complex.positions.length / 6; _i2++) {
181
+ complex.positions[_i2 * 6 + 5] = this.totalDistance;
182
+ }
183
+ }
184
+
185
+ complex.startIndex = complex.positions.length / 6;
134
186
  return complex;
135
187
  }
136
- this.lastFlip = -1;
137
- this.started = false;
138
- this.normal = null;
139
- this.totalDistance = 0;
140
- const total = points.length;
141
- let count = complex.startIndex;
142
- for (let i = 1; i < total; i++) {
143
- const last = points[i - 1];
144
- last.push(originPoints[i - 1][2] ?? 0);
145
- const originLast = originPoints[i - 1];
146
- const cur = points[i];
147
- cur.push(originPoints[i][2] ?? 0);
148
- const originCur = originPoints[i];
149
- const next = i < points.length - 1 ? [...points[i + 1], originPoints[i + 1][2] ?? 0] : null;
150
- const originNext = i < originPoints.length - 1 ? originPoints[i + 1] : null;
151
- const amt = this.segment_gaode2(complex, count, last, cur, next, originLast, originCur, originNext);
152
- count += amt;
153
- }
154
- if (this.dash) {
155
- for (let i = 0; i < complex.positions.length / 6; i++) {
156
- complex.positions[i * 6 + 5] = this.totalDistance;
188
+ }, {
189
+ key: "extrude_gaode2",
190
+ value: function extrude_gaode2(points, originPoints) {
191
+ var complex = this.complex;
192
+
193
+ if (points.length <= 1) {
194
+ return complex;
157
195
  }
158
- }
159
- complex.startIndex = complex.positions.length / 6;
160
- return complex;
161
- }
162
- extrude(points) {
163
- const complex = this.complex;
164
- if (points.length <= 1) {
196
+
197
+ this.lastFlip = -1;
198
+ this.started = false;
199
+ this.normal = null;
200
+ this.totalDistance = 0; // 去除数组里重复的点
201
+ // points = getArrayUnique(points);
202
+
203
+ var total = points.length;
204
+ var count = complex.startIndex;
205
+
206
+ for (var i = 1; i < total; i++) {
207
+ var _originPoints$3, _originPoints$i$2, _originPoints$4;
208
+
209
+ var last = points[i - 1];
210
+ last.push((_originPoints$3 = originPoints[i - 1][2]) !== null && _originPoints$3 !== void 0 ? _originPoints$3 : 0); // @ts-ignore
211
+
212
+ var originLast = originPoints[i - 1];
213
+ var cur = points[i];
214
+ cur.push((_originPoints$i$2 = originPoints[i][2]) !== null && _originPoints$i$2 !== void 0 ? _originPoints$i$2 : 0); // @ts-ignore
215
+
216
+ var originCur = originPoints[i];
217
+ var next = i < points.length - 1 ? [].concat((0, _toConsumableArray2.default)(points[i + 1]), [(_originPoints$4 = originPoints[i + 1][2]) !== null && _originPoints$4 !== void 0 ? _originPoints$4 : 0]) : null;
218
+ var originNext = i < originPoints.length - 1 ? originPoints[i + 1] : null;
219
+ var amt = this.segment_gaode2(complex, count, // @ts-ignore
220
+ last, // @ts-ignore
221
+ cur, // @ts-ignore
222
+ next, // @ts-ignore
223
+ originLast, originCur, // @ts-ignore
224
+ originNext);
225
+ count += amt;
226
+ }
227
+
228
+ if (this.dash) {
229
+ for (var _i3 = 0; _i3 < complex.positions.length / 6; _i3++) {
230
+ complex.positions[_i3 * 6 + 5] = this.totalDistance;
231
+ }
232
+ }
233
+
234
+ complex.startIndex = complex.positions.length / 6;
165
235
  return complex;
166
236
  }
167
- this.lastFlip = -1;
168
- this.started = false;
169
- this.normal = null;
170
- this.totalDistance = 0;
171
- const total = points.length;
172
- let count = complex.startIndex;
173
- for (let i = 1; i < total; i++) {
174
- const last = points[i - 1];
175
- const cur = points[i];
176
- const next = i < points.length - 1 ? points[i + 1] : null;
177
- const amt = this.segment(complex, count, last, cur, next);
178
- count += amt;
179
- }
180
- if (this.dash) {
181
- for (let i = 0; i < complex.positions.length / 6; i++) {
182
- complex.positions[i * 6 + 5] = this.totalDistance;
237
+ }, {
238
+ key: "extrude",
239
+ value: function extrude(points) {
240
+ var complex = this.complex;
241
+
242
+ if (points.length <= 1) {
243
+ return complex;
183
244
  }
184
- }
185
- complex.startIndex = complex.positions.length / 6;
186
- return complex;
187
- }
188
- simpleSegment(complex, index, last, cur, next) {
189
- let count = 0;
190
- const indices = complex.indices;
191
- const positions = complex.positions;
192
- const normals = complex.normals;
193
- const flatCur = (0, import_l7_utils.aProjectFlat)([cur[0], cur[1]]);
194
- const flatLast = (0, import_l7_utils.aProjectFlat)([last[0], last[1]]);
195
- direction(lineA, flatCur, flatLast);
196
- let segmentDistance = 0;
197
- if (this.dash) {
198
- segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
199
- this.totalDistance += segmentDistance;
200
- }
201
- if (!this.normal) {
202
- this.normal = import_gl_matrix.vec2.create();
203
- computeNormal(this.normal, lineA);
204
- }
205
- if (!this.started) {
206
- this.started = true;
207
- this.extrusions(positions, normals, last, this.normal, this.thickness, this.totalDistance - segmentDistance);
208
- }
209
- indices.push(index + 0, index + 1, index + 2);
210
- if (!next) {
211
- computeNormal(this.normal, lineA);
212
- this.extrusions(positions, normals, cur, this.normal, this.thickness, this.totalDistance);
213
- indices.push(...this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
214
- count += 2;
215
- } else {
216
- const flatNext = (0, import_l7_utils.aProjectFlat)([next[0], next[1]]);
217
- if (isPointEqual(flatCur, flatNext)) {
218
- import_gl_matrix.vec2.add(flatNext, flatCur, import_gl_matrix.vec2.normalize(flatNext, import_gl_matrix.vec2.subtract(flatNext, flatCur, flatLast)));
245
+
246
+ this.lastFlip = -1;
247
+ this.started = false;
248
+ this.normal = null;
249
+ this.totalDistance = 0; // 去除数组里重复的点
250
+ // points = getArrayUnique(points);
251
+
252
+ var total = points.length;
253
+ var count = complex.startIndex;
254
+
255
+ for (var i = 1; i < total; i++) {
256
+ var last = points[i - 1];
257
+ var cur = points[i];
258
+ var next = i < points.length - 1 ? points[i + 1] : null;
259
+ var amt = this.segment(complex, count, last, cur, next);
260
+ count += amt;
219
261
  }
220
- direction(lineB, flatNext, flatCur);
221
- const [miterLen, miter] = computeMiter(tangent, import_gl_matrix.vec2.create(), lineA, lineB, this.thickness);
222
- let flip = import_gl_matrix.vec2.dot(tangent, this.normal) < 0 ? -1 : 1;
223
- this.extrusions(positions, normals, cur, miter, miterLen, this.totalDistance);
224
- indices.push(...this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
225
- flip = -1;
226
- import_gl_matrix.vec2.copy(this.normal, miter);
227
- count += 2;
228
- this.lastFlip = flip;
229
- }
230
- return count;
231
- }
232
- segment_gaode2(complex, index, last, cur, next, originLast, originCur, originNext) {
233
- let count = 0;
234
- const indices = complex.indices;
235
- const positions = complex.positions;
236
- const normals = complex.normals;
237
- const capSquare = this.cap === "square";
238
- const joinBevel = this.join === "bevel";
239
- const flatCur = (0, import_l7_utils.aProjectFlat)([originCur[0], originCur[1]]);
240
- const flatLast = (0, import_l7_utils.aProjectFlat)([originLast[0], originLast[1]]);
241
- direction(lineA, cur, last);
242
- let segmentDistance = 0;
243
- if (this.dash) {
244
- segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
245
- this.totalDistance += segmentDistance;
246
- }
247
- if (!this.normal) {
248
- this.normal = import_gl_matrix.vec2.create();
249
- computeNormal(this.normal, lineA);
250
- }
251
- if (!this.started) {
252
- this.started = true;
253
- if (capSquare) {
254
- const out1 = import_gl_matrix.vec2.create();
255
- const out2 = import_gl_matrix.vec2.create();
256
- import_gl_matrix.vec2.add(out1, this.normal, lineA);
257
- import_gl_matrix.vec2.add(out2, this.normal, lineA);
258
- normals.push(out2[0], out2[1], 0);
259
- normals.push(out1[0], out1[1], 0);
260
- positions.push(last[0], last[1], last[2] | 0, this.totalDistance - segmentDistance, -this.thickness, last[2] | 0);
261
- this.complex.indexes.push(this.currentIndex);
262
- positions.push(last[0], last[1], last[2] | 0, this.totalDistance - segmentDistance, this.thickness, last[2] | 0);
263
- this.complex.indexes.push(this.currentIndex);
264
- this.currentIndex++;
265
- } else {
266
- this.extrusions(positions, normals, last, this.normal, this.thickness, this.totalDistance - segmentDistance);
262
+
263
+ if (this.dash) {
264
+ for (var _i4 = 0; _i4 < complex.positions.length / 6; _i4++) {
265
+ complex.positions[_i4 * 6 + 5] = this.totalDistance;
266
+ }
267
267
  }
268
+
269
+ complex.startIndex = complex.positions.length / 6;
270
+ return complex;
268
271
  }
269
- indices.push(index + 0, index + 1, index + 2);
270
- if (!next) {
271
- computeNormal(this.normal, lineA);
272
- if (capSquare) {
273
- const out1 = import_gl_matrix.vec2.create();
274
- const out2 = import_gl_matrix.vec2.create();
275
- import_gl_matrix.vec2.sub(out2, lineA, this.normal);
276
- import_gl_matrix.vec2.add(out1, lineA, this.normal);
277
- normals.push(out2[0], out2[1], 0);
278
- normals.push(out1[0], out1[1], 0);
279
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness, cur[2] | 0);
280
- this.complex.indexes.push(this.currentIndex);
281
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness, cur[2] | 0);
282
- this.complex.indexes.push(this.currentIndex);
283
- this.currentIndex++;
284
- } else {
285
- this.extrusions(positions, normals, cur, this.normal, this.thickness, this.totalDistance);
272
+ }, {
273
+ key: "simpleSegment",
274
+ value: function simpleSegment(complex, index, last, cur, next) {
275
+ var count = 0;
276
+ var indices = complex.indices;
277
+ var positions = complex.positions;
278
+ var normals = complex.normals;
279
+ var flatCur = (0, _l7Utils.aProjectFlat)([cur[0], cur[1]]);
280
+ var flatLast = (0, _l7Utils.aProjectFlat)([last[0], last[1]]); // @ts-ignore
281
+
282
+ direction(lineA, flatCur, flatLast);
283
+ var segmentDistance = 0;
284
+
285
+ if (this.dash) {
286
+ // @ts-ignore
287
+ segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
288
+ this.totalDistance += segmentDistance;
286
289
  }
287
- indices.push(...this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
288
- count += 2;
289
- } else {
290
- if (isPointEqual(cur, next)) {
291
- import_gl_matrix.vec2.add(next, cur, import_gl_matrix.vec2.normalize(next, import_gl_matrix.vec2.subtract(next, cur, last)));
290
+
291
+ if (!this.normal) {
292
+ this.normal = _glMatrix.vec2.create();
293
+ computeNormal(this.normal, lineA);
292
294
  }
293
- direction(lineB, next, cur);
294
- const [miterLen, miter] = computeMiter(tangent, import_gl_matrix.vec2.create(), lineA, lineB, this.thickness);
295
- let flip = import_gl_matrix.vec2.dot(tangent, this.normal) < 0 ? -1 : 1;
296
- let bevel = joinBevel;
297
- if (!bevel && this.join === "miter") {
298
- const limit = miterLen;
299
- if (limit > this.miterLimit) {
300
- bevel = true;
301
- }
295
+
296
+ if (!this.started) {
297
+ this.started = true;
298
+ this.extrusions(positions, normals, last, this.normal, this.thickness, this.totalDistance - segmentDistance);
302
299
  }
303
- if (bevel) {
304
- normals.push(this.normal[0], this.normal[1], 0);
305
- normals.push(miter[0], miter[1], 0);
306
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, -this.thickness * flip, cur[2] | 0);
307
- this.complex.indexes.push(this.currentIndex);
308
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness * flip, cur[2] | 0);
309
- this.complex.indexes.push(this.currentIndex);
310
- this.currentIndex++;
311
- indices.push(...this.lastFlip !== -flip ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
312
- indices.push(index + 2, index + 3, index + 4);
313
- computeNormal(tmp, lineB);
314
- import_gl_matrix.vec2.copy(this.normal, tmp);
315
- normals.push(this.normal[0], this.normal[1], 0);
316
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, -this.thickness * flip, cur[2] | 0);
317
- this.complex.indexes.push(this.currentIndex);
318
- this.currentIndex++;
319
- count += 3;
300
+
301
+ indices.push(index + 0, index + 1, index + 2);
302
+
303
+ if (!next) {
304
+ computeNormal(this.normal, lineA);
305
+ this.extrusions(positions, normals, cur, this.normal, this.thickness, this.totalDistance);
306
+ indices.push.apply(indices, (0, _toConsumableArray2.default)(this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]));
307
+ count += 2;
320
308
  } else {
309
+ var flatNext = (0, _l7Utils.aProjectFlat)([next[0], next[1]]);
310
+
311
+ if (isPointEqual(flatCur, flatNext)) {
312
+ _glMatrix.vec2.add(flatNext, flatCur, _glMatrix.vec2.normalize(flatNext, _glMatrix.vec2.subtract(flatNext, flatCur, flatLast)));
313
+ }
314
+
315
+ direction(lineB, flatNext, flatCur); // stores tangent & miter
316
+
317
+ var _computeMiter = computeMiter(tangent, _glMatrix.vec2.create(), lineA, lineB, this.thickness),
318
+ _computeMiter2 = (0, _slicedToArray2.default)(_computeMiter, 2),
319
+ miterLen = _computeMiter2[0],
320
+ miter = _computeMiter2[1]; // normal(tmp, lineA)
321
+ // get orientation
322
+
323
+
324
+ var flip = _glMatrix.vec2.dot(tangent, this.normal) < 0 ? -1 : 1;
321
325
  this.extrusions(positions, normals, cur, miter, miterLen, this.totalDistance);
322
- indices.push(...this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
323
- flip = -1;
324
- import_gl_matrix.vec2.copy(this.normal, miter);
326
+ indices.push.apply(indices, (0, _toConsumableArray2.default)(this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]));
327
+ flip = -1; // the miter is now the normal for our next join
328
+
329
+ _glMatrix.vec2.copy(this.normal, miter);
330
+
325
331
  count += 2;
332
+ this.lastFlip = flip;
326
333
  }
327
- this.lastFlip = flip;
328
- }
329
- return count;
330
- }
331
- segment(complex, index, last, cur, next) {
332
- let count = 0;
333
- const indices = complex.indices;
334
- const positions = complex.positions;
335
- const normals = complex.normals;
336
- const capSquare = this.cap === "square";
337
- const joinBevel = this.join === "bevel";
338
- const flatCur = (0, import_l7_utils.aProjectFlat)([cur[0], cur[1]]);
339
- const flatLast = (0, import_l7_utils.aProjectFlat)([last[0], last[1]]);
340
- direction(lineA, flatCur, flatLast);
341
- let segmentDistance = 0;
342
- if (this.dash) {
343
- segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
344
- this.totalDistance += segmentDistance;
345
- }
346
- if (!this.normal) {
347
- this.normal = import_gl_matrix.vec2.create();
348
- computeNormal(this.normal, lineA);
334
+
335
+ return count;
349
336
  }
350
- if (!this.started) {
351
- this.started = true;
352
- if (capSquare) {
353
- const out1 = import_gl_matrix.vec2.create();
354
- const out2 = import_gl_matrix.vec2.create();
355
- import_gl_matrix.vec2.add(out1, this.normal, lineA);
356
- import_gl_matrix.vec2.add(out2, this.normal, lineA);
357
- normals.push(out2[0], out2[1], 0);
358
- normals.push(out1[0], out1[1], 0);
359
- positions.push(last[0], last[1], last[2] | 0, this.totalDistance - segmentDistance, -this.thickness, last[2] | 0);
360
- this.complex.indexes.push(this.currentIndex);
361
- positions.push(last[0], last[1], last[2] | 0, this.totalDistance - segmentDistance, this.thickness, last[2] | 0);
362
- this.complex.indexes.push(this.currentIndex);
363
- this.currentIndex++;
337
+ }, {
338
+ key: "segment_gaode2",
339
+ value: function segment_gaode2(complex, index, last, cur, next, originLast, originCur, originNext) {
340
+ var count = 0;
341
+ var indices = complex.indices;
342
+ var positions = complex.positions;
343
+ var normals = complex.normals;
344
+ var capSquare = this.cap === 'square';
345
+ var joinBevel = this.join === 'bevel';
346
+ var flatCur = (0, _l7Utils.aProjectFlat)([originCur[0], originCur[1]]);
347
+ var flatLast = (0, _l7Utils.aProjectFlat)([originLast[0], originLast[1]]); // @ts-ignore
348
+
349
+ direction(lineA, cur, last);
350
+ var segmentDistance = 0;
351
+
352
+ if (this.dash) {
353
+ // @ts-ignore
354
+ segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
355
+ this.totalDistance += segmentDistance;
356
+ }
357
+
358
+ if (!this.normal) {
359
+ this.normal = _glMatrix.vec2.create();
360
+ computeNormal(this.normal, lineA);
361
+ }
362
+
363
+ if (!this.started) {
364
+ this.started = true; // if the end cap is type square, we can just push the verts out a bit
365
+
366
+ if (capSquare) {
367
+ // vec2.scaleAndAdd(capEnd, last, lineA, -this.thickness);
368
+ var out1 = _glMatrix.vec2.create();
369
+
370
+ var out2 = _glMatrix.vec2.create();
371
+
372
+ _glMatrix.vec2.add(out1, this.normal, lineA);
373
+
374
+ _glMatrix.vec2.add(out2, this.normal, lineA);
375
+
376
+ normals.push(out2[0], out2[1], 0);
377
+ normals.push(out1[0], out1[1], 0);
378
+ positions.push(last[0], last[1], last[2] | 0, this.totalDistance - segmentDistance, -this.thickness, last[2] | 0);
379
+ this.complex.indexes.push(this.currentIndex);
380
+ positions.push(last[0], last[1], last[2] | 0, this.totalDistance - segmentDistance, this.thickness, last[2] | 0);
381
+ this.complex.indexes.push(this.currentIndex);
382
+ this.currentIndex++;
383
+ } else {
384
+ this.extrusions(positions, normals, last, this.normal, this.thickness, this.totalDistance - segmentDistance);
385
+ }
386
+ }
387
+
388
+ indices.push(index + 0, index + 1, index + 2);
389
+
390
+ if (!next) {
391
+ computeNormal(this.normal, lineA);
392
+
393
+ if (capSquare) {
394
+ var _out = _glMatrix.vec2.create();
395
+
396
+ var _out2 = _glMatrix.vec2.create();
397
+
398
+ _glMatrix.vec2.sub(_out2, lineA, this.normal);
399
+
400
+ _glMatrix.vec2.add(_out, lineA, this.normal);
401
+
402
+ normals.push(_out2[0], _out2[1], 0);
403
+ normals.push(_out[0], _out[1], 0);
404
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness, cur[2] | 0);
405
+ this.complex.indexes.push(this.currentIndex);
406
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness, cur[2] | 0);
407
+ this.complex.indexes.push(this.currentIndex);
408
+ this.currentIndex++;
409
+ } else {
410
+ this.extrusions(positions, normals, cur, this.normal, this.thickness, this.totalDistance);
411
+ }
412
+
413
+ indices.push.apply(indices, (0, _toConsumableArray2.default)(this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]));
414
+ count += 2;
364
415
  } else {
365
- this.extrusions(positions, normals, last, this.normal, this.thickness, this.totalDistance - segmentDistance);
416
+ // @ts-ignore
417
+ if (isPointEqual(cur, next)) {
418
+ _glMatrix.vec2.add( // @ts-ignore
419
+ next, // @ts-ignore
420
+ cur, _glMatrix.vec2.normalize( // @ts-ignore
421
+ next, // @ts-ignore
422
+ _glMatrix.vec2.subtract(next, cur, last)));
423
+ } // @ts-ignore
424
+
425
+
426
+ direction(lineB, next, cur); // stores tangent & miter
427
+
428
+ var _computeMiter3 = computeMiter(tangent, _glMatrix.vec2.create(), lineA, lineB, this.thickness),
429
+ _computeMiter4 = (0, _slicedToArray2.default)(_computeMiter3, 2),
430
+ miterLen = _computeMiter4[0],
431
+ miter = _computeMiter4[1]; // normal(tmp, lineA)
432
+ // get orientation
433
+
434
+
435
+ var flip = _glMatrix.vec2.dot(tangent, this.normal) < 0 ? -1 : 1;
436
+ var bevel = joinBevel;
437
+
438
+ if (!bevel && this.join === 'miter') {
439
+ var limit = miterLen;
440
+
441
+ if (limit > this.miterLimit) {
442
+ bevel = true;
443
+ }
444
+ }
445
+
446
+ if (bevel) {
447
+ normals.push(this.normal[0], this.normal[1], 0);
448
+ normals.push(miter[0], miter[1], 0);
449
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, -this.thickness * flip, cur[2] | 0);
450
+ this.complex.indexes.push(this.currentIndex);
451
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness * flip, cur[2] | 0);
452
+ this.complex.indexes.push(this.currentIndex);
453
+ this.currentIndex++;
454
+ indices.push.apply(indices, (0, _toConsumableArray2.default)(this.lastFlip !== -flip ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3])); // now add the bevel triangle
455
+
456
+ indices.push(index + 2, index + 3, index + 4);
457
+ computeNormal(tmp, lineB);
458
+
459
+ _glMatrix.vec2.copy(this.normal, tmp); // store normal for next round
460
+
461
+
462
+ normals.push(this.normal[0], this.normal[1], 0);
463
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, -this.thickness * flip, cur[2] | 0);
464
+ this.complex.indexes.push(this.currentIndex);
465
+ this.currentIndex++;
466
+ count += 3;
467
+ } else {
468
+ this.extrusions(positions, normals, cur, miter, miterLen, this.totalDistance);
469
+ indices.push.apply(indices, (0, _toConsumableArray2.default)(this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]));
470
+ flip = -1; // the miter is now the normal for our next join
471
+
472
+ _glMatrix.vec2.copy(this.normal, miter);
473
+
474
+ count += 2;
475
+ }
476
+
477
+ this.lastFlip = flip;
366
478
  }
479
+
480
+ return count;
367
481
  }
368
- indices.push(index + 0, index + 1, index + 2);
369
- if (!next) {
370
- computeNormal(this.normal, lineA);
371
- if (capSquare) {
372
- const out1 = import_gl_matrix.vec2.create();
373
- const out2 = import_gl_matrix.vec2.create();
374
- import_gl_matrix.vec2.sub(out2, lineA, this.normal);
375
- import_gl_matrix.vec2.add(out1, lineA, this.normal);
376
- normals.push(out2[0], out2[1], 0);
377
- normals.push(out1[0], out1[1], 0);
378
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness, cur[2] | 0);
379
- this.complex.indexes.push(this.currentIndex);
380
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness, cur[2] | 0);
381
- this.complex.indexes.push(this.currentIndex);
382
- this.currentIndex++;
383
- } else {
384
- this.extrusions(positions, normals, cur, this.normal, this.thickness, this.totalDistance);
482
+ }, {
483
+ key: "segment",
484
+ value: function segment(complex, index, last, cur, next) {
485
+ var count = 0;
486
+ var indices = complex.indices;
487
+ var positions = complex.positions;
488
+ var normals = complex.normals;
489
+ var capSquare = this.cap === 'square';
490
+ var joinBevel = this.join === 'bevel';
491
+ var flatCur = (0, _l7Utils.aProjectFlat)([cur[0], cur[1]]);
492
+ var flatLast = (0, _l7Utils.aProjectFlat)([last[0], last[1]]); // @ts-ignore
493
+
494
+ direction(lineA, flatCur, flatLast);
495
+ var segmentDistance = 0;
496
+
497
+ if (this.dash) {
498
+ // @ts-ignore
499
+ segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
500
+ this.totalDistance += segmentDistance;
385
501
  }
386
- indices.push(...this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
387
- count += 2;
388
- } else {
389
- const flatNext = (0, import_l7_utils.aProjectFlat)([next[0], next[1]]);
390
- if (isPointEqual(flatCur, flatNext)) {
391
- import_gl_matrix.vec2.add(flatNext, flatCur, import_gl_matrix.vec2.normalize(flatNext, import_gl_matrix.vec2.subtract(flatNext, flatCur, flatLast)));
502
+
503
+ if (!this.normal) {
504
+ this.normal = _glMatrix.vec2.create();
505
+ computeNormal(this.normal, lineA);
392
506
  }
393
- direction(lineB, flatNext, flatCur);
394
- const [miterLen, miter] = computeMiter(tangent, import_gl_matrix.vec2.create(), lineA, lineB, this.thickness);
395
- let flip = import_gl_matrix.vec2.dot(tangent, this.normal) < 0 ? -1 : 1;
396
- let bevel = joinBevel;
397
- if (!bevel && this.join === "miter") {
398
- const limit = miterLen;
399
- if (limit > this.miterLimit) {
400
- bevel = true;
507
+
508
+ if (!this.started) {
509
+ this.started = true; // if the end cap is type square, we can just push the verts out a bit
510
+
511
+ if (capSquare) {
512
+ // vec2.scaleAndAdd(capEnd, last, lineA, -this.thickness);
513
+ var out1 = _glMatrix.vec2.create();
514
+
515
+ var out2 = _glMatrix.vec2.create();
516
+
517
+ _glMatrix.vec2.add(out1, this.normal, lineA);
518
+
519
+ _glMatrix.vec2.add(out2, this.normal, lineA);
520
+
521
+ normals.push(out2[0], out2[1], 0);
522
+ normals.push(out1[0], out1[1], 0);
523
+ positions.push(last[0], last[1], last[2] | 0, this.totalDistance - segmentDistance, -this.thickness, last[2] | 0);
524
+ this.complex.indexes.push(this.currentIndex);
525
+ positions.push(last[0], last[1], last[2] | 0, this.totalDistance - segmentDistance, this.thickness, last[2] | 0);
526
+ this.complex.indexes.push(this.currentIndex);
527
+ this.currentIndex++; // this.extrusions(positions, normals, last, out, this.thickness);
528
+ // last = capEnd;
529
+ } else {
530
+ this.extrusions(positions, normals, last, this.normal, this.thickness, this.totalDistance - segmentDistance);
401
531
  }
402
532
  }
403
- if (bevel) {
404
- normals.push(this.normal[0], this.normal[1], 0);
405
- normals.push(miter[0], miter[1], 0);
406
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, -this.thickness * flip, cur[2] | 0);
407
- this.complex.indexes.push(this.currentIndex);
408
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness * flip, cur[2] | 0);
409
- this.complex.indexes.push(this.currentIndex);
410
- this.currentIndex++;
411
- indices.push(...this.lastFlip !== -flip ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
412
- indices.push(index + 2, index + 3, index + 4);
413
- computeNormal(tmp, lineB);
414
- import_gl_matrix.vec2.copy(this.normal, tmp);
415
- normals.push(this.normal[0], this.normal[1], 0);
416
- positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, -this.thickness * flip, cur[2] | 0);
417
- this.complex.indexes.push(this.currentIndex);
418
- this.currentIndex++;
419
- count += 3;
420
- } else {
421
- this.extrusions(positions, normals, cur, miter, miterLen, this.totalDistance);
422
- indices.push(...this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
423
- flip = -1;
424
- import_gl_matrix.vec2.copy(this.normal, miter);
533
+
534
+ indices.push(index + 0, index + 1, index + 2);
535
+
536
+ if (!next) {
537
+ computeNormal(this.normal, lineA);
538
+
539
+ if (capSquare) {
540
+ // vec2.scaleAndAdd(capEnd, cur, lineA, this.thickness);
541
+ // cur = capEnd;
542
+ var _out3 = _glMatrix.vec2.create();
543
+
544
+ var _out4 = _glMatrix.vec2.create();
545
+
546
+ _glMatrix.vec2.sub(_out4, lineA, this.normal);
547
+
548
+ _glMatrix.vec2.add(_out3, lineA, this.normal); // this.extrusions(positions, normals, cur, out, this.thickness);
549
+
550
+
551
+ normals.push(_out4[0], _out4[1], 0);
552
+ normals.push(_out3[0], _out3[1], 0);
553
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness, cur[2] | 0);
554
+ this.complex.indexes.push(this.currentIndex);
555
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness, cur[2] | 0);
556
+ this.complex.indexes.push(this.currentIndex);
557
+ this.currentIndex++;
558
+ } else {
559
+ this.extrusions(positions, normals, cur, this.normal, this.thickness, this.totalDistance);
560
+ } // this.extrusions(positions, normals, cur, this.normal, this.thickness);
561
+
562
+
563
+ indices.push.apply(indices, (0, _toConsumableArray2.default)(this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]));
425
564
  count += 2;
565
+ } else {
566
+ var flatNext = (0, _l7Utils.aProjectFlat)([next[0], next[1]]);
567
+
568
+ if (isPointEqual(flatCur, flatNext)) {
569
+ _glMatrix.vec2.add(flatNext, flatCur, _glMatrix.vec2.normalize(flatNext, _glMatrix.vec2.subtract(flatNext, flatCur, flatLast)));
570
+ }
571
+
572
+ direction(lineB, flatNext, flatCur); // stores tangent & miter
573
+
574
+ var _computeMiter5 = computeMiter(tangent, _glMatrix.vec2.create(), lineA, lineB, this.thickness),
575
+ _computeMiter6 = (0, _slicedToArray2.default)(_computeMiter5, 2),
576
+ miterLen = _computeMiter6[0],
577
+ miter = _computeMiter6[1]; // normal(tmp, lineA)
578
+ // get orientation
579
+
580
+
581
+ var flip = _glMatrix.vec2.dot(tangent, this.normal) < 0 ? -1 : 1;
582
+ var bevel = joinBevel;
583
+
584
+ if (!bevel && this.join === 'miter') {
585
+ var limit = miterLen;
586
+
587
+ if (limit > this.miterLimit) {
588
+ bevel = true;
589
+ }
590
+ }
591
+
592
+ if (bevel) {
593
+ normals.push(this.normal[0], this.normal[1], 0);
594
+ normals.push(miter[0], miter[1], 0);
595
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, -this.thickness * flip, cur[2] | 0);
596
+ this.complex.indexes.push(this.currentIndex);
597
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, this.thickness * flip, cur[2] | 0);
598
+ this.complex.indexes.push(this.currentIndex);
599
+ this.currentIndex++;
600
+ indices.push.apply(indices, (0, _toConsumableArray2.default)(this.lastFlip !== -flip ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3])); // now add the bevel triangle
601
+
602
+ indices.push(index + 2, index + 3, index + 4);
603
+ computeNormal(tmp, lineB);
604
+
605
+ _glMatrix.vec2.copy(this.normal, tmp); // store normal for next round
606
+
607
+
608
+ normals.push(this.normal[0], this.normal[1], 0);
609
+ positions.push(cur[0], cur[1], cur[2] | 0, this.totalDistance, -this.thickness * flip, cur[2] | 0);
610
+ this.complex.indexes.push(this.currentIndex);
611
+ this.currentIndex++;
612
+ count += 3;
613
+ } else {
614
+ this.extrusions(positions, normals, cur, miter, miterLen, this.totalDistance);
615
+ indices.push.apply(indices, (0, _toConsumableArray2.default)(this.lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]));
616
+ flip = -1; // the miter is now the normal for our next join
617
+
618
+ _glMatrix.vec2.copy(this.normal, miter);
619
+
620
+ count += 2;
621
+ }
622
+
623
+ this.lastFlip = flip;
426
624
  }
427
- this.lastFlip = flip;
625
+
626
+ return count;
428
627
  }
429
- return count;
430
- }
431
- extrusions(positions, normals, point, normal, thickness, distanceRadio) {
432
- normals.push(normal[0], normal[1], 0);
433
- normals.push(normal[0], normal[1], 0);
434
- positions.push(point[0], point[1], point[2] | 0, distanceRadio, -thickness, point[2] | 0);
435
- this.complex.indexes.push(this.currentIndex);
436
- positions.push(point[0], point[1], point[2] | 0, distanceRadio, thickness, point[2] | 0);
437
- this.complex.indexes.push(this.currentIndex);
438
- this.currentIndex++;
439
- }
440
- lineSegmentDistance(b1, a1) {
441
- const dx = a1[0] - b1[0];
442
- const dy = a1[1] - b1[1];
443
- return Math.sqrt(dx * dx + dy * dy);
444
- }
445
- };
446
- // Annotate the CommonJS export names for ESM import in node:
447
- 0 && (module.exports = {
448
- computeMiter,
449
- computeNormal,
450
- direction
451
- });
628
+ }, {
629
+ key: "extrusions",
630
+ value: function extrusions(positions, normals, point, // 顶点
631
+ normal, // 法向量
632
+ thickness, // 高度
633
+ distanceRadio) {
634
+ normals.push(normal[0], normal[1], 0);
635
+ normals.push(normal[0], normal[1], 0);
636
+ positions.push(point[0], point[1], point[2] | 0, distanceRadio, -thickness, point[2] | 0);
637
+ this.complex.indexes.push(this.currentIndex);
638
+ positions.push(point[0], point[1], point[2] | 0, distanceRadio, thickness, point[2] | 0);
639
+ this.complex.indexes.push(this.currentIndex);
640
+ this.currentIndex++;
641
+ }
642
+ }, {
643
+ key: "lineSegmentDistance",
644
+ value: function lineSegmentDistance(b1, a1) {
645
+ var dx = a1[0] - b1[0];
646
+ var dy = a1[1] - b1[1];
647
+ return Math.sqrt(dx * dx + dy * dy);
648
+ }
649
+ }]);
650
+ return ExtrudePolyline;
651
+ }();
652
+
653
+ exports.default = ExtrudePolyline;