Pārlūkot izejas kodu

Rotation snaps to PI/12

main
Steve Ruiz 4 gadus atpakaļ
vecāks
revīzija
def8f665d3
1 mainītis faili ar 9 papildinājumiem un 6 dzēšanām
  1. 9
    6
      state/sessions/rotate-session.ts

+ 9
- 6
state/sessions/rotate-session.ts Parādīt failu

45
       const shape = page.shapes[id]
45
       const shape = page.shapes[id]
46
 
46
 
47
       getShapeUtils(shape)
47
       getShapeUtils(shape)
48
-        .rotateTo(shape, (PI2 + (rotation + rot)) % PI2)
48
+        .rotateTo(
49
+          shape,
50
+          (PI2 +
51
+            (isLocked
52
+              ? clampToRotationToSegments(rotation + rot, 24)
53
+              : rotation + rot)) %
54
+            PI2
55
+        )
49
         .translateTo(
56
         .translateTo(
50
           shape,
57
           shape,
51
           vec.sub(vec.rotWith(center, boundsCenter, rot % PI2), offset)
58
           vec.sub(vec.rotWith(center, boundsCenter, rot % PI2), offset)
70
 export function getRotateSnapshot(data: Data) {
77
 export function getRotateSnapshot(data: Data) {
71
   const shapes = getSelectedShapes(current(data))
78
   const shapes = getSelectedShapes(current(data))
72
 
79
 
73
-  // A mapping of selected shapes and their bounds
74
   const shapesBounds = Object.fromEntries(
80
   const shapesBounds = Object.fromEntries(
75
     shapes.map((shape) => [shape.id, getShapeBounds(shape)])
81
     shapes.map((shape) => [shape.id, getShapeBounds(shape)])
76
   )
82
   )
77
 
83
 
78
-  // The common (exterior) bounds of the selected shapes
79
   const bounds = getCommonBounds(...Object.values(shapesBounds))
84
   const bounds = getCommonBounds(...Object.values(shapesBounds))
80
 
85
 
81
-  const boundsCenter = getBoundsCenter(bounds)
82
-
83
   return {
86
   return {
84
-    boundsCenter,
85
     currentPageId: data.currentPageId,
87
     currentPageId: data.currentPageId,
86
     boundsRotation: data.boundsRotation,
88
     boundsRotation: data.boundsRotation,
89
+    boundsCenter: getBoundsCenter(bounds),
87
     shapes: shapes.map(({ id, point, rotation }) => {
90
     shapes: shapes.map(({ id, point, rotation }) => {
88
       const bounds = shapesBounds[id]
91
       const bounds = shapesBounds[id]
89
       const offset = [bounds.width / 2, bounds.height / 2]
92
       const offset = [bounds.width / 2, bounds.height / 2]

Notiek ielāde…
Atcelt
Saglabāt