mirror of
https://github.com/konvajs/konva.git
synced 2026-01-23 21:34:50 +08:00
feat: impliment getSelftRect method for Arc
This commit is contained in:
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user