[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | exports.RegularPolygon = void 0;
|
---|
| 4 | const Factory_1 = require("../Factory");
|
---|
| 5 | const Shape_1 = require("../Shape");
|
---|
| 6 | const Validators_1 = require("../Validators");
|
---|
| 7 | const Global_1 = require("../Global");
|
---|
| 8 | class RegularPolygon extends Shape_1.Shape {
|
---|
| 9 | _sceneFunc(context) {
|
---|
| 10 | const points = this._getPoints();
|
---|
| 11 | context.beginPath();
|
---|
| 12 | context.moveTo(points[0].x, points[0].y);
|
---|
| 13 | for (var n = 1; n < points.length; n++) {
|
---|
| 14 | context.lineTo(points[n].x, points[n].y);
|
---|
| 15 | }
|
---|
| 16 | context.closePath();
|
---|
| 17 | context.fillStrokeShape(this);
|
---|
| 18 | }
|
---|
| 19 | _getPoints() {
|
---|
| 20 | const sides = this.attrs.sides;
|
---|
| 21 | const radius = this.attrs.radius || 0;
|
---|
| 22 | const points = [];
|
---|
| 23 | for (var n = 0; n < sides; n++) {
|
---|
| 24 | points.push({
|
---|
| 25 | x: radius * Math.sin((n * 2 * Math.PI) / sides),
|
---|
| 26 | y: -1 * radius * Math.cos((n * 2 * Math.PI) / sides),
|
---|
| 27 | });
|
---|
| 28 | }
|
---|
| 29 | return points;
|
---|
| 30 | }
|
---|
| 31 | getSelfRect() {
|
---|
| 32 | const points = this._getPoints();
|
---|
| 33 | var minX = points[0].x;
|
---|
| 34 | var maxX = points[0].y;
|
---|
| 35 | var minY = points[0].x;
|
---|
| 36 | var maxY = points[0].y;
|
---|
| 37 | points.forEach((point) => {
|
---|
| 38 | minX = Math.min(minX, point.x);
|
---|
| 39 | maxX = Math.max(maxX, point.x);
|
---|
| 40 | minY = Math.min(minY, point.y);
|
---|
| 41 | maxY = Math.max(maxY, point.y);
|
---|
| 42 | });
|
---|
| 43 | return {
|
---|
| 44 | x: minX,
|
---|
| 45 | y: minY,
|
---|
| 46 | width: maxX - minX,
|
---|
| 47 | height: maxY - minY,
|
---|
| 48 | };
|
---|
| 49 | }
|
---|
| 50 | getWidth() {
|
---|
| 51 | return this.radius() * 2;
|
---|
| 52 | }
|
---|
| 53 | getHeight() {
|
---|
| 54 | return this.radius() * 2;
|
---|
| 55 | }
|
---|
| 56 | setWidth(width) {
|
---|
| 57 | this.radius(width / 2);
|
---|
| 58 | }
|
---|
| 59 | setHeight(height) {
|
---|
| 60 | this.radius(height / 2);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | exports.RegularPolygon = RegularPolygon;
|
---|
| 64 | RegularPolygon.prototype.className = 'RegularPolygon';
|
---|
| 65 | RegularPolygon.prototype._centroid = true;
|
---|
| 66 | RegularPolygon.prototype._attrsAffectingSize = ['radius'];
|
---|
| 67 | (0, Global_1._registerNode)(RegularPolygon);
|
---|
| 68 | Factory_1.Factory.addGetterSetter(RegularPolygon, 'radius', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 69 | Factory_1.Factory.addGetterSetter(RegularPolygon, 'sides', 0, (0, Validators_1.getNumberValidator)());
|
---|