plotboilerplate 1.20.0 → 1.20.1

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/README.md CHANGED
@@ -542,6 +542,7 @@ new MouseHandler(document.getElementById("mycanvas"))
542
542
  - [jburkardt](https://people.sc.fsu.edu/~jburkardt/data/obj/obj.html "jburkardt") for the obj test files.
543
543
  - [@veltman](https://noahveltman.com/) for the awesome [geometric skeletonization article](https://observablehq.com/@veltman/centerline-labeling)
544
544
  - [girih-tiles-spatial.jpg from Lund University, Architecture, Spatial Experiments, 2016.](https://spatialexperiments.wordpress.com/2016/09/19/islamic-geometry/girih-tiles-4/)
545
+ - [https://javascript.plainenglish.io/june-3-parsing-and-validating-svg-paths-with-regex-7bd0e245115] Josh Frank's regular expression for parsing SVG path data.
545
546
 
546
547
  ## Todos
547
548
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plotboilerplate",
3
- "version": "1.20.0",
3
+ "version": "1.20.1",
4
4
  "description": "A simple javascript plotting boilerplate for 2d stuff.",
5
5
  "private": false,
6
6
  "main": "src/cjs/index.js",
@@ -9,7 +9,8 @@
9
9
  * @author Ikaros Kappler
10
10
  * @date 2022-11-06
11
11
  * @modified 2022-12-21 (winter solstice) Porting this to Typescript.
12
- * @version 0.0.1-alpha
12
+ * @modified 2023-01-17 Handling multiple parameter sets now.
13
+ * @version 0.0.2-alpha
13
14
  **/
14
15
  import { CubicBezierCurve } from "../../../CubicBezierCurve";
15
16
  import { Line } from "../../../Line";
@@ -10,7 +10,8 @@
10
10
  * @author Ikaros Kappler
11
11
  * @date 2022-11-06
12
12
  * @modified 2022-12-21 (winter solstice) Porting this to Typescript.
13
- * @version 0.0.1-alpha
13
+ * @modified 2023-01-17 Handling multiple parameter sets now.
14
+ * @version 0.0.2-alpha
14
15
  **/
15
16
  Object.defineProperty(exports, "__esModule", { value: true });
16
17
  exports.parseSVGPathData = void 0;
@@ -41,6 +42,7 @@ var parseSVGPathData = function (dataString) {
41
42
  var firstPoint = { x: NaN, y: NaN };
42
43
  var lastPoint = { x: NaN, y: NaN };
43
44
  var lastControlPoint = { x: NaN, y: NaN };
45
+ var lastQuadraticControlPoint = { x: NaN, y: NaN };
44
46
  while (i < dataElements.length) {
45
47
  // Could this also be SVGPathShorthandQuadraticCurveToCommand?
46
48
  var data = dataElements[i];
@@ -158,29 +160,29 @@ var _handleMove = function (data, isRelative, firstPoint, lastPoint, lastControl
158
160
  };
159
161
  // Draw a line segment from the current position
160
162
  var _handleLineTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
161
- // console.log("Handle LINETO", data);
162
163
  if (data.length < 3) {
163
164
  throw "Unsufficient params for LINETO";
164
165
  }
165
- // console.log("Y: ", Number(data[2]), "lastPoint", lastPoint);
166
- // result.push( new)
167
- var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
168
- if (isRelative) {
169
- line.b.x += Number(data[1]);
170
- line.b.y += Number(data[2]);
171
- }
172
- else {
173
- line.b.x = Number(data[1]);
174
- line.b.y = Number(data[2]);
175
- }
176
- result.push(line);
177
- lastPoint.x = line.b.x;
178
- lastPoint.y = line.b.y;
179
- lastControlPoint.x = line.b.x;
180
- lastControlPoint.y = line.b.y;
181
- if (isNaN(firstPoint.y)) {
182
- firstPoint.x = line.a.x;
183
- firstPoint.y = line.a.y;
166
+ for (var i = 1; i + 1 < data.length; i += 2) {
167
+ var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
168
+ if (isRelative) {
169
+ line.b.x += Number(data[i]);
170
+ line.b.y += Number(data[i + 1]);
171
+ }
172
+ else {
173
+ line.b.x = Number(data[i]);
174
+ line.b.y = Number(data[i + 1]);
175
+ }
176
+ result.push(line);
177
+ lastPoint.x = line.b.x;
178
+ lastPoint.y = line.b.y;
179
+ lastControlPoint.x = line.b.x;
180
+ lastControlPoint.y = line.b.y;
181
+ if (isNaN(firstPoint.y)) {
182
+ firstPoint.x = line.a.x;
183
+ firstPoint.y = line.a.y;
184
+ }
185
+ console.log("LINETO LINE", i, line.toString());
184
186
  }
185
187
  };
186
188
  var _handleHorizontalLineTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
@@ -188,49 +190,46 @@ var _handleHorizontalLineTo = function (data, isRelative, firstPoint, lastPoint,
188
190
  if (data.length < 2) {
189
191
  throw "Unsufficient params for HORIZONTALLINETO";
190
192
  }
191
- // console.log("Y: ", Number(data[2]), "lastPoint", lastPoint);
192
- // result.push( new)
193
- var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
194
- if (isRelative) {
195
- line.b.x += Number(data[1]);
196
- // line.b.y += Number(data[2]);
197
- }
198
- else {
199
- line.b.x = Number(data[1]);
200
- // line.b.y = Number(data[2]);
201
- }
202
- result.push(line);
203
- lastPoint.x = line.b.x;
204
- // lastPoint.y = line.b.y;
205
- lastControlPoint.x = line.b.x;
206
- if (isNaN(firstPoint.y)) {
207
- firstPoint.x = line.a.x;
208
- firstPoint.y = line.a.y;
193
+ for (var i = 1; i < data.length; i++) {
194
+ var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
195
+ if (isRelative) {
196
+ line.b.x += Number(data[i]);
197
+ // line.b.y += Number(data[2]);
198
+ }
199
+ else {
200
+ line.b.x = Number(data[i]);
201
+ // line.b.y = Number(data[2]);
202
+ }
203
+ result.push(line);
204
+ lastPoint.x = line.b.x;
205
+ // lastPoint.y = line.b.y;
206
+ lastControlPoint.x = line.b.x;
207
+ if (isNaN(firstPoint.y)) {
208
+ firstPoint.x = line.a.x;
209
+ firstPoint.y = line.a.y;
210
+ }
209
211
  }
210
212
  };
211
213
  var _handleVerticalLineTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
212
- // console.log("Handle VERTICALLINETO", data);
213
214
  if (data.length < 2) {
214
215
  throw "Unsufficient params for VERTICALLINETO";
215
216
  }
216
- // console.log("Y: ", Number(data[2]), "lastPoint", lastPoint);
217
- // result.push( new)
218
- var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
219
- if (isRelative) {
220
- // line.b.x += Number(data[1]);
221
- line.b.y += Number(data[1]);
222
- }
223
- else {
224
- // line.b.x = Number(data[1]);
225
- line.b.y = Number(data[1]);
226
- }
227
- result.push(line);
228
- // lastPoint.x = line.b.x;
229
- lastPoint.y = line.b.y;
230
- lastControlPoint.y = line.b.y;
231
- if (isNaN(firstPoint.y)) {
232
- firstPoint.x = line.a.x;
233
- firstPoint.y = line.a.y;
217
+ for (var i = 1; i < data.length; i++) {
218
+ var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
219
+ if (isRelative) {
220
+ line.b.y += Number(data[i]);
221
+ }
222
+ else {
223
+ line.b.y = Number(data[i]);
224
+ }
225
+ result.push(line);
226
+ // lastPoint.x = line.b.x;
227
+ lastPoint.y = line.b.y;
228
+ lastControlPoint.y = line.b.y;
229
+ if (isNaN(firstPoint.y)) {
230
+ firstPoint.x = line.a.x;
231
+ firstPoint.y = line.a.y;
232
+ }
234
233
  }
235
234
  };
236
235
  // CurveTo: C|c x1 y1 x2 y2 x y
@@ -239,33 +238,33 @@ var _handleCubicBezierTo = function (data, isRelative, firstPoint, lastPoint, la
239
238
  if (data.length < 7) {
240
239
  throw "Unsufficient params for CUBICBEZIERTO";
241
240
  }
242
- // console.log("Y: ", Number(data[2]), "lastPoint", lastPoint);
243
- // result.push( new)
244
- var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
245
- if (isRelative) {
246
- curve.startControlPoint.x += Number(data[1]);
247
- curve.startControlPoint.y += Number(data[2]);
248
- curve.endControlPoint.x += Number(data[3]);
249
- curve.endControlPoint.y += Number(data[4]);
250
- curve.endPoint.x += Number(data[5]);
251
- curve.endPoint.y += Number(data[6]);
252
- }
253
- else {
254
- curve.startControlPoint.x = Number(data[1]);
255
- curve.startControlPoint.y = Number(data[2]);
256
- curve.endControlPoint.x = Number(data[3]);
257
- curve.endControlPoint.y = Number(data[4]);
258
- curve.endPoint.x = Number(data[5]);
259
- curve.endPoint.y = Number(data[6]);
260
- }
261
- result.push(curve);
262
- lastPoint.x = curve.endPoint.x;
263
- lastPoint.y = curve.endPoint.y;
264
- lastControlPoint.x = curve.endControlPoint.x;
265
- lastControlPoint.y = curve.endControlPoint.y;
266
- if (isNaN(firstPoint.x)) {
267
- firstPoint.x = curve.startPoint.x;
268
- firstPoint.y = curve.startPoint.y;
241
+ for (var i = 1; i + 5 < data.length; i += 6) {
242
+ var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
243
+ if (isRelative) {
244
+ curve.startControlPoint.x += Number(data[i]);
245
+ curve.startControlPoint.y += Number(data[i + 1]);
246
+ curve.endControlPoint.x += Number(data[i + 2]);
247
+ curve.endControlPoint.y += Number(data[i + 3]);
248
+ curve.endPoint.x += Number(data[i + 4]);
249
+ curve.endPoint.y += Number(data[i + 5]);
250
+ }
251
+ else {
252
+ curve.startControlPoint.x = Number(data[i]);
253
+ curve.startControlPoint.y = Number(data[i + 1]);
254
+ curve.endControlPoint.x = Number(data[i + 2]);
255
+ curve.endControlPoint.y = Number(data[i + 3]);
256
+ curve.endPoint.x = Number(data[i + 4]);
257
+ curve.endPoint.y = Number(data[i + 5]);
258
+ }
259
+ result.push(curve);
260
+ lastPoint.x = curve.endPoint.x;
261
+ lastPoint.y = curve.endPoint.y;
262
+ lastControlPoint.x = curve.endControlPoint.x;
263
+ lastControlPoint.y = curve.endControlPoint.y;
264
+ if (isNaN(firstPoint.x)) {
265
+ firstPoint.x = curve.startPoint.x;
266
+ firstPoint.y = curve.startPoint.y;
267
+ }
269
268
  }
270
269
  };
271
270
  // QuadraticCurveTo: Q|q x1 y1 x y
@@ -274,93 +273,109 @@ var _handleQuadraticCurveTo = function (data, isRelative, firstPoint, lastPoint,
274
273
  if (data.length < 5) {
275
274
  throw "Unsufficient params for QUADRATICBEZIERTO";
276
275
  }
277
- // console.log("Y: ", Number(data[2]), "lastPoint", lastPoint);
278
- // result.push( new)
279
- var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
280
- if (isRelative) {
281
- curve.startControlPoint.x += curve.startPoint.x + (Number(data[1]) - curve.startControlPoint.x); // * 0.666;
282
- curve.startControlPoint.y += curve.startPoint.y + (Number(data[2]) - curve.startControlPoint.y); // * 0.666;
283
- curve.endPoint.x += Number(data[3]);
284
- curve.endPoint.y += Number(data[4]);
285
- curve.endControlPoint.x = curve.startControlPoint.x;
286
- curve.endControlPoint.y = curve.startControlPoint.y;
287
- }
288
- else {
289
- curve.startControlPoint.x = curve.startPoint.x + (Number(data[1]) - curve.startControlPoint.x); // * 0.666;
290
- curve.startControlPoint.y = curve.startPoint.y + (Number(data[2]) - curve.startControlPoint.y); // * 0.666;
291
- curve.endPoint.x = Number(data[3]);
292
- curve.endPoint.y = Number(data[4]);
293
- curve.endControlPoint.x = curve.startControlPoint.x;
294
- curve.endControlPoint.y = curve.startControlPoint.y;
295
- }
296
- // var lastQuadraticControlPoint = { x: Number(data[1]), y: Number(data[2]) };
297
- var lastQuadraticControlPoint = { x: curve.endControlPoint.x, y: curve.endControlPoint.y };
298
- // Convert quadratic curve to cubic curve
299
- curve.startControlPoint.x = curve.startPoint.x + (curve.startControlPoint.x - curve.startPoint.x) * 0.666;
300
- curve.startControlPoint.y = curve.startPoint.y + (curve.startControlPoint.y - curve.startPoint.y) * 0.666;
301
- curve.endControlPoint.x = curve.endPoint.x + (curve.endControlPoint.x - curve.endPoint.x) * 0.666;
302
- curve.endControlPoint.y = curve.endPoint.y + (curve.endControlPoint.y - curve.endPoint.y) * 0.666;
303
- result.push(curve);
304
- lastPoint.x = curve.endPoint.x;
305
- lastPoint.y = curve.endPoint.y;
306
- lastControlPoint.x = curve.endControlPoint.x;
307
- lastControlPoint.y = curve.endControlPoint.y;
308
- if (isNaN(firstPoint.x)) {
309
- firstPoint.x = curve.startPoint.x;
310
- firstPoint.y = curve.startPoint.y;
311
- }
276
+ var i = 1;
277
+ var localLastQuadraticControlPoint = { x: 0, y: 0 };
278
+ // This loops runs at least once
279
+ while (i + 3 < data.length && data[i] !== "t" && data[i] !== "T") {
280
+ var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
281
+ if (isRelative) {
282
+ curve.startControlPoint.x += curve.startPoint.x + (Number(data[i]) - curve.startControlPoint.x); // * 0.666;
283
+ curve.startControlPoint.y += curve.startPoint.y + (Number(data[i + 1]) - curve.startControlPoint.y); // * 0.666;
284
+ curve.endPoint.x += Number(data[i + 2]);
285
+ curve.endPoint.y += Number(data[i + 3]);
286
+ curve.endControlPoint.x = curve.startControlPoint.x;
287
+ curve.endControlPoint.y = curve.startControlPoint.y;
288
+ }
289
+ else {
290
+ curve.startControlPoint.x = curve.startPoint.x + (Number(data[i]) - curve.startControlPoint.x); // * 0.666;
291
+ curve.startControlPoint.y = curve.startPoint.y + (Number(data[i + 1]) - curve.startControlPoint.y); // * 0.666;
292
+ curve.endPoint.x = Number(data[i + 2]);
293
+ curve.endPoint.y = Number(data[i + 3]);
294
+ curve.endControlPoint.x = curve.startControlPoint.x;
295
+ curve.endControlPoint.y = curve.startControlPoint.y;
296
+ }
297
+ // var lastQuadraticControlPoint = { x: Number(data[1]), y: Number(data[2]) };
298
+ localLastQuadraticControlPoint = { x: curve.endControlPoint.x, y: curve.endControlPoint.y };
299
+ // Convert quadratic curve to cubic curve
300
+ curve.startControlPoint.x = curve.startPoint.x + (curve.startControlPoint.x - curve.startPoint.x) * 0.666;
301
+ curve.startControlPoint.y = curve.startPoint.y + (curve.startControlPoint.y - curve.startPoint.y) * 0.666;
302
+ curve.endControlPoint.x = curve.endPoint.x + (curve.endControlPoint.x - curve.endPoint.x) * 0.666;
303
+ curve.endControlPoint.y = curve.endPoint.y + (curve.endControlPoint.y - curve.endPoint.y) * 0.666;
304
+ result.push(curve);
305
+ lastPoint.x = curve.endPoint.x;
306
+ lastPoint.y = curve.endPoint.y;
307
+ lastControlPoint.x = curve.endControlPoint.x;
308
+ lastControlPoint.y = curve.endControlPoint.y;
309
+ if (isNaN(firstPoint.x)) {
310
+ firstPoint.x = curve.startPoint.x;
311
+ firstPoint.y = curve.startPoint.y;
312
+ }
313
+ i += 4;
314
+ } // END while
312
315
  // 'T' or 't' command may follow
313
- if (data.length >= 8) {
316
+ // if (data.length >= 8) {
317
+ if (i < data.length && (data[i] == "t" || data[i] === "T")) {
314
318
  // TODO: think about this type cast!
315
319
  var subData = data.slice(5);
316
320
  // var lastQuadraticControlPoint = { x: Number(data[1]), y: Number(data[2]) };
317
321
  if (subData[0] === "T") {
318
- // _handleShorthandQuadraticCurveTo(subData, false, firstPoint, lastPoint, lastControlPoint, result);
319
- _handleShorthandQuadraticCurveTo(subData, false, firstPoint, lastPoint, lastQuadraticControlPoint, result);
322
+ // _handleShorthandQuadraticCurveTo(subData, false, firstPoint, lastPoint, lastControlPoint, lastQuadraticControlPoint, result);
323
+ _handleShorthandQuadraticCurveTo(subData, false, firstPoint, lastPoint, lastControlPoint, localLastQuadraticControlPoint, result);
320
324
  }
321
325
  else if (subData[0] === "t") {
322
- // _handleShorthandQuadraticCurveTo(subData, true, firstPoint, lastPoint, lastControlPoint, result);
323
- _handleShorthandQuadraticCurveTo(subData, true, firstPoint, lastPoint, lastQuadraticControlPoint, result);
326
+ // _handleShorthandQuadraticCurveTo(subData, true, firstPoint, lastPoint, lastControlPoint, lastQuadraticControlPoint, result);
327
+ _handleShorthandQuadraticCurveTo(subData, true, firstPoint, lastPoint, lastControlPoint, localLastQuadraticControlPoint, result);
324
328
  }
325
329
  }
326
330
  };
327
331
  // This is a helper function and works only in combination with Quadratic Bézier Curves
328
- // T|t x y
329
- var _handleShorthandQuadraticCurveTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
330
- // console.log("Handle SHORTHANDQUADRATICCURVETO", data);
332
+ // T|t (x y)+
333
+ var _handleShorthandQuadraticCurveTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, lastQuadraticControlPoint, result) {
331
334
  if (data.length < 3) {
332
335
  throw "Unsufficient params for SHORTHANDQUADRATICCURVETO";
333
336
  }
334
- var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
335
- if (isRelative) {
336
- curve.endPoint.x += Number(data[1]);
337
- curve.endPoint.y += Number(data[2]);
338
- curve.startControlPoint.x += curve.startPoint.x - (lastControlPoint.x - lastPoint.x);
339
- curve.startControlPoint.y += curve.startPoint.y - (lastControlPoint.y - lastPoint.y);
340
- }
341
- else {
342
- curve.endPoint.x = Number(data[1]);
343
- curve.endPoint.y = Number(data[2]);
344
- curve.startControlPoint.x = curve.startPoint.x - (lastControlPoint.x - lastPoint.x);
345
- curve.startControlPoint.y = curve.startPoint.y - (lastControlPoint.y - lastPoint.y);
346
- }
347
- // First handle as symmetrical cubic curve
348
- curve.endControlPoint.x = curve.startControlPoint.x;
349
- curve.endControlPoint.y = curve.startControlPoint.y;
350
- // Convert quadratic curve to cubic curve
351
- curve.startControlPoint.x = curve.startPoint.x + (curve.startControlPoint.x - curve.startPoint.x) * 0.666;
352
- curve.startControlPoint.y = curve.startPoint.y + (curve.startControlPoint.y - curve.startPoint.y) * 0.666;
353
- curve.endControlPoint.x = curve.endPoint.x + (curve.endControlPoint.x - curve.endPoint.x) * 0.666;
354
- curve.endControlPoint.y = curve.endPoint.y + (curve.endControlPoint.y - curve.endPoint.y) * 0.666;
355
- // console.log("ADDING T CURVE", curve);
356
- result.push(curve);
357
- lastPoint.x = curve.endPoint.x;
358
- lastPoint.y = curve.endPoint.y;
359
- lastControlPoint.x = curve.endControlPoint.x;
360
- lastControlPoint.y = curve.endControlPoint.y;
361
- if (isNaN(firstPoint.x)) {
362
- firstPoint.x = curve.startPoint.x;
363
- firstPoint.y = curve.startPoint.y;
337
+ var i = 1;
338
+ while (i + 1 < data.length) {
339
+ // Respect multiple 'T|t' commands here
340
+ if (data[i] === "T" || data[i] === "t") {
341
+ i++;
342
+ continue;
343
+ }
344
+ var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
345
+ if (isRelative) {
346
+ curve.endPoint.x += Number(data[i]);
347
+ curve.endPoint.y += Number(data[i + 1]);
348
+ curve.startControlPoint.x += curve.startPoint.x - (lastQuadraticControlPoint.x - lastPoint.x);
349
+ curve.startControlPoint.y += curve.startPoint.y - (lastQuadraticControlPoint.y - lastPoint.y);
350
+ }
351
+ else {
352
+ curve.endPoint.x = Number(data[i]);
353
+ curve.endPoint.y = Number(data[i + 1]);
354
+ curve.startControlPoint.x = curve.startPoint.x - (lastQuadraticControlPoint.x - lastPoint.x);
355
+ curve.startControlPoint.y = curve.startPoint.y - (lastQuadraticControlPoint.y - lastPoint.y);
356
+ }
357
+ // First handle as symmetrical cubic curve
358
+ curve.endControlPoint.x = curve.startControlPoint.x;
359
+ curve.endControlPoint.y = curve.startControlPoint.y;
360
+ lastQuadraticControlPoint.y = curve.endControlPoint.y;
361
+ lastQuadraticControlPoint.x = curve.endControlPoint.x;
362
+ // Convert quadratic curve to cubic curve
363
+ var scaleFactor = 0.666; // i === 1 ? 0.666 : 1.0;
364
+ curve.startControlPoint.x = curve.startPoint.x + (curve.startControlPoint.x - curve.startPoint.x) * scaleFactor;
365
+ curve.startControlPoint.y = curve.startPoint.y + (curve.startControlPoint.y - curve.startPoint.y) * scaleFactor;
366
+ curve.endControlPoint.x = curve.endPoint.x + (curve.endControlPoint.x - curve.endPoint.x) * scaleFactor;
367
+ curve.endControlPoint.y = curve.endPoint.y + (curve.endControlPoint.y - curve.endPoint.y) * scaleFactor;
368
+ // console.log("ADDING T CURVE", curve);
369
+ result.push(curve);
370
+ lastPoint.x = curve.endPoint.x;
371
+ lastPoint.y = curve.endPoint.y;
372
+ lastControlPoint.x = curve.endControlPoint.x;
373
+ lastControlPoint.y = curve.endControlPoint.y;
374
+ if (isNaN(firstPoint.x)) {
375
+ firstPoint.x = curve.startPoint.x;
376
+ firstPoint.y = curve.startPoint.y;
377
+ }
378
+ i += 2;
364
379
  }
365
380
  };
366
381
  // The S|s x2 y2 x y
@@ -398,57 +413,65 @@ var _handleShorthandCubicCurveTo = function (data, isRelative, firstPoint, lastP
398
413
  };
399
414
  // EllipticalArcTo: A|a rx ry x-axis-rotation large-arc-flag sweep-flag x y
400
415
  var _handleArcTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
401
- // console.log("Handle ARCTO", data);
402
416
  if (data.length < 8) {
403
417
  throw "Unsufficient params for ARCTO";
404
418
  }
405
- var arcEndPoint = { x: Number(data[6]), y: Number(data[7]) };
406
- if (isRelative) {
407
- arcEndPoint.x += lastPoint.x;
408
- arcEndPoint.y += lastPoint.y;
409
- }
410
- // console.log(
411
- // "lastPoint.x",
412
- // lastPoint.x, // x1
413
- // "lastPoint.y",
414
- // lastPoint.y, // y1
415
- // "data[1]",
416
- // Number(data[1]), // rx
417
- // "data[2]",
418
- // Number(data[2]), // ry
419
- // "data[3]",
420
- // Number(data[3]), // phi: number,
421
- // "data[4]",
422
- // Boolean(data[4]), // fa: boolean,
423
- // "data[5]",
424
- // Boolean(data[5]), // fs: boolean,
425
- // "data[6]",
426
- // arcEndPoint.x, // Number(data[6]), // x2: number,
427
- // "data[7]",
428
- // arcEndPoint.y // Number(data[7]) // y2: number
429
- // );
430
- // A 5 4 0 1 1 -10 -5
431
- // TODO: respect relative/absolute here
432
- var ellipseSector = VEllipseSector_1.VEllipseSector.ellipseSectorUtils.endpointToCenterParameters(lastPoint.x, lastPoint.y, Number(data[1]), Number(data[2]), Number(data[3]) * DEG_TO_RAD, Boolean(data[4]), Boolean(data[5]), arcEndPoint.x, arcEndPoint.y // Number(data[7]) // y2: number
433
- );
434
- // console.log("ellipseSector", ellipseSector);
435
- var curves = ellipseSector.toCubicBezier(4); // 4 segments already seems to be a good approximation
436
- for (var i = 0; i < curves.length; i++) {
437
- result.push(curves[i]); // Destruct!
438
- }
439
- // result.push(ellipseSector.ellipse);
440
- if (curves.length > 0) {
441
- // console.log("curves", curves);
442
- var lastCurve = curves[curves.length - 1];
443
- lastPoint.x = lastCurve.endPoint.x;
444
- lastPoint.y = lastCurve.endPoint.y;
445
- lastControlPoint.x = lastCurve.endControlPoint.x;
446
- lastControlPoint.y = lastCurve.endControlPoint.y;
447
- if (isNaN(firstPoint.x)) {
448
- firstPoint.x = curves[0].startPoint.x;
449
- firstPoint.y = curves[0].startPoint.y;
419
+ for (var i = 1; i + 6 < data.length; i += 7) {
420
+ var arcEndPoint = { x: Number(data[i + 5]), y: Number(data[i + 6]) };
421
+ if (isRelative) {
422
+ arcEndPoint.x += lastPoint.x;
423
+ arcEndPoint.y += lastPoint.y;
450
424
  }
451
- }
425
+ // console.log(
426
+ // "ARC",
427
+ // "data.length",
428
+ // data.length,
429
+ // "i",
430
+ // i,
431
+ // "lastPoint.x",
432
+ // lastPoint.x, // x1
433
+ // "lastPoint.y",
434
+ // lastPoint.y, // y1
435
+ // "data[i]",
436
+ // Number(data[i]), // rx
437
+ // "data[i+1]",
438
+ // Number(data[i + 1]), // ry
439
+ // "data[i+2]",
440
+ // Number(data[i + 2]), // phi: number,
441
+ // "data[i+3]",
442
+ // Boolean(data[i + 3]), // fa: boolean,
443
+ // "data[i+4]",
444
+ // Boolean(data[i + 4]), // fs: boolean,
445
+ // "data[i+5]",
446
+ // arcEndPoint.x, // Number(data[6]), // x2: number,
447
+ // "data[i+6]",
448
+ // arcEndPoint.y // Number(data[7]) // y2: number
449
+ // );
450
+ // A 5 4 0 1 1 -10 -5
451
+ // TODO: respect relative/absolute here
452
+ var ellipseSector = VEllipseSector_1.VEllipseSector.ellipseSectorUtils.endpointToCenterParameters(lastPoint.x, lastPoint.y, Number(data[i]), Number(data[i + 1]), Number(data[i + 2]) * DEG_TO_RAD, Boolean(data[i + 3]), Boolean(data[i + 4]), arcEndPoint.x, arcEndPoint.y // Number(data[7]) // y2: number
453
+ );
454
+ // console.log("ellipseSector", ellipseSector);
455
+ var curves = ellipseSector.toCubicBezier(4); // 4 segments already seems to be a good approximation
456
+ for (var j = 0; j < curves.length; j++) {
457
+ result.push(curves[j]); // Destruct!
458
+ }
459
+ // result.push(ellipseSector.ellipse);
460
+ if (curves.length > 0) {
461
+ // console.log("curves", curves);
462
+ var lastCurve = curves[curves.length - 1];
463
+ // lastPoint.x = lastCurve.endPoint.x;
464
+ // lastPoint.y = lastCurve.endPoint.y;
465
+ lastControlPoint.x = lastCurve.endControlPoint.x;
466
+ lastControlPoint.y = lastCurve.endControlPoint.y;
467
+ if (isNaN(firstPoint.x)) {
468
+ firstPoint.x = curves[0].startPoint.x;
469
+ firstPoint.y = curves[0].startPoint.y;
470
+ }
471
+ }
472
+ lastPoint.x = arcEndPoint.x;
473
+ lastPoint.y = arcEndPoint.y;
474
+ } // END for
452
475
  // TODO: track first/last/control point
453
476
  };
454
477
  var _handleClosePath = function (_data, _isRelative, firstPoint, lastPoint, lastControlPoint, result) {