Circle.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. setRadius(radius) {
  21. this.radius = radius;
  22. }
  23. setCenter(center) {
  24. if (center) {
  25. this.center = {};
  26. this.center.x = center.x;
  27. this.center.y = center.y;
  28. }
  29. }
  30. createPoints() {
  31. this.points[0] = {
  32. x: this.center.x - this.radius,
  33. y: this.center.y + this.radius,
  34. };
  35. this.points[1] = {
  36. x: this.center.x + this.radius,
  37. y: this.center.y + this.radius,
  38. };
  39. this.points[2] = {
  40. x: this.center.x + this.radius,
  41. y: this.center.y - this.radius,
  42. };
  43. this.points[3] = {
  44. x: this.center.x - this.radius,
  45. y: this.center.y - this.radius,
  46. };
  47. }
  48. setColor(value) {
  49. this.color = value;
  50. }
  51. }