Skip to content

Commit

Permalink
fix(shape): 修复 sector & arc 角度从非 0 到 0 不更新 (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue authored Oct 26, 2023
1 parent 9497e97 commit 13afa9f
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/f-engine/src/shape/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class Arc extends Path {
const { cx = 0, cy = 0, startAngle, endAngle, r, anticlockwise } = this.parsedStyle;

if (isNil(startAngle) || isNil(endAngle) || startAngle === endAngle || isNil(r) || r <= 0) {
super.setAttribute('path', '');
return;
}

Expand Down
1 change: 1 addition & 0 deletions packages/f-engine/src/shape/sector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class Sector extends Path {
const { cx, cy, startAngle, endAngle, r, r0, radius, anticlockwise = false } = this.parsedStyle;

if (isNil(startAngle) || isNil(endAngle) || startAngle === endAngle || isNil(r) || r <= 0) {
super.setAttribute('path', '');
return;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions packages/f-engine/test/shape/arc.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,46 @@ describe('Arc', () => {
await delay(500);
expect(context).toMatchImageSnapshot();
});

it('角度从非0到0', async () => {
const { props } = (
<Canvas context={context} pixelRatio={1}>
<arc
style={{
cx: 60,
cy: 60,
stroke: 'red',
lineWidth: '8px',
startAngle: '-1.57rad',
endAngle: '4.36rad',
r: 50,
}}
/>
</Canvas>
);

const canvas = new Canvas(props);
await canvas.render();
await delay(500);
expect(context).toMatchImageSnapshot();

const update = (
<Canvas context={context} pixelRatio={1}>
<arc
style={{
cx: 60,
cy: 60,
stroke: 'red',
lineWidth: '8px',
startAngle: '1rad',
endAngle: '1rad',
r: 50,
}}
/>
</Canvas>
);
await canvas.update(update.props);
await delay(500);
expect(context).toMatchImageSnapshot();
});
});
42 changes: 42 additions & 0 deletions packages/f-engine/test/shape/sector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,46 @@ describe('Sector', () => {
expect(context).toMatchImageSnapshot();
});
});

it('角度从非0到0', async () => {
const { props } = (
<Canvas context={context} pixelRatio={1}>
<sector
style={{
cx: 150,
cy: 120,
fill: 'red',
startAngle: '-1.57rad',
endAngle: '4.36rad',
r0: 60,
r: 100,
}}
/>
</Canvas>
);

const canvas = new Canvas(props);
await canvas.render();
await delay(500);
expect(context).toMatchImageSnapshot();

const update = (
<Canvas context={context} pixelRatio={1}>
<sector
style={{
cx: 150,
cy: 120,
fill: 'red',
startAngle: '1rad',
endAngle: '1rad',
r0: 60,
r: 100,
}}
/>
</Canvas>
);
await canvas.update(update.props);
await delay(500);
expect(context).toMatchImageSnapshot();
});
});

0 comments on commit 13afa9f

Please sign in to comment.