You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { v4 as uuid } from "uuid"
  2. import * as vec from "utils/vec"
  3. import { BaseLibShape, PolylineShape, ShapeType } from "types"
  4. const Polyline: BaseLibShape<ShapeType.Polyline> = {
  5. create(props): PolylineShape {
  6. return {
  7. id: uuid(),
  8. type: ShapeType.Polyline,
  9. name: "Polyline",
  10. parentId: "page0",
  11. childIndex: 0,
  12. point: [0, 0],
  13. points: [[0, 0]],
  14. rotation: 0,
  15. style: {},
  16. ...props,
  17. }
  18. },
  19. render({ id, points }) {
  20. return <polyline id={id} points={points.toString()} />
  21. },
  22. getBounds(shape) {
  23. let minX = 0
  24. let minY = 0
  25. let maxX = 0
  26. let maxY = 0
  27. for (let [x, y] of shape.points) {
  28. minX = Math.min(x, minX)
  29. minY = Math.min(y, minY)
  30. maxX = Math.max(x, maxX)
  31. maxY = Math.max(y, maxY)
  32. }
  33. return {
  34. minX: minX + shape.point[0],
  35. minY: minY + shape.point[1],
  36. maxX: maxX + shape.point[0],
  37. maxY: maxY + shape.point[1],
  38. width: maxX - minX,
  39. height: maxY - minY,
  40. }
  41. },
  42. hitTest(shape) {
  43. return true
  44. },
  45. rotate(shape) {
  46. return shape
  47. },
  48. translate(shape) {
  49. return shape
  50. },
  51. scale(shape, scale: number) {
  52. return shape
  53. },
  54. stretch(shape, scaleX: number, scaleY: number) {
  55. return shape
  56. },
  57. }
  58. export default Polyline