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

@ -8,7 +8,7 @@
* Konva JavaScript Framework v8.3.0
* http://konvajs.org/
* Licensed under the MIT
* Date: Mon Nov 15 2021
* Date: Thu Nov 25 2021
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@ -9719,6 +9719,28 @@
setHeight(height) {
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
};
}
}
Arc.prototype._centroid = true;
Arc.prototype.className = 'Arc';

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

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>;

View File

@ -6,5 +6,5 @@
"lib": ["ES2015", "dom"],
"module": "CommonJS"
},
"include": ["../src/*.ts"]
"include": ["../src/**/*.ts"]
}

View File

@ -89,10 +89,10 @@ describe('Arc', function () {
stage.add(layer);
assert.deepEqual(arc.getSelfRect(), {
x: -80,
y: -80,
width: 160,
height: 160,
x: 0,
y: 0,
width: 80,
height: 80,
});
});

View File

@ -9,5 +9,5 @@
"declaration": true,
"removeComments": true
},
"include": ["./src/*.ts"],
"include": ["./src/**/*.ts"],
}

View File

@ -3,6 +3,7 @@
"outDir": "lib",
"module": "ES2015",
"target": "ES2015",
"sourceMap": true,
"noEmitOnError": true,
"lib": ["ES2015", "dom"],
"moduleResolution": "node",
@ -11,5 +12,5 @@
// "noImplicitAny": true,
// "strict": true
},
"include": ["./src/*.ts"]
"include": ["./src/**/*.ts"]
}

View File

@ -6,5 +6,5 @@
"moduleResolution": "node",
"lib": ["ES2015", "dom"]
},
"include": ["./src/*.ts"]
"include": ["./src/**/*.ts"]
}