Skip to content

Commit

Permalink
fix(Vectorizer): fix normalizePathData() to support zero-length arc t…
Browse files Browse the repository at this point in the history
…o curve (#2598)
  • Loading branch information
kumilingus committed Mar 27, 2024
1 parent 4622900 commit 62bfd32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/joint-core/src/V/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,10 @@ const V = (function() {
var ry2 = ry * ry;

var k = ((large_arc_flag == sweep_flag) ? -1 : 1) * sqrt(abs(((rx2 * ry2) - (rx2 * y * y) - (ry2 * x * x)) / ((rx2 * y * y) + (ry2 * x * x))));
if (!Number.isFinite(k)) {
// Arc is a single point
return [x1, y1, x2, y2, x2, y2];
}

var cx = ((k * rx * y) / ry) + ((x1 + x2) / 2);
var cy = ((k * -ry * x) / rx) + ((y1 + y2) / 2);
Expand Down
2 changes: 2 additions & 0 deletions packages/joint-core/test/vectorizer/vectorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,8 @@ QUnit.module('vectorizer', function(hooks) {
assert.equal(V.normalizePathData('A 3 0 0 0 1 10 15'), 'M 0 0 L 10 15'); // 0 y radius
assert.equal(V.normalizePathData('A 0 0 0 0 1 10 15'), 'M 0 0 L 10 15'); // 0 x and y radii

assert.equal(V.normalizePathData('M 3 7 A 7 7 0 0 1 3 7'), 'M 3 7 C 3 7 3 7 3 7'); // arc corresponding to a single point

// Make sure this does not throw an error because of recursion in a2c() exceeding the maximum stack size
V.normalizePathData('M 0 0 A 1 1 0 1 0 -1 -1');
V.normalizePathData('M 14.4 29.52 a .72 .72 0 1 0 -.72 -.72 A .72 .72 0 0 0 14.4 29.52Z');
Expand Down

0 comments on commit 62bfd32

Please sign in to comment.