mirror of
https://github.com/konvajs/konva.git
synced 2025-10-08 00:14:23 +08:00
fix path arc parsing without separators
This commit is contained in:
@@ -515,8 +515,36 @@ export class Path extends Shape<PathConfig> {
|
|||||||
str = str.slice(1);
|
str = str.slice(1);
|
||||||
|
|
||||||
coords.length = 0;
|
coords.length = 0;
|
||||||
while ((match = re.exec(str))) {
|
if (c === 'a' || c === 'A') {
|
||||||
coords.push(match[0]);
|
let i = 0;
|
||||||
|
while (i < str.length) {
|
||||||
|
// skip separators
|
||||||
|
while (i < str.length && (str[i] === ',' || str[i] === ' ')) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i >= str.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const idx = coords.length % 7;
|
||||||
|
if (idx === 3 || idx === 4) {
|
||||||
|
// flags are single-digit values (0 or 1)
|
||||||
|
coords.push(str[i]);
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
let s = '';
|
||||||
|
if (str[i] === '-' || str[i] === '+') {
|
||||||
|
s += str[i++];
|
||||||
|
}
|
||||||
|
while (i < str.length && /[0-9.]/.test(str[i])) {
|
||||||
|
s += str[i++];
|
||||||
|
}
|
||||||
|
coords.push(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while ((match = re.exec(str))) {
|
||||||
|
coords.push(match[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// while ((match = re.exec(str))) {
|
// while ((match = re.exec(str))) {
|
||||||
|
@@ -60,6 +60,22 @@ describe('Path', function () {
|
|||||||
assert.equal(path.getClassName(), 'Path');
|
assert.equal(path.getClassName(), 'Path');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parses arc without separators after flags', function () {
|
||||||
|
const path = new Konva.Path({
|
||||||
|
data: 'M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1115 0z',
|
||||||
|
});
|
||||||
|
const arc = path.dataArray[3];
|
||||||
|
assert.equal(arc.command, 'A');
|
||||||
|
assert.closeTo(arc.points[0], 12, 0.001);
|
||||||
|
assert.closeTo(arc.points[1], 10.5, 0.001);
|
||||||
|
assert.closeTo(arc.points[2], 7.5, 0.001);
|
||||||
|
assert.closeTo(arc.points[3], 7.5, 0.001);
|
||||||
|
assert.closeTo(arc.points[4], Math.PI, 0.001);
|
||||||
|
assert.closeTo(arc.points[5], Math.PI, 0.001);
|
||||||
|
assert.equal(arc.points[6], 0);
|
||||||
|
assert.equal(arc.points[7], 1);
|
||||||
|
});
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
it('add path with line cap and line join', function () {
|
it('add path with line cap and line join', function () {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
|
Reference in New Issue
Block a user