mirror of
https://github.com/konvajs/konva.git
synced 2025-10-21 19:37:31 +08:00
fix arc getSelfRect bound
This commit is contained in:
@@ -62,35 +62,25 @@ export class Arc extends Shape<ArcConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSelfRect() {
|
getSelfRect() {
|
||||||
const radius = this.outerRadius()
|
const innerRadius = this.innerRadius()
|
||||||
const DEG_TO_RAD = Math.PI / 180;
|
const outerRadius = this.outerRadius()
|
||||||
const angle = this.angle() * DEG_TO_RAD;
|
const clockwise = this.clockwise()
|
||||||
const inc = 1 * DEG_TO_RAD;
|
const angle = Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
||||||
let start = 0
|
|
||||||
let end = angle + inc
|
|
||||||
|
|
||||||
if (this.clockwise()) {
|
|
||||||
start = end
|
|
||||||
end = 360
|
|
||||||
}
|
|
||||||
|
|
||||||
const xs = [];
|
|
||||||
const ys = [];
|
|
||||||
for (let i = 0; i < end; i += inc ) {
|
|
||||||
xs.push(Math.cos(i));
|
|
||||||
ys.push(Math.sin(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
const minX = Math.round(radius * Math.min(...xs));
|
|
||||||
const maxX = Math.round(radius * Math.max(...xs));
|
|
||||||
const minY = Math.round(radius * Math.min(...ys));
|
|
||||||
const maxY = Math.round(radius * Math.max(...ys));
|
|
||||||
|
|
||||||
|
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI))
|
||||||
|
const boundRightRatio = 1
|
||||||
|
const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2))
|
||||||
|
const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2))
|
||||||
|
const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius)
|
||||||
|
const boundRight = boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius)
|
||||||
|
const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius)
|
||||||
|
const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x: minX || 0,
|
x: Math.round(boundLeft),
|
||||||
y: minY || 0,
|
y: Math.round(clockwise ? -1 * boundBottom : boundTop),
|
||||||
width: maxX - minX,
|
width: Math.round(boundRight - boundLeft),
|
||||||
height: maxY - minY
|
height: Math.round(boundBottom - boundTop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user