@react-native-ohos/react-native-reanimated 4.0.0-rc.1 → 4.0.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/compatibility.json +161 -161
  2. package/harmony/reanimated/BuildProfile.ets +16 -16
  3. package/harmony/reanimated/build-profile.json5 +18 -18
  4. package/harmony/reanimated/hvigorfile.ts +4 -4
  5. package/harmony/reanimated/index.ets +4 -4
  6. package/harmony/reanimated/oh-package-lock.json5 +39 -0
  7. package/harmony/reanimated/oh-package.json5 +12 -12
  8. package/harmony/reanimated/src/main/cpp/CMakeLists.txt +65 -62
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +81 -81
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +46 -46
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/InterpolatorRegistry.cpp +390 -390
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/InterpolatorRegistry.h +16 -16
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/definitions.h +30 -30
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/filters/FilterOp.cpp +46 -46
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/filters/FilterOp.h +23 -23
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/Quaternion.cpp +53 -53
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/Quaternion.h +21 -21
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix.cpp +166 -166
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix.h +71 -71
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix2D.cpp +368 -368
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix2D.h +53 -53
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix3D.cpp +594 -594
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix3D.h +67 -67
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformOp.cpp +52 -52
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformOp.h +26 -26
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/vectors.cpp +156 -156
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/vectors.h +76 -76
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSAngle.cpp +94 -93
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSAngle.h +33 -33
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSBoolean.cpp +48 -48
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSBoolean.h +31 -31
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSColor.cpp +135 -135
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSColor.h +61 -61
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSDiscreteArray.cpp +100 -100
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSDiscreteArray.h +45 -44
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSKeyword.cpp +81 -81
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSKeyword.h +53 -53
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSLength.cpp +122 -122
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSLength.h +38 -38
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSNumber.cpp +82 -82
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSNumber.h +63 -63
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSValue.h +118 -118
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSValueVariant.cpp +174 -174
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSValueVariant.h +111 -111
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/complex/CSSBoxShadow.cpp +196 -196
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/complex/CSSBoxShadow.h +66 -66
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/complex/CSSDropShadow.cpp +134 -134
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/complex/CSSDropShadow.h +44 -44
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.cpp +174 -174
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.h +49 -49
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSKeyframesConfig.cpp +45 -45
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSKeyframesConfig.h +26 -26
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSTransitionConfig.cpp +90 -90
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSTransitionConfig.h +43 -43
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/common.cpp +17 -17
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/common.h +13 -13
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSAnimation.cpp +127 -127
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSAnimation.h +51 -51
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSTransition.cpp +145 -145
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSTransition.h +47 -47
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/EasingFunctions.cpp +69 -69
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/EasingFunctions.h +22 -22
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/cubicBezier.cpp +66 -66
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/cubicBezier.h +15 -15
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/linear.cpp +28 -28
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/linear.h +15 -15
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/steps.cpp +13 -13
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/steps.h +12 -12
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/InterpolatorFactory.cpp +157 -157
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/InterpolatorFactory.h +189 -189
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/PropertyInterpolator.cpp +76 -76
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/PropertyInterpolator.h +66 -66
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/configs.h +20 -20
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperation.cpp +136 -136
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperation.h +40 -40
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperationInterpolator.cpp +38 -38
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperationInterpolator.h +24 -24
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterStyleInterpolator.cpp +58 -58
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterStyleInterpolator.h +24 -24
  80. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/blur.h +14 -14
  81. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/brightness.h +14 -14
  82. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/contrast.h +14 -14
  83. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/dropShadow.h +17 -17
  84. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/grayscale.h +14 -14
  85. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/hueRotate.h +14 -14
  86. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/invert.h +14 -14
  87. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/opacity.h +14 -14
  88. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/saturate.h +14 -14
  89. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/sepia.h +14 -14
  90. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/ArrayPropertiesInterpolator.cpp +95 -95
  91. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/ArrayPropertiesInterpolator.h +36 -36
  92. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/GroupPropertiesInterpolator.cpp +41 -41
  93. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/GroupPropertiesInterpolator.h +32 -32
  94. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/RecordPropertiesInterpolator.cpp +99 -99
  95. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/RecordPropertiesInterpolator.h +37 -37
  96. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/OperationsStyleInterpolator.cpp +308 -308
  97. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/OperationsStyleInterpolator.h +100 -100
  98. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/StyleOperation.cpp +19 -19
  99. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/StyleOperation.h +94 -94
  100. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/StyleOperationInterpolator.cpp +18 -18
  101. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/StyleOperationInterpolator.h +43 -43
  102. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/AnimationStyleInterpolator.h +26 -26
  103. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/TransitionStyleInterpolator.cpp +103 -103
  104. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/TransitionStyleInterpolator.h +42 -42
  105. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperation.cpp +224 -224
  106. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperation.h +52 -52
  107. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperationInterpolator.cpp +218 -218
  108. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperationInterpolator.h +89 -89
  109. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformsStyleInterpolator.cpp +149 -149
  110. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformsStyleInterpolator.h +33 -33
  111. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/matrix.cpp +208 -208
  112. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/matrix.h +56 -56
  113. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/perspective.cpp +42 -42
  114. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/perspective.h +20 -20
  115. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/rotate.cpp +41 -41
  116. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/rotate.h +39 -39
  117. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/scale.cpp +28 -28
  118. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/scale.h +25 -25
  119. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/skew.cpp +14 -14
  120. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/skew.h +20 -20
  121. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/translate.cpp +39 -39
  122. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/translate.h +25 -25
  123. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ResolvableValueInterpolator.cpp +47 -47
  124. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ResolvableValueInterpolator.h +43 -43
  125. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/SimpleValueInterpolator.cpp +70 -70
  126. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/SimpleValueInterpolator.h +40 -40
  127. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ValueInterpolator.cpp +146 -146
  128. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ValueInterpolator.h +71 -71
  129. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/misc/ViewStylesRepository.cpp +155 -155
  130. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/misc/ViewStylesRepository.h +53 -53
  131. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.cpp +170 -170
  132. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.h +67 -67
  133. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/KeyframeProgressProvider.h +12 -12
  134. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/RawProgressProvider.cpp +41 -41
  135. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/RawProgressProvider.h +31 -31
  136. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.cpp +193 -193
  137. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.h +77 -77
  138. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.cpp +340 -340
  139. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.h +80 -80
  140. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSKeyframesRegistry.cpp +45 -45
  141. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSKeyframesRegistry.h +29 -29
  142. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSTransitionsRegistry.cpp +167 -167
  143. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSTransitionsRegistry.h +51 -51
  144. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/StaticPropsRegistry.cpp +61 -61
  145. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/StaticPropsRegistry.h +33 -33
  146. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGBrush.cpp +80 -80
  147. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGBrush.h +39 -39
  148. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGLength.cpp +93 -93
  149. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGLength.h +36 -36
  150. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGStrokeDashArray.cpp +111 -110
  151. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGStrokeDashArray.h +33 -33
  152. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.cpp +75 -75
  153. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.h +45 -45
  154. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/algorithms.cpp +12 -12
  155. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/algorithms.h +10 -10
  156. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/interpolators.cpp +36 -36
  157. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/interpolators.h +23 -23
  158. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/props.cpp +149 -149
  159. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/props.h +32 -32
  160. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +113 -113
  161. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +49 -49
  162. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +46 -46
  163. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +56 -56
  164. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +37 -37
  165. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +104 -104
  166. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +22 -22
  167. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.cpp +72 -72
  168. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.h +25 -25
  169. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp +160 -160
  170. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h +71 -71
  171. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.cpp +161 -161
  172. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.h +65 -65
  173. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +11 -11
  174. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +137 -137
  175. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +82 -82
  176. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp +79 -79
  177. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.h +81 -81
  178. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp +864 -864
  179. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h +214 -214
  180. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp +897 -897
  181. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +220 -220
  182. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +31 -31
  183. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +146 -146
  184. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/PropsDiffer.cpp +456 -456
  185. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/PropsDiffer.h +102 -102
  186. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp +544 -544
  187. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/PropValueProcessor.cpp +119 -119
  188. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/PropValueProcessor.h +39 -39
  189. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +1380 -1376
  190. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +230 -228
  191. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +183 -183
  192. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +93 -93
  193. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +54 -54
  194. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +28 -28
  195. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +58 -58
  196. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +31 -31
  197. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeatureFlags.cpp +18 -18
  198. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeatureFlags.h +44 -44
  199. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +67 -67
  200. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +114 -114
  201. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedVersion.cpp +46 -46
  202. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedVersion.h +18 -18
  203. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +233 -230
  204. package/harmony/reanimated/src/main/cpp/ReanimatedModule.h +23 -23
  205. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.cpp +56 -56
  206. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.h +30 -30
  207. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.cpp +44 -44
  208. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.h +16 -16
  209. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.cpp +265 -265
  210. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.h +36 -36
  211. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.cpp +35 -35
  212. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.h +23 -23
  213. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.cpp +23 -23
  214. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.h +19 -19
  215. package/harmony/reanimated/src/main/cpp/TransformParser.h +93 -93
  216. package/harmony/reanimated/src/main/ets/AnimationManager.ts +60 -60
  217. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +51 -51
  218. package/harmony/reanimated/src/main/ets/ReanimatedPackage.ts +25 -25
  219. package/harmony/reanimated/src/main/module.json5 +12 -12
  220. package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
  221. package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
  222. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
  223. package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
  224. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
  225. package/harmony/reanimated/ts.ts +6 -6
  226. package/harmony/reanimated.har +0 -0
  227. package/package.json +70 -68
  228. package/scripts/deploy.js +191 -191
  229. package/scripts/set-reanimated-version.js +37 -37
  230. package/scripts/update-version.js +119 -119
  231. package/scripts/validate-react-native-version.js +46 -46
  232. package/scripts/validate-worklets-build.js +17 -17
  233. package/scripts/validate-worklets-version.js +84 -79
  234. package/scripts/worklets-version.json +4 -4
  235. package/src/index.ts +9 -9
@@ -1,594 +1,594 @@
1
- #include <reanimated/CSS/common/transforms/TransformMatrix3D.h>
2
- #include <reanimated/CSS/interpolation/transforms/TransformOperation.h>
3
-
4
- #include <string>
5
-
6
- namespace reanimated::css {
7
-
8
- TransformMatrix3D::TransformMatrix3D(jsi::Runtime &rt, const jsi::Value &value)
9
- : TransformMatrixBase<TransformMatrix3D, MATRIX_3D_DIMENSION>() {
10
- const auto &array = value.asObject(rt).asArray(rt);
11
- const auto size = array.size(rt);
12
-
13
- if (size != SIZE) {
14
- throw std::invalid_argument("[Reanimated] TransformMatrix3D: Invalid matrix size: " + std::to_string(size));
15
- }
16
-
17
- for (size_t i = 0; i < SIZE; ++i) {
18
- matrix_[i] = array.getValueAtIndex(rt, i).asNumber();
19
- }
20
- }
21
-
22
- TransformMatrix3D::TransformMatrix3D(const folly::dynamic &array)
23
- : TransformMatrixBase<TransformMatrix3D, MATRIX_3D_DIMENSION>() {
24
- const auto size = array.size();
25
-
26
- if (size != SIZE) {
27
- throw std::invalid_argument("[Reanimated] TransformMatrix3D: Invalid matrix size: " + std::to_string(size));
28
- }
29
-
30
- for (size_t i = 0; i < SIZE; ++i) {
31
- matrix_[i] = array[i].asDouble();
32
- }
33
- }
34
-
35
- TransformMatrix3D::Decomposed TransformMatrix3D::Decomposed::interpolate(
36
- const double progress,
37
- const TransformMatrix3D::Decomposed &to) const {
38
- return {
39
- .scale = scale.interpolate(progress, to.scale),
40
- .skew = skew.interpolate(progress, to.skew),
41
- .quaternion = quaternion.interpolate(progress, to.quaternion),
42
- .translation = translation.interpolate(progress, to.translation),
43
- .perspective = perspective.interpolate(progress, to.perspective)};
44
- }
45
-
46
- #ifndef NDEBUG
47
-
48
- std::ostream &operator<<(std::ostream &os, const TransformMatrix3D::Decomposed &decomposed) {
49
- os << "TransformMatrix3D::Decomposed(scale=" << decomposed.scale << ", skew=" << decomposed.skew
50
- << ", quaternion=" << decomposed.quaternion << ", translation=" << decomposed.translation
51
- << ", perspective=" << decomposed.perspective << ")";
52
- return os;
53
- }
54
-
55
- #endif // NDEBUG
56
-
57
- // Template specializations for TransformMatrix3D::create
58
- template <>
59
- TransformMatrix3D TransformMatrix3D::create<TransformOp::Perspective>(double v) {
60
- if (v == 0) {
61
- // Ignore perspective if it is invalid
62
- return TransformMatrix3D();
63
- }
64
- // clang-format off
65
- return TransformMatrix3D({
66
- 1, 0, 0, 0,
67
- 0, 1, 0, 0,
68
- 0, 0, 1, -1.0 / v,
69
- 0, 0, 0, 1
70
- });
71
- // clang-format on
72
- }
73
-
74
- template <>
75
- TransformMatrix3D TransformMatrix3D::create<TransformOp::RotateX>(double v) {
76
- const auto cosVal = std::cos(v);
77
- const auto sinVal = std::sin(v);
78
- // clang-format off
79
- return TransformMatrix3D({
80
- 1, 0, 0, 0,
81
- 0, cosVal, sinVal, 0,
82
- 0, -sinVal, cosVal, 0,
83
- 0, 0, 0, 1
84
- });
85
- // clang-format on
86
- }
87
-
88
- template <>
89
- TransformMatrix3D TransformMatrix3D::create<TransformOp::RotateY>(double v) {
90
- const auto cosVal = std::cos(v);
91
- const auto sinVal = std::sin(v);
92
- // clang-format off
93
- return TransformMatrix3D({
94
- cosVal, 0, -sinVal, 0,
95
- 0, 1, 0, 0,
96
- sinVal, 0, cosVal, 0,
97
- 0, 0, 0, 1
98
- });
99
- // clang-format on
100
- }
101
-
102
- template <>
103
- TransformMatrix3D TransformMatrix3D::create<TransformOp::RotateZ>(double v) {
104
- const auto cosVal = std::cos(v);
105
- const auto sinVal = std::sin(v);
106
- // clang-format off
107
- return TransformMatrix3D({
108
- cosVal, sinVal, 0, 0,
109
- -sinVal, cosVal, 0, 0,
110
- 0, 0, 1, 0,
111
- 0, 0, 0, 1
112
- });
113
- // clang-format on
114
- }
115
-
116
- template <>
117
- TransformMatrix3D TransformMatrix3D::create<TransformOp::Rotate>(double v) {
118
- return TransformMatrix3D::create<TransformOp::RotateZ>(v);
119
- }
120
-
121
- template <>
122
- TransformMatrix3D TransformMatrix3D::create<TransformOp::Scale>(double v) {
123
- // clang-format off
124
- return TransformMatrix3D({
125
- v, 0, 0, 0,
126
- 0, v, 0, 0,
127
- 0, 0, v, 0,
128
- 0, 0, 0, 1
129
- });
130
- // clang-format on
131
- }
132
-
133
- template <>
134
- TransformMatrix3D TransformMatrix3D::create<TransformOp::ScaleX>(double v) {
135
- // clang-format off
136
- return TransformMatrix3D({
137
- v, 0, 0, 0,
138
- 0, 1, 0, 0,
139
- 0, 0, 1, 0,
140
- 0, 0, 0, 1
141
- });
142
- // clang-format on
143
- }
144
-
145
- template <>
146
- TransformMatrix3D TransformMatrix3D::create<TransformOp::ScaleY>(double v) {
147
- // clang-format off
148
- return TransformMatrix3D({
149
- 1, 0, 0, 0,
150
- 0, v, 0, 0,
151
- 0, 0, 1, 0,
152
- 0, 0, 0, 1
153
- });
154
- // clang-format on
155
- }
156
-
157
- template <>
158
- TransformMatrix3D TransformMatrix3D::create<TransformOp::TranslateX>(double v) {
159
- // clang-format off
160
- return TransformMatrix3D({
161
- 1, 0, 0, 0,
162
- 0, 1, 0, 0,
163
- 0, 0, 1, 0,
164
- v, 0, 0, 1
165
- });
166
- // clang-format on
167
- }
168
-
169
- template <>
170
- TransformMatrix3D TransformMatrix3D::create<TransformOp::TranslateY>(double v) {
171
- // clang-format off
172
- return TransformMatrix3D({
173
- 1, 0, 0, 0,
174
- 0, 1, 0, 0,
175
- 0, 0, 1, 0,
176
- 0, v, 0, 1
177
- });
178
- // clang-format on
179
- }
180
-
181
- template <>
182
- TransformMatrix3D TransformMatrix3D::create<TransformOp::SkewX>(double v) {
183
- const auto tanVal = std::tan(v);
184
- // clang-format off
185
- return TransformMatrix3D({
186
- 1, 0, 0, 0,
187
- tanVal, 1, 0, 0,
188
- 0, 0, 1, 0,
189
- 0, 0, 0, 1
190
- });
191
- // clang-format on
192
- }
193
-
194
- template <>
195
- TransformMatrix3D TransformMatrix3D::create<TransformOp::SkewY>(double v) {
196
- const auto tanVal = std::tan(v);
197
- // clang-format off
198
- return TransformMatrix3D({
199
- 1, tanVal, 0, 0,
200
- 0, 1, 0, 0,
201
- 0, 0, 1, 0,
202
- 0, 0, 0, 1
203
- });
204
- // clang-format on
205
- }
206
-
207
- template <TransformOp TOperation>
208
- TransformMatrix3D TransformMatrix3D::create(double value) {
209
- throw std::invalid_argument(
210
- "[Reanimated] Cannot create TransformMatrix3D from: " + getTransformOperationName(TOperation));
211
- }
212
-
213
- TransformMatrix3D TransformMatrix3D::from2D(const TransformMatrix2D &m) {
214
- // clang-format off
215
- return TransformMatrix3D({
216
- m[0], m[1], 0, m[2],
217
- m[3], m[4], 0, m[5],
218
- 0, 0, 1, 0,
219
- m[6], m[7], 0, m[8]
220
- });
221
- // clang-format on
222
- }
223
-
224
- Vector4D operator*(const Vector4D &v, const TransformMatrix3D &m) {
225
- Vector4D result;
226
-
227
- for (size_t i = 0; i < 4; ++i) {
228
- for (size_t j = 0; j < 4; ++j) {
229
- result[i] += v[j] * m[j * 4 + i];
230
- }
231
- }
232
-
233
- return result;
234
- }
235
-
236
- #ifndef NDEBUG
237
-
238
- std::ostream &operator<<(std::ostream &os, const TransformMatrix3D &matrix) {
239
- std::string result = "TransformMatrix3D{";
240
- for (size_t i = 0; i < 16; ++i) {
241
- result += std::to_string(matrix[i]);
242
- if (i < 15) {
243
- result += ", ";
244
- }
245
- }
246
- result += "}";
247
- return os << result;
248
- }
249
-
250
- #endif // NDEBUG
251
-
252
- /**
253
- * Calculates the determinant of the 4x4 matrix using the minor (Laplace
254
- * expansion) method.
255
- *
256
- * | a1 a2 a3 a4 |
257
- * | b1 b2 b3 b4 |
258
- * | c1 c2 c3 c4 |
259
- * | d1 d2 d3 d4 |
260
- */
261
- double TransformMatrix3D::determinant() const {
262
- const double a1 = matrix_[0];
263
- const double b1 = matrix_[1];
264
- const double c1 = matrix_[2];
265
- const double d1 = matrix_[3];
266
-
267
- const double a2 = matrix_[4];
268
- const double b2 = matrix_[5];
269
- const double c2 = matrix_[6];
270
- const double d2 = matrix_[7];
271
-
272
- const double a3 = matrix_[8];
273
- const double b3 = matrix_[9];
274
- const double c3 = matrix_[10];
275
- const double d3 = matrix_[11];
276
-
277
- const double a4 = matrix_[12];
278
- const double b4 = matrix_[13];
279
- const double c4 = matrix_[14];
280
- const double d4 = matrix_[15];
281
-
282
- return a1 * determinant3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4) -
283
- b1 * determinant3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4) +
284
- c1 * determinant3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4) - d1 * determinant3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4);
285
- }
286
-
287
- void TransformMatrix3D::adjugate() {
288
- const double a1 = matrix_[0];
289
- const double b1 = matrix_[1];
290
- const double c1 = matrix_[2];
291
- const double d1 = matrix_[3];
292
-
293
- const double a2 = matrix_[4];
294
- const double b2 = matrix_[5];
295
- const double c2 = matrix_[6];
296
- const double d2 = matrix_[7];
297
-
298
- const double a3 = matrix_[8];
299
- const double b3 = matrix_[9];
300
- const double c3 = matrix_[10];
301
- const double d3 = matrix_[11];
302
-
303
- const double a4 = matrix_[12];
304
- const double b4 = matrix_[13];
305
- const double c4 = matrix_[14];
306
- const double d4 = matrix_[15];
307
-
308
- matrix_[0] = determinant3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4);
309
- matrix_[4] = -determinant3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4);
310
- matrix_[8] = determinant3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4);
311
- matrix_[12] = -determinant3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4);
312
-
313
- matrix_[1] = -determinant3x3(b1, b3, b4, c1, c3, c4, d1, d3, d4);
314
- matrix_[5] = determinant3x3(a1, a3, a4, c1, c3, c4, d1, d3, d4);
315
- matrix_[9] = -determinant3x3(a1, a3, a4, b1, b3, b4, d1, d3, d4);
316
- matrix_[13] = determinant3x3(a1, a3, a4, b1, b3, b4, c1, c3, c4);
317
-
318
- matrix_[2] = determinant3x3(b1, b2, b4, c1, c2, c4, d1, d2, d4);
319
- matrix_[6] = -determinant3x3(a1, a2, a4, c1, c2, c4, d1, d2, d4);
320
- matrix_[10] = determinant3x3(a1, a2, a4, b1, b2, b4, d1, d2, d4);
321
- matrix_[14] = -determinant3x3(a1, a2, a4, b1, b2, b4, c1, c2, c4);
322
-
323
- matrix_[3] = -determinant3x3(b1, b2, b3, c1, c2, c3, d1, d2, d3);
324
- matrix_[7] = determinant3x3(a1, a2, a3, c1, c2, c3, d1, d2, d3);
325
- matrix_[11] = -determinant3x3(a1, a2, a3, b1, b2, b3, d1, d2, d3);
326
- matrix_[15] = determinant3x3(a1, a2, a3, b1, b2, b3, c1, c2, c3);
327
- }
328
-
329
- bool TransformMatrix3D::invert() {
330
- const auto det = determinant();
331
-
332
- // If the determinant is invalid (zero, very small number, etc.), then the
333
- // matrix is not invertible
334
- if (!std::isnormal(det)) {
335
- return false;
336
- }
337
-
338
- adjugate();
339
- for (size_t i = 0; i < 16; ++i) {
340
- matrix_[i] /= det;
341
- }
342
-
343
- return true;
344
- }
345
-
346
- void TransformMatrix3D::translate3d(const Vector3D &translation) {
347
- for (size_t i = 0; i < 4; ++i) {
348
- matrix_[12 + i] += translation[0] * matrix_[i] + translation[1] * matrix_[4 + i] + translation[2] * matrix_[8 + i];
349
- }
350
- }
351
-
352
- void TransformMatrix3D::scale3d(const Vector3D &scale) {
353
- for (size_t i = 0; i < 4; ++i) {
354
- matrix_[i] *= scale[0];
355
- matrix_[4 + i] *= scale[1];
356
- matrix_[8 + i] *= scale[2];
357
- }
358
- }
359
-
360
- std::optional<TransformMatrix3D::Decomposed> TransformMatrix3D::decompose() const {
361
- auto matrixCp = *this;
362
-
363
- if (!matrixCp.normalize()) {
364
- return std::nullopt;
365
- }
366
- const auto perspective = matrixCp.computePerspective();
367
- if (!perspective) {
368
- return std::nullopt;
369
- }
370
- const auto translation = matrixCp.getTranslation();
371
-
372
- // Move the remaining matrix to 3 separate column vectors for easier
373
- // processing
374
- std::array<Vector3D, 3> rows;
375
- for (size_t i = 0; i < 3; ++i) {
376
- rows[i] = Vector3D(matrixCp[i * 4], matrixCp[i * 4 + 1], matrixCp[i * 4 + 2]);
377
- }
378
-
379
- auto [scale, skew] = computeScaleAndSkew(rows);
380
-
381
- // At this point, the matrix (in rows) is orthonormal.
382
- // Check for a coordinate system flip. If the determinant
383
- // is negative, then negate the matrix and the scaling factors.
384
- if (rows[0].dot(rows[1].cross(rows[2])) < 0) {
385
- scale *= -1;
386
- for (auto &row : rows) {
387
- row *= -1;
388
- }
389
- }
390
- const auto rotation = computeQuaternion(rows);
391
-
392
- return TransformMatrix3D::Decomposed{
393
- .scale = scale,
394
- .skew = skew,
395
- .quaternion = rotation,
396
- .translation = translation,
397
- .perspective = perspective.value()};
398
- }
399
-
400
- TransformMatrix3D TransformMatrix3D::recompose(const TransformMatrix3D::Decomposed &decomposed) {
401
- auto result = TransformMatrix3D();
402
-
403
- // Start from applying perspective
404
- for (size_t i = 0; i < 4; ++i) {
405
- result[3 + i * 4] = decomposed.perspective[i];
406
- }
407
-
408
- // Apply translation
409
- result.translate3d(decomposed.translation);
410
-
411
- // Apply rotation
412
- result = fromQuaternion(decomposed.quaternion) * result;
413
-
414
- // Apply skew
415
- auto hasSkewYZ = decomposed.skew[2] != 0;
416
- auto hasSkewXZ = decomposed.skew[1] != 0;
417
- auto hasSkewXY = decomposed.skew[0] != 0;
418
-
419
- if (hasSkewYZ || hasSkewXZ || hasSkewXY) {
420
- auto tmp = TransformMatrix3D();
421
- if (hasSkewYZ) { // YZ
422
- tmp[9] = decomposed.skew[2];
423
- result = tmp * result;
424
- }
425
- if (hasSkewXZ) { // XZ
426
- tmp[8] = decomposed.skew[1];
427
- result = tmp * result;
428
- }
429
- if (hasSkewXY) { // XY
430
- tmp[4] = decomposed.skew[0];
431
- result = tmp * result;
432
- }
433
- }
434
-
435
- // Apply scale
436
- result.scale3d(decomposed.scale);
437
-
438
- return result;
439
- }
440
-
441
- TransformMatrix3D TransformMatrix3D::fromQuaternion(const Quaternion &q) {
442
- const double xx = q.x * q.x;
443
- const double yy = q.y * q.y;
444
- const double zz = q.z * q.z;
445
- const double xz = q.x * q.z;
446
- const double xy = q.x * q.y;
447
- const double yz = q.y * q.z;
448
- const double xw = q.w * q.x;
449
- const double yw = q.w * q.y;
450
- const double zw = q.w * q.z;
451
-
452
- // clang-format off
453
- return TransformMatrix3D({
454
- 1 - 2 * (yy + zz), 2 * (xy - zw), 2 * (xz + yw), 0,
455
- 2 * (xy + zw), 1 - 2 * (xx + zz), 2 * (yz - xw), 0,
456
- 2 * (xz - yw), 2 * (yz + xw), 1 - 2 * (xx + yy), 0,
457
- 0, 0, 0, 1
458
- });
459
- // clang-format on
460
- }
461
-
462
- std::optional<Vector4D> TransformMatrix3D::computePerspective() const {
463
- auto perspectiveMatrix = *this;
464
-
465
- for (size_t i = 0; i < 3; ++i) {
466
- perspectiveMatrix[3 + i * 4] = 0;
467
- }
468
- perspectiveMatrix[15] = 1;
469
-
470
- if (perspectiveMatrix.isSingular()) {
471
- return std::nullopt;
472
- }
473
-
474
- if (matrix_[3] == 0 && matrix_[7] == 0 && matrix_[11] == 0) {
475
- // No perspective
476
- return Vector4D{0, 0, 0, 1};
477
- }
478
-
479
- // Invert and transpose the perspective matrix (we will solve the equation
480
- // by multiplying the rhs vector by the inverse of the perspective matrix)
481
- if (!perspectiveMatrix.invert()) {
482
- return std::nullopt;
483
- }
484
- perspectiveMatrix.transpose();
485
-
486
- // rhs is the right hand side of the equation we are trying to solve
487
- const Vector4D rhs(matrix_[3], matrix_[7], matrix_[11], matrix_[15]);
488
- // Solve the equation
489
- return rhs * perspectiveMatrix;
490
- }
491
-
492
- Vector3D TransformMatrix3D::getTranslation() const {
493
- return Vector3D(matrix_[12], matrix_[13], matrix_[14]);
494
- }
495
-
496
- std::pair<Vector3D, Vector3D> TransformMatrix3D::computeScaleAndSkew(std::array<Vector3D, 3> &rows) {
497
- Vector3D scale, skew;
498
-
499
- // Compute X scale factor and normalize first row
500
- scale[0] = rows[0].length();
501
- rows[0].normalize();
502
-
503
- // Compute XY shear factor and make 2nd row orthogonal to 1st.
504
- skew[0] = rows[0].dot(rows[1]);
505
- rows[1] = rows[1].addScaled(rows[0], -skew[0]);
506
-
507
- // Now, compute Y scale and normalize 2nd row.
508
- scale[1] = rows[1].length();
509
- rows[1].normalize();
510
- skew[0] /= scale[1]; // normalize XY shear
511
-
512
- // Compute XZ and YZ shears, orthogonalize 3rd row
513
- skew[1] = rows[0].dot(rows[2]);
514
- rows[2] = rows[2].addScaled(rows[0], -skew[1]);
515
- skew[2] = rows[1].dot(rows[2]);
516
- rows[2] = rows[2].addScaled(rows[1], -skew[2]);
517
-
518
- // Next, get Z scale and normalize 3rd row
519
- scale[2] = rows[2].length();
520
- rows[2].normalize();
521
- skew[1] /= scale[2]; // normalize XZ shear
522
- skew[2] /= scale[2]; // normalize YZ shear
523
-
524
- return {scale, skew};
525
- }
526
-
527
- Quaternion TransformMatrix3D::computeQuaternion(std::array<Vector3D, 3> &rows) {
528
- double m00 = rows[0][0];
529
- double m01 = rows[0][1];
530
- double m02 = rows[0][2];
531
-
532
- double m10 = rows[1][0];
533
- double m11 = rows[1][1];
534
- double m12 = rows[1][2];
535
-
536
- double m20 = rows[2][0];
537
- double m21 = rows[2][1];
538
- double m22 = rows[2][2];
539
-
540
- Quaternion q;
541
- double trace = m00 + m11 + m22; // Trace of the matrix
542
-
543
- if (trace > 0.0) {
544
- double s = 0.5 / sqrt(trace + 1.0);
545
- q.w = 0.25 / s;
546
- q.x = (m21 - m12) * s;
547
- q.y = (m02 - m20) * s;
548
- q.z = (m10 - m01) * s;
549
- } else {
550
- if (m00 > m11 && m00 > m22) {
551
- double s = 2.0 * sqrt(1.0 + m00 - m11 - m22);
552
- q.w = (m21 - m12) / s;
553
- q.x = 0.25 * s;
554
- q.y = (m01 + m10) / s;
555
- q.z = (m02 + m20) / s;
556
- } else if (m11 > m22) {
557
- double s = 2.0 * sqrt(1.0 + m11 - m00 - m22);
558
- q.w = (m02 - m20) / s;
559
- q.x = (m01 + m10) / s;
560
- q.y = 0.25 * s;
561
- q.z = (m12 + m21) / s;
562
- } else {
563
- double s = 2.0 * sqrt(1.0 + m22 - m00 - m11);
564
- q.w = (m10 - m01) / s;
565
- q.x = (m02 + m20) / s;
566
- q.y = (m12 + m21) / s;
567
- q.z = 0.25 * s;
568
- }
569
- }
570
-
571
- return q;
572
- }
573
-
574
- /**
575
- * Calculate the determinant of a 3x3 matrix
576
- *
577
- * | a b c |
578
- * | d e f |
579
- * | g h i |
580
- */
581
- double TransformMatrix3D::determinant3x3(
582
- const double a,
583
- const double b,
584
- const double c,
585
- const double d,
586
- const double e,
587
- const double f,
588
- const double g,
589
- const double h,
590
- const double i) {
591
- return (a * e * i) + (b * f * g) + (c * d * h) - (c * e * g) - (b * d * i) - (a * f * h);
592
- }
593
-
594
- } // namespace reanimated::css
1
+ #include <reanimated/CSS/common/transforms/TransformMatrix3D.h>
2
+ #include <reanimated/CSS/interpolation/transforms/TransformOperation.h>
3
+
4
+ #include <string>
5
+
6
+ namespace reanimated::css {
7
+
8
+ TransformMatrix3D::TransformMatrix3D(jsi::Runtime &rt, const jsi::Value &value)
9
+ : TransformMatrixBase<TransformMatrix3D, MATRIX_3D_DIMENSION>() {
10
+ const auto &array = value.asObject(rt).asArray(rt);
11
+ const auto size = array.size(rt);
12
+
13
+ if (size != SIZE) {
14
+ throw std::invalid_argument("[Reanimated] TransformMatrix3D: Invalid matrix size: " + std::to_string(size));
15
+ }
16
+
17
+ for (size_t i = 0; i < SIZE; ++i) {
18
+ matrix_[i] = array.getValueAtIndex(rt, i).asNumber();
19
+ }
20
+ }
21
+
22
+ TransformMatrix3D::TransformMatrix3D(const folly::dynamic &array)
23
+ : TransformMatrixBase<TransformMatrix3D, MATRIX_3D_DIMENSION>() {
24
+ const auto size = array.size();
25
+
26
+ if (size != SIZE) {
27
+ throw std::invalid_argument("[Reanimated] TransformMatrix3D: Invalid matrix size: " + std::to_string(size));
28
+ }
29
+
30
+ for (size_t i = 0; i < SIZE; ++i) {
31
+ matrix_[i] = array[i].asDouble();
32
+ }
33
+ }
34
+
35
+ TransformMatrix3D::Decomposed TransformMatrix3D::Decomposed::interpolate(
36
+ const double progress,
37
+ const TransformMatrix3D::Decomposed &to) const {
38
+ return {
39
+ .scale = scale.interpolate(progress, to.scale),
40
+ .skew = skew.interpolate(progress, to.skew),
41
+ .quaternion = quaternion.interpolate(progress, to.quaternion),
42
+ .translation = translation.interpolate(progress, to.translation),
43
+ .perspective = perspective.interpolate(progress, to.perspective)};
44
+ }
45
+
46
+ #ifndef NDEBUG
47
+
48
+ std::ostream &operator<<(std::ostream &os, const TransformMatrix3D::Decomposed &decomposed) {
49
+ os << "TransformMatrix3D::Decomposed(scale=" << decomposed.scale << ", skew=" << decomposed.skew
50
+ << ", quaternion=" << decomposed.quaternion << ", translation=" << decomposed.translation
51
+ << ", perspective=" << decomposed.perspective << ")";
52
+ return os;
53
+ }
54
+
55
+ #endif // NDEBUG
56
+
57
+ // Template specializations for TransformMatrix3D::create
58
+ template <>
59
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::Perspective>(double v) {
60
+ if (v == 0) {
61
+ // Ignore perspective if it is invalid
62
+ return TransformMatrix3D();
63
+ }
64
+ // clang-format off
65
+ return TransformMatrix3D({
66
+ 1, 0, 0, 0,
67
+ 0, 1, 0, 0,
68
+ 0, 0, 1, -1.0 / v,
69
+ 0, 0, 0, 1
70
+ });
71
+ // clang-format on
72
+ }
73
+
74
+ template <>
75
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::RotateX>(double v) {
76
+ const auto cosVal = std::cos(v);
77
+ const auto sinVal = std::sin(v);
78
+ // clang-format off
79
+ return TransformMatrix3D({
80
+ 1, 0, 0, 0,
81
+ 0, cosVal, sinVal, 0,
82
+ 0, -sinVal, cosVal, 0,
83
+ 0, 0, 0, 1
84
+ });
85
+ // clang-format on
86
+ }
87
+
88
+ template <>
89
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::RotateY>(double v) {
90
+ const auto cosVal = std::cos(v);
91
+ const auto sinVal = std::sin(v);
92
+ // clang-format off
93
+ return TransformMatrix3D({
94
+ cosVal, 0, -sinVal, 0,
95
+ 0, 1, 0, 0,
96
+ sinVal, 0, cosVal, 0,
97
+ 0, 0, 0, 1
98
+ });
99
+ // clang-format on
100
+ }
101
+
102
+ template <>
103
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::RotateZ>(double v) {
104
+ const auto cosVal = std::cos(v);
105
+ const auto sinVal = std::sin(v);
106
+ // clang-format off
107
+ return TransformMatrix3D({
108
+ cosVal, sinVal, 0, 0,
109
+ -sinVal, cosVal, 0, 0,
110
+ 0, 0, 1, 0,
111
+ 0, 0, 0, 1
112
+ });
113
+ // clang-format on
114
+ }
115
+
116
+ template <>
117
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::Rotate>(double v) {
118
+ return TransformMatrix3D::create<TransformOp::RotateZ>(v);
119
+ }
120
+
121
+ template <>
122
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::Scale>(double v) {
123
+ // clang-format off
124
+ return TransformMatrix3D({
125
+ v, 0, 0, 0,
126
+ 0, v, 0, 0,
127
+ 0, 0, v, 0,
128
+ 0, 0, 0, 1
129
+ });
130
+ // clang-format on
131
+ }
132
+
133
+ template <>
134
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::ScaleX>(double v) {
135
+ // clang-format off
136
+ return TransformMatrix3D({
137
+ v, 0, 0, 0,
138
+ 0, 1, 0, 0,
139
+ 0, 0, 1, 0,
140
+ 0, 0, 0, 1
141
+ });
142
+ // clang-format on
143
+ }
144
+
145
+ template <>
146
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::ScaleY>(double v) {
147
+ // clang-format off
148
+ return TransformMatrix3D({
149
+ 1, 0, 0, 0,
150
+ 0, v, 0, 0,
151
+ 0, 0, 1, 0,
152
+ 0, 0, 0, 1
153
+ });
154
+ // clang-format on
155
+ }
156
+
157
+ template <>
158
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::TranslateX>(double v) {
159
+ // clang-format off
160
+ return TransformMatrix3D({
161
+ 1, 0, 0, 0,
162
+ 0, 1, 0, 0,
163
+ 0, 0, 1, 0,
164
+ v, 0, 0, 1
165
+ });
166
+ // clang-format on
167
+ }
168
+
169
+ template <>
170
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::TranslateY>(double v) {
171
+ // clang-format off
172
+ return TransformMatrix3D({
173
+ 1, 0, 0, 0,
174
+ 0, 1, 0, 0,
175
+ 0, 0, 1, 0,
176
+ 0, v, 0, 1
177
+ });
178
+ // clang-format on
179
+ }
180
+
181
+ template <>
182
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::SkewX>(double v) {
183
+ const auto tanVal = std::tan(v);
184
+ // clang-format off
185
+ return TransformMatrix3D({
186
+ 1, 0, 0, 0,
187
+ tanVal, 1, 0, 0,
188
+ 0, 0, 1, 0,
189
+ 0, 0, 0, 1
190
+ });
191
+ // clang-format on
192
+ }
193
+
194
+ template <>
195
+ TransformMatrix3D TransformMatrix3D::create<TransformOp::SkewY>(double v) {
196
+ const auto tanVal = std::tan(v);
197
+ // clang-format off
198
+ return TransformMatrix3D({
199
+ 1, tanVal, 0, 0,
200
+ 0, 1, 0, 0,
201
+ 0, 0, 1, 0,
202
+ 0, 0, 0, 1
203
+ });
204
+ // clang-format on
205
+ }
206
+
207
+ template <TransformOp TOperation>
208
+ TransformMatrix3D TransformMatrix3D::create(double value) {
209
+ throw std::invalid_argument(
210
+ "[Reanimated] Cannot create TransformMatrix3D from: " + getTransformOperationName(TOperation));
211
+ }
212
+
213
+ TransformMatrix3D TransformMatrix3D::from2D(const TransformMatrix2D &m) {
214
+ // clang-format off
215
+ return TransformMatrix3D({
216
+ m[0], m[1], 0, m[2],
217
+ m[3], m[4], 0, m[5],
218
+ 0, 0, 1, 0,
219
+ m[6], m[7], 0, m[8]
220
+ });
221
+ // clang-format on
222
+ }
223
+
224
+ Vector4D operator*(const Vector4D &v, const TransformMatrix3D &m) {
225
+ Vector4D result;
226
+
227
+ for (size_t i = 0; i < 4; ++i) {
228
+ for (size_t j = 0; j < 4; ++j) {
229
+ result[i] += v[j] * m[j * 4 + i];
230
+ }
231
+ }
232
+
233
+ return result;
234
+ }
235
+
236
+ #ifndef NDEBUG
237
+
238
+ std::ostream &operator<<(std::ostream &os, const TransformMatrix3D &matrix) {
239
+ std::string result = "TransformMatrix3D{";
240
+ for (size_t i = 0; i < 16; ++i) {
241
+ result += std::to_string(matrix[i]);
242
+ if (i < 15) {
243
+ result += ", ";
244
+ }
245
+ }
246
+ result += "}";
247
+ return os << result;
248
+ }
249
+
250
+ #endif // NDEBUG
251
+
252
+ /**
253
+ * Calculates the determinant of the 4x4 matrix using the minor (Laplace
254
+ * expansion) method.
255
+ *
256
+ * | a1 a2 a3 a4 |
257
+ * | b1 b2 b3 b4 |
258
+ * | c1 c2 c3 c4 |
259
+ * | d1 d2 d3 d4 |
260
+ */
261
+ double TransformMatrix3D::determinant() const {
262
+ const double a1 = matrix_[0];
263
+ const double b1 = matrix_[1];
264
+ const double c1 = matrix_[2];
265
+ const double d1 = matrix_[3];
266
+
267
+ const double a2 = matrix_[4];
268
+ const double b2 = matrix_[5];
269
+ const double c2 = matrix_[6];
270
+ const double d2 = matrix_[7];
271
+
272
+ const double a3 = matrix_[8];
273
+ const double b3 = matrix_[9];
274
+ const double c3 = matrix_[10];
275
+ const double d3 = matrix_[11];
276
+
277
+ const double a4 = matrix_[12];
278
+ const double b4 = matrix_[13];
279
+ const double c4 = matrix_[14];
280
+ const double d4 = matrix_[15];
281
+
282
+ return a1 * determinant3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4) -
283
+ b1 * determinant3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4) +
284
+ c1 * determinant3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4) - d1 * determinant3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4);
285
+ }
286
+
287
+ void TransformMatrix3D::adjugate() {
288
+ const double a1 = matrix_[0];
289
+ const double b1 = matrix_[1];
290
+ const double c1 = matrix_[2];
291
+ const double d1 = matrix_[3];
292
+
293
+ const double a2 = matrix_[4];
294
+ const double b2 = matrix_[5];
295
+ const double c2 = matrix_[6];
296
+ const double d2 = matrix_[7];
297
+
298
+ const double a3 = matrix_[8];
299
+ const double b3 = matrix_[9];
300
+ const double c3 = matrix_[10];
301
+ const double d3 = matrix_[11];
302
+
303
+ const double a4 = matrix_[12];
304
+ const double b4 = matrix_[13];
305
+ const double c4 = matrix_[14];
306
+ const double d4 = matrix_[15];
307
+
308
+ matrix_[0] = determinant3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4);
309
+ matrix_[4] = -determinant3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4);
310
+ matrix_[8] = determinant3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4);
311
+ matrix_[12] = -determinant3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4);
312
+
313
+ matrix_[1] = -determinant3x3(b1, b3, b4, c1, c3, c4, d1, d3, d4);
314
+ matrix_[5] = determinant3x3(a1, a3, a4, c1, c3, c4, d1, d3, d4);
315
+ matrix_[9] = -determinant3x3(a1, a3, a4, b1, b3, b4, d1, d3, d4);
316
+ matrix_[13] = determinant3x3(a1, a3, a4, b1, b3, b4, c1, c3, c4);
317
+
318
+ matrix_[2] = determinant3x3(b1, b2, b4, c1, c2, c4, d1, d2, d4);
319
+ matrix_[6] = -determinant3x3(a1, a2, a4, c1, c2, c4, d1, d2, d4);
320
+ matrix_[10] = determinant3x3(a1, a2, a4, b1, b2, b4, d1, d2, d4);
321
+ matrix_[14] = -determinant3x3(a1, a2, a4, b1, b2, b4, c1, c2, c4);
322
+
323
+ matrix_[3] = -determinant3x3(b1, b2, b3, c1, c2, c3, d1, d2, d3);
324
+ matrix_[7] = determinant3x3(a1, a2, a3, c1, c2, c3, d1, d2, d3);
325
+ matrix_[11] = -determinant3x3(a1, a2, a3, b1, b2, b3, d1, d2, d3);
326
+ matrix_[15] = determinant3x3(a1, a2, a3, b1, b2, b3, c1, c2, c3);
327
+ }
328
+
329
+ bool TransformMatrix3D::invert() {
330
+ const auto det = determinant();
331
+
332
+ // If the determinant is invalid (zero, very small number, etc.), then the
333
+ // matrix is not invertible
334
+ if (!std::isnormal(det)) {
335
+ return false;
336
+ }
337
+
338
+ adjugate();
339
+ for (size_t i = 0; i < 16; ++i) {
340
+ matrix_[i] /= det;
341
+ }
342
+
343
+ return true;
344
+ }
345
+
346
+ void TransformMatrix3D::translate3d(const Vector3D &translation) {
347
+ for (size_t i = 0; i < 4; ++i) {
348
+ matrix_[12 + i] += translation[0] * matrix_[i] + translation[1] * matrix_[4 + i] + translation[2] * matrix_[8 + i];
349
+ }
350
+ }
351
+
352
+ void TransformMatrix3D::scale3d(const Vector3D &scale) {
353
+ for (size_t i = 0; i < 4; ++i) {
354
+ matrix_[i] *= scale[0];
355
+ matrix_[4 + i] *= scale[1];
356
+ matrix_[8 + i] *= scale[2];
357
+ }
358
+ }
359
+
360
+ std::optional<TransformMatrix3D::Decomposed> TransformMatrix3D::decompose() const {
361
+ auto matrixCp = *this;
362
+
363
+ if (!matrixCp.normalize()) {
364
+ return std::nullopt;
365
+ }
366
+ const auto perspective = matrixCp.computePerspective();
367
+ if (!perspective) {
368
+ return std::nullopt;
369
+ }
370
+ const auto translation = matrixCp.getTranslation();
371
+
372
+ // Move the remaining matrix to 3 separate column vectors for easier
373
+ // processing
374
+ std::array<Vector3D, 3> rows;
375
+ for (size_t i = 0; i < 3; ++i) {
376
+ rows[i] = Vector3D(matrixCp[i * 4], matrixCp[i * 4 + 1], matrixCp[i * 4 + 2]);
377
+ }
378
+
379
+ auto [scale, skew] = computeScaleAndSkew(rows);
380
+
381
+ // At this point, the matrix (in rows) is orthonormal.
382
+ // Check for a coordinate system flip. If the determinant
383
+ // is negative, then negate the matrix and the scaling factors.
384
+ if (rows[0].dot(rows[1].cross(rows[2])) < 0) {
385
+ scale *= -1;
386
+ for (auto &row : rows) {
387
+ row *= -1;
388
+ }
389
+ }
390
+ const auto rotation = computeQuaternion(rows);
391
+
392
+ return TransformMatrix3D::Decomposed{
393
+ .scale = scale,
394
+ .skew = skew,
395
+ .quaternion = rotation,
396
+ .translation = translation,
397
+ .perspective = perspective.value()};
398
+ }
399
+
400
+ TransformMatrix3D TransformMatrix3D::recompose(const TransformMatrix3D::Decomposed &decomposed) {
401
+ auto result = TransformMatrix3D();
402
+
403
+ // Start from applying perspective
404
+ for (size_t i = 0; i < 4; ++i) {
405
+ result[3 + i * 4] = decomposed.perspective[i];
406
+ }
407
+
408
+ // Apply translation
409
+ result.translate3d(decomposed.translation);
410
+
411
+ // Apply rotation
412
+ result = fromQuaternion(decomposed.quaternion) * result;
413
+
414
+ // Apply skew
415
+ auto hasSkewYZ = decomposed.skew[2] != 0;
416
+ auto hasSkewXZ = decomposed.skew[1] != 0;
417
+ auto hasSkewXY = decomposed.skew[0] != 0;
418
+
419
+ if (hasSkewYZ || hasSkewXZ || hasSkewXY) {
420
+ auto tmp = TransformMatrix3D();
421
+ if (hasSkewYZ) { // YZ
422
+ tmp[9] = decomposed.skew[2];
423
+ result = tmp * result;
424
+ }
425
+ if (hasSkewXZ) { // XZ
426
+ tmp[8] = decomposed.skew[1];
427
+ result = tmp * result;
428
+ }
429
+ if (hasSkewXY) { // XY
430
+ tmp[4] = decomposed.skew[0];
431
+ result = tmp * result;
432
+ }
433
+ }
434
+
435
+ // Apply scale
436
+ result.scale3d(decomposed.scale);
437
+
438
+ return result;
439
+ }
440
+
441
+ TransformMatrix3D TransformMatrix3D::fromQuaternion(const Quaternion &q) {
442
+ const double xx = q.x * q.x;
443
+ const double yy = q.y * q.y;
444
+ const double zz = q.z * q.z;
445
+ const double xz = q.x * q.z;
446
+ const double xy = q.x * q.y;
447
+ const double yz = q.y * q.z;
448
+ const double xw = q.w * q.x;
449
+ const double yw = q.w * q.y;
450
+ const double zw = q.w * q.z;
451
+
452
+ // clang-format off
453
+ return TransformMatrix3D({
454
+ 1 - 2 * (yy + zz), 2 * (xy - zw), 2 * (xz + yw), 0,
455
+ 2 * (xy + zw), 1 - 2 * (xx + zz), 2 * (yz - xw), 0,
456
+ 2 * (xz - yw), 2 * (yz + xw), 1 - 2 * (xx + yy), 0,
457
+ 0, 0, 0, 1
458
+ });
459
+ // clang-format on
460
+ }
461
+
462
+ std::optional<Vector4D> TransformMatrix3D::computePerspective() const {
463
+ auto perspectiveMatrix = *this;
464
+
465
+ for (size_t i = 0; i < 3; ++i) {
466
+ perspectiveMatrix[3 + i * 4] = 0;
467
+ }
468
+ perspectiveMatrix[15] = 1;
469
+
470
+ if (perspectiveMatrix.isSingular()) {
471
+ return std::nullopt;
472
+ }
473
+
474
+ if (matrix_[3] == 0 && matrix_[7] == 0 && matrix_[11] == 0) {
475
+ // No perspective
476
+ return Vector4D{0, 0, 0, 1};
477
+ }
478
+
479
+ // Invert and transpose the perspective matrix (we will solve the equation
480
+ // by multiplying the rhs vector by the inverse of the perspective matrix)
481
+ if (!perspectiveMatrix.invert()) {
482
+ return std::nullopt;
483
+ }
484
+ perspectiveMatrix.transpose();
485
+
486
+ // rhs is the right hand side of the equation we are trying to solve
487
+ const Vector4D rhs(matrix_[3], matrix_[7], matrix_[11], matrix_[15]);
488
+ // Solve the equation
489
+ return rhs * perspectiveMatrix;
490
+ }
491
+
492
+ Vector3D TransformMatrix3D::getTranslation() const {
493
+ return Vector3D(matrix_[12], matrix_[13], matrix_[14]);
494
+ }
495
+
496
+ std::pair<Vector3D, Vector3D> TransformMatrix3D::computeScaleAndSkew(std::array<Vector3D, 3> &rows) {
497
+ Vector3D scale, skew;
498
+
499
+ // Compute X scale factor and normalize first row
500
+ scale[0] = rows[0].length();
501
+ rows[0].normalize();
502
+
503
+ // Compute XY shear factor and make 2nd row orthogonal to 1st.
504
+ skew[0] = rows[0].dot(rows[1]);
505
+ rows[1] = rows[1].addScaled(rows[0], -skew[0]);
506
+
507
+ // Now, compute Y scale and normalize 2nd row.
508
+ scale[1] = rows[1].length();
509
+ rows[1].normalize();
510
+ skew[0] /= scale[1]; // normalize XY shear
511
+
512
+ // Compute XZ and YZ shears, orthogonalize 3rd row
513
+ skew[1] = rows[0].dot(rows[2]);
514
+ rows[2] = rows[2].addScaled(rows[0], -skew[1]);
515
+ skew[2] = rows[1].dot(rows[2]);
516
+ rows[2] = rows[2].addScaled(rows[1], -skew[2]);
517
+
518
+ // Next, get Z scale and normalize 3rd row
519
+ scale[2] = rows[2].length();
520
+ rows[2].normalize();
521
+ skew[1] /= scale[2]; // normalize XZ shear
522
+ skew[2] /= scale[2]; // normalize YZ shear
523
+
524
+ return {scale, skew};
525
+ }
526
+
527
+ Quaternion TransformMatrix3D::computeQuaternion(std::array<Vector3D, 3> &rows) {
528
+ double m00 = rows[0][0];
529
+ double m01 = rows[0][1];
530
+ double m02 = rows[0][2];
531
+
532
+ double m10 = rows[1][0];
533
+ double m11 = rows[1][1];
534
+ double m12 = rows[1][2];
535
+
536
+ double m20 = rows[2][0];
537
+ double m21 = rows[2][1];
538
+ double m22 = rows[2][2];
539
+
540
+ Quaternion q;
541
+ double trace = m00 + m11 + m22; // Trace of the matrix
542
+
543
+ if (trace > 0.0) {
544
+ double s = 0.5 / sqrt(trace + 1.0);
545
+ q.w = 0.25 / s;
546
+ q.x = (m21 - m12) * s;
547
+ q.y = (m02 - m20) * s;
548
+ q.z = (m10 - m01) * s;
549
+ } else {
550
+ if (m00 > m11 && m00 > m22) {
551
+ double s = 2.0 * sqrt(1.0 + m00 - m11 - m22);
552
+ q.w = (m21 - m12) / s;
553
+ q.x = 0.25 * s;
554
+ q.y = (m01 + m10) / s;
555
+ q.z = (m02 + m20) / s;
556
+ } else if (m11 > m22) {
557
+ double s = 2.0 * sqrt(1.0 + m11 - m00 - m22);
558
+ q.w = (m02 - m20) / s;
559
+ q.x = (m01 + m10) / s;
560
+ q.y = 0.25 * s;
561
+ q.z = (m12 + m21) / s;
562
+ } else {
563
+ double s = 2.0 * sqrt(1.0 + m22 - m00 - m11);
564
+ q.w = (m10 - m01) / s;
565
+ q.x = (m02 + m20) / s;
566
+ q.y = (m12 + m21) / s;
567
+ q.z = 0.25 * s;
568
+ }
569
+ }
570
+
571
+ return q;
572
+ }
573
+
574
+ /**
575
+ * Calculate the determinant of a 3x3 matrix
576
+ *
577
+ * | a b c |
578
+ * | d e f |
579
+ * | g h i |
580
+ */
581
+ double TransformMatrix3D::determinant3x3(
582
+ const double a,
583
+ const double b,
584
+ const double c,
585
+ const double d,
586
+ const double e,
587
+ const double f,
588
+ const double g,
589
+ const double h,
590
+ const double i) {
591
+ return (a * e * i) + (b * f * g) + (c * d * h) - (c * e * g) - (b * d * i) - (a * f * h);
592
+ }
593
+
594
+ } // namespace reanimated::css