123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import VectorType from "../enum/VectorType.js";
- import Geometry from "./Geometry.js";
- import { mathUtil } from "../Util/MathUtil.js";
- import { coordinate } from "../Coordinate.js";
- import Constant from "../Constant.js";
- //const sideWidth = 10;
- export default class SVG extends Geometry {
- constructor(center, vectorId) {
- super();
- this.center = center;
- this.points = null; //包裹的矩形的四个顶点
- this.angle = 0; //逆时针为负,顺时针为正。单位是:°
- this.scale = 1; //缩放比例
- this.name = null;
- this.geoType = VectorType.SVG;
- this.setId(vectorId);
- }
- // createDefaultPoints() {
- // this.points = [];
- // this.points[0] = {
- // x: this.center.x - sideWidth / 2,
- // y: this.center.y + sideWidth / 2,
- // };
- // this.points[1] = {
- // x: this.center.x + sideWidth / 2,
- // y: this.center.y + sideWidth / 2,
- // };
- // this.points[2] = {
- // x: this.center.x + sideWidth / 2,
- // y: this.center.y - sideWidth / 2,
- // };
- // this.points[3] = {
- // x: this.center.x - sideWidth / 2,
- // y: this.center.y - sideWidth / 2,
- // };
- // }
- getBoundingVertexs(center) {
- const boundingVertexs = [];
- const rec = this.getLengthWidth();
- const length = this.getScale() * rec.length * this.scale;
- const width = this.getScale() * rec.width * this.scale;
- const minX = center.x - length / 2;
- const minY = center.y - width / 2;
- const maxX = center.x + length / 2;
- const maxY = center.y + width / 2;
- const point1 = this.rotatePoint(
- {
- x: minX,
- y: maxY,
- },
- center,
- this.angle
- );
- const point2 = this.rotatePoint(
- {
- x: maxX,
- y: maxY,
- },
- center,
- this.angle
- );
- const point3 = this.rotatePoint(
- {
- x: maxX,
- y: minY,
- },
- center,
- this.angle
- );
- const point4 = this.rotatePoint(
- {
- x: minX,
- y: minY,
- },
- center,
- this.angle
- );
- boundingVertexs.push(point1);
- boundingVertexs.push(point2);
- boundingVertexs.push(point3);
- boundingVertexs.push(point4);
- return boundingVertexs;
- }
- //不同图例,缩放比不一样
- getScale() {
- return 1;
- }
- getLengthWidth() {
- return {
- length: 32,
- width: 32,
- };
- }
- }
|