line-interaction.ts 939 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {
  2. hasExceededDragThreshold,
  3. normalizeCoordinate
  4. } from '@/components/mt-dzr/utils/drag-position'
  5. type LinePoint = {
  6. x: number
  7. y: number
  8. }
  9. type LineBinfo = {
  10. left: number
  11. top: number
  12. width: number
  13. height: number
  14. }
  15. export const hasLineDragStarted = (deltaX: number, deltaY: number) =>
  16. hasExceededDragThreshold(deltaX, deltaY)
  17. export const normalizeLineGeometry = (binfo: LineBinfo, points: LinePoint[]) => ({
  18. binfo: {
  19. left: normalizeCoordinate(binfo.left),
  20. top: normalizeCoordinate(binfo.top),
  21. width: normalizeCoordinate(binfo.width),
  22. height: normalizeCoordinate(binfo.height)
  23. },
  24. points: points.map((point) => ({
  25. x: normalizeCoordinate(point.x),
  26. y: normalizeCoordinate(point.y)
  27. }))
  28. })
  29. export const completeLineEdit = <T>(
  30. value: T,
  31. changed: boolean,
  32. update: (value: T) => void,
  33. complete: () => void
  34. ) => {
  35. if (!changed) {
  36. return
  37. }
  38. update(value)
  39. complete()
  40. }