Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { uniqueId } from 'utils/utils'
  2. import vec from 'utils/vec'
  3. import { RayShape, ShapeType } from 'types'
  4. import { intersectCircleBounds } from 'utils/intersections'
  5. import { ThinLine } from 'components/canvas/misc'
  6. import { translateBounds, boundsContained } from 'utils'
  7. import { defaultStyle } from 'state/shape-styles'
  8. import { registerShapeUtils } from './register'
  9. const ray = registerShapeUtils<RayShape>({
  10. boundsCache: new WeakMap([]),
  11. defaultProps: {
  12. id: uniqueId(),
  13. type: ShapeType.Ray,
  14. isGenerated: false,
  15. name: 'Ray',
  16. parentId: 'page1',
  17. childIndex: 0,
  18. point: [0, 0],
  19. direction: [0, 1],
  20. rotation: 0,
  21. isAspectRatioLocked: false,
  22. isLocked: false,
  23. isHidden: false,
  24. style: defaultStyle,
  25. },
  26. shouldRender(shape, prev) {
  27. return shape.direction !== prev.direction || shape.style !== prev.style
  28. },
  29. render({ id, direction }) {
  30. const [x2, y2] = vec.add([0, 0], vec.mul(direction, 10000))
  31. return (
  32. <g id={id}>
  33. <ThinLine x1={0} y1={0} x2={x2} y2={y2} />
  34. <use href="#dot" />
  35. </g>
  36. )
  37. },
  38. getRotatedBounds(shape) {
  39. return this.getBounds(shape)
  40. },
  41. getBounds(shape) {
  42. if (!this.boundsCache.has(shape)) {
  43. const bounds = {
  44. minX: 0,
  45. maxX: 1,
  46. minY: 0,
  47. maxY: 1,
  48. width: 1,
  49. height: 1,
  50. }
  51. this.boundsCache.set(shape, bounds)
  52. }
  53. return translateBounds(this.boundsCache.get(shape), shape.point)
  54. },
  55. getCenter(shape) {
  56. return shape.point
  57. },
  58. hitTest() {
  59. return true
  60. },
  61. hitTestBounds(this, shape, brushBounds) {
  62. const shapeBounds = this.getBounds(shape)
  63. return (
  64. boundsContained(shapeBounds, brushBounds) ||
  65. intersectCircleBounds(shape.point, 4, brushBounds).length > 0
  66. )
  67. },
  68. transform(shape, bounds) {
  69. shape.point = [bounds.minX, bounds.minY]
  70. return this
  71. },
  72. transformSingle(shape, bounds, info) {
  73. return this.transform(shape, bounds, info)
  74. },
  75. canTransform: false,
  76. canChangeAspectRatio: false,
  77. canStyleFill: false,
  78. })
  79. export default ray