source: imaps-frontend/node_modules/konva/lib/shapes/RegularPolygon.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RegularPolygon = void 0;
4const Factory_1 = require("../Factory");
5const Shape_1 = require("../Shape");
6const Validators_1 = require("../Validators");
7const Global_1 = require("../Global");
8class 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}
63exports.RegularPolygon = RegularPolygon;
64RegularPolygon.prototype.className = 'RegularPolygon';
65RegularPolygon.prototype._centroid = true;
66RegularPolygon.prototype._attrsAffectingSize = ['radius'];
67(0, Global_1._registerNode)(RegularPolygon);
68Factory_1.Factory.addGetterSetter(RegularPolygon, 'radius', 0, (0, Validators_1.getNumberValidator)());
69Factory_1.Factory.addGetterSetter(RegularPolygon, 'sides', 0, (0, Validators_1.getNumberValidator)());
Note: See TracBrowser for help on using the repository browser.