mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
Merge pull request #1244 from iahu/arc-self-rect
fix: handle Arc clockwise on getSelfRect
This commit is contained in:
commit
bdcfb2455f
@ -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));
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user