fix: handle Arc clockwise on getSelfRect

This commit is contained in:
i18u 2021-11-26 10:15:35 +08:00
parent a120ae93b3
commit bed6f8bb7a
2 changed files with 36 additions and 1 deletions

View File

@ -66,10 +66,17 @@ export class Arc extends Shape<ArcConfig> {
const DEG_TO_RAD = Math.PI / 180;
const angle = this.angle() * DEG_TO_RAD;
const inc = 1 * DEG_TO_RAD;
let start = 0
let end = angle + inc
if (this.clockwise()) {
start = end
end = 360
}
const xs = [];
const ys = [];
for (let i = 0; i < angle + inc; i += inc ) {
for (let i = 0; i < end; i += inc ) {
xs.push(Math.cos(i));
ys.push(Math.sin(i));
}

View File

@ -96,6 +96,34 @@ describe('Arc', function () {
});
});
it('getSelfRect on clockwise', function () {
var stage = addStage();
var layer = new Konva.Layer();
var arc = new Konva.Arc({
x: 100,
y: 100,
innerRadius: 50,
outerRadius: 80,
angle: 90,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myArc',
draggable: true,
clockwise: true,
});
layer.add(arc);
stage.add(layer);
assert.deepEqual(arc.getSelfRect(), {
x: -80,
y: -80,
width: 160,
height: 160,
});
});
it('cache', function () {
var stage = addStage();
var layer = new Konva.Layer();