{-# LANGUAGE BlockArguments #-}{-# LANGUAGE ImportQualifiedPost #-}module Support.Fixtures ( xPos , xNeg , yPos , yNeg , zPos , zNeg , intrinsicComposed , intrinsicComposedD , trs , toNDC , intrinsicComposedRef , trsRef , quarterTurn , twelfthTurn , fourteenthTurn , rotationsMatch ) whereimport Geomancyimport Hedgehogimport Data.Foldable (for_)import Linear (M44, V3(..))import Linear qualifiedimport Linear.Epsilon (Epsilon)import Geomancy.DQuaternion qualifiedimport Geomancy.Quaternion qualifiedimport Geomancy.Transform qualified as Transformimport Support.Ball (Ball, balls, enclosed)import Support.Reference.Mat4 qualified as Ref.Mat4import Support.Reference.Quaternion qualified as Ref.Quaternionimport Support.Reference.Transform qualified as Ref.TransformxPos :: Vec3xPos = vec3 1 0 0xNeg :: Vec3xNeg = vec3 (-1) 0 0yPos :: Vec3yPos = vec3 0 1 0yNeg :: Vec3yNeg = vec3 0 (-1) 0zPos :: Vec3zPos = vec3 0 0 1zNeg :: Vec3zNeg = vec3 0 0 (-1)intrinsicComposed :: Float -> Float -> Float -> QuaternionintrinsicComposed roll pitch yaw = Geomancy.Quaternion.axisAngle (vec3 0 1 0) yaw * Geomancy.Quaternion.axisAngle (vec3 1 0 0) pitch * Geomancy.Quaternion.axisAngle (vec3 0 0 1) rollintrinsicComposedD :: Double -> Double -> Double -> DQuaternionintrinsicComposedD roll pitch yaw = Geomancy.DQuaternion.axisAngle (dvec3 0 1 0) yaw * Geomancy.DQuaternion.axisAngle (dvec3 1 0 0) pitch * Geomancy.DQuaternion.axisAngle (dvec3 0 0 1) rolltrs :: Vec3 -> Quaternion -> Vec3 -> Transformtrs t r s = mconcat [ Transform.translateV t , Transform.rotateQ r , Transform.scaleV s ]toNDC :: Vec4 -> Vec3toNDC v = withVec4 v \x y z w -> vec3 (x/w) (y/w) (z/w)intrinsicComposedRef :: (Floating a, Epsilon a) => a -> a -> a -> Linear.Quaternion aintrinsicComposedRef roll pitch yaw = Ref.Quaternion.axisAngle (V3 0 1 0) yaw `Ref.Quaternion.multiply` Ref.Quaternion.axisAngle (V3 1 0 0) pitch `Ref.Quaternion.multiply` Ref.Quaternion.axisAngle (V3 0 0 1) rolltrsRef :: RealFloat p => V3 (Ball p) -> Linear.Quaternion (Ball p) -> V3 (Ball p) -> M44 (Ball p)trsRef t r s = foldr Ref.Mat4.compose Ref.Mat4.identity [ Ref.Transform.translateV t , Ref.Transform.rotateQ r , Ref.Transform.scaleV s ]quarterTurn :: Floating a => aquarterTurn = pi / 2twelfthTurn :: Floating a => atwelfthTurn = pi / 6fourteenthTurn :: Floating a => afourteenthTurn = pi / 7rotationsMatch :: (Show v, Show p, RealFloat p) => (v -> V3 p) -> (v -> v) -> (V3 (Ball p) -> V3 (Ball p)) -> [(v, v)] -> PropertyT IO ()rotationsMatch toV rotate rotateBall cases = for_ cases \(input, expected) -> do let rotated = rotate input rotatedBall = rotateBall (balls (toV input)) annotateShow rotated replicate 3 Nothing === enclosed rotatedBall (toV rotated) replicate 3 Nothing === enclosed rotatedBall (toV expected)