feat: impliment getSelftRect method for Arc

This commit is contained in:
i18u
2021-11-25 19:05:56 +08:00
parent f771910578
commit 279eaac88c
8 changed files with 61 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ import { Konva } from '../Global';
import { GetSet } from '../types';
import { getNumberValidator, getBooleanValidator } from '../Validators';
import { _registerNode } from '../Global';
import { Transform, Util } from '../Util';
export interface ArcConfig extends ShapeConfig {
angle: number;
@@ -60,6 +61,32 @@ export class Arc extends Shape<ArcConfig> {
this.outerRadius(height / 2);
}
getSelfRect() {
const radius = this.outerRadius()
const DEG_TO_RAD = Math.PI / 180;
const angle = this.angle() * DEG_TO_RAD;
const inc = 1 * DEG_TO_RAD;
const xs = [];
const ys = [];
for (let i = 0; i < angle + inc; 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));
return {
x: minX || 0,
y: minY || 0,
width: maxX - minX,
height: maxY - minY
}
}
innerRadius: GetSet<number, this>;
outerRadius: GetSet<number, this>;
angle: GetSet<number, this>;