Circle.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import VectorType from "../enum/VectorType.js";
  2. import SelectState from "../enum/SelectState.js";
  3. import Geometry from "./Geometry";
  4. import Constant from "../Constant.js";
  5. import Style from "../CanvasStyle";
  6. //不靠墙
  7. export default class Circle extends Geometry {
  8. constructor(center, radius, vectorId) {
  9. super();
  10. this.radius = Style.Circle.radius;
  11. this.center = null;
  12. this.color = Style.Circle.strokeStyle;
  13. this.points = []; //包含圆的4个顶点,按照顺时针的方式存入数组中,第一个元素是左上角顶点
  14. this.geoType = VectorType.Circle;
  15. this.setId(vectorId);
  16. this.setRadius(radius);
  17. this.setCenter(center);
  18. this.createPoints();
  19. }
  20. createPoints() {
  21. this.points[0] = {
  22. x: this.center.x - this.radius,
  23. y: this.center.y + this.radius,
  24. };
  25. this.points[1] = {
  26. x: this.center.x + this.radius,
  27. y: this.center.y + this.radius,
  28. };
  29. this.points[2] = {
  30. x: this.center.x + this.radius,
  31. y: this.center.y - this.radius,
  32. };
  33. this.points[3] = {
  34. x: this.center.x - this.radius,
  35. y: this.center.y - this.radius,
  36. };
  37. }
  38. setPoints(points) {
  39. if (points && points.length == 4) {
  40. this.points = JSON.parse(JSON.stringify(points));
  41. } else {
  42. this.createPoints();
  43. }
  44. }
  45. setColor(value) {
  46. this.color = value;
  47. }
  48. }