Merge pull request #1244 from iahu/arc-self-rect

fix: handle Arc clockwise on getSelfRect
This commit is contained in:
Anton Lavrenov 2021-11-26 07:17:43 -05:00 committed by GitHub
commit bdcfb2455f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 DEG_TO_RAD = Math.PI / 180;
const angle = this.angle() * DEG_TO_RAD; const angle = this.angle() * DEG_TO_RAD;
const inc = 1 * 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 xs = [];
const ys = []; const ys = [];
for (let i = 0; i < angle + inc; i += inc ) { for (let i = 0; i < end; i += inc ) {
xs.push(Math.cos(i)); xs.push(Math.cos(i));
ys.push(Math.sin(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 () { it('cache', function () {
var stage = addStage(); var stage = addStage();
var layer = new Konva.Layer(); var layer = new Konva.Layer();