packages feed

AC-Vector-Fancy 2.2.0 → 2.3.0

raw patch · 2 files changed

+43/−34 lines, 2 filesdep ~AC-VectorPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: AC-Vector

API changes (from Hackage documentation)

- Data.Vector.Fancy: instance Project Vector1 Vector2
- Data.Vector.Fancy: instance Project Vector2 Vector3
- Data.Vector.Fancy: instance Project Vector3 Vector4
+ Data.Vector.Fancy: instance Project Vector1
+ Data.Vector.Fancy: instance Project Vector2
+ Data.Vector.Fancy: instance Project Vector3
- Data.Vector.Fancy: class Project lo hi
+ Data.Vector.Fancy: class (Vector v, Vector (ProjectTo v)) => Project v where { type family ProjectTo v :: *; }
- Data.Vector.Fancy: orthographic_down :: (Project lo hi) => hi -> (lo, Scalar)
+ Data.Vector.Fancy: orthographic_down :: (Project v) => ProjectTo v -> (v, Scalar)
- Data.Vector.Fancy: orthographic_up :: (Project lo hi) => (lo, Scalar) -> hi
+ Data.Vector.Fancy: orthographic_up :: (Project v) => (v, Scalar) -> ProjectTo v
- Data.Vector.Fancy: perspective_down :: (Project lo hi) => hi -> (lo, Scalar)
+ Data.Vector.Fancy: perspective_down :: (Project v) => ProjectTo v -> (v, Scalar)
- Data.Vector.Fancy: perspective_up :: (Project lo hi) => (lo, Scalar) -> hi
+ Data.Vector.Fancy: perspective_up :: (Project v) => (v, Scalar) -> ProjectTo v

Files

AC-Vector-Fancy.cabal view
@@ -1,6 +1,6 @@ Cabal-Version: >= 1.6
 Name:          AC-Vector-Fancy
-Version:       2.2.0
+Version:       2.3.0
 Stability:     Experimental
 Synopsis:      Fancy type-system stuff for AC-Vector
 
@@ -10,12 +10,9 @@   (Requires several language extensions, including
   type families.)
 
-  Names updated to match AC-Vector. Gather modules are now
-  here instead of in AC-Vector, and some module names have
-  changed too for greater consistency. Added a new HasSpace
-  class for generically dealing with structures of
-  different dimensionallities (and updated everything else
-  to use it).
+  Changed the @Project@ class from being multi-parameter
+  to using an associated type. (Should help resolve some
+  of the \"ambiguous type\" errors.)
 
 Category:      Data, Math, Numerical, Graphics
 License:       BSD3
@@ -33,5 +30,5 @@     Data.Vector.Transform.Fancy,
     Data.BoundingBox,
     Data.BoundingBox.Fancy
-  Build-Depends:   base >= 4 && < 5, AC-Angle >= 1.0, AC-Vector >= 2.2.0
+  Build-Depends:   base >= 4 && < 5, AC-Angle >= 1.0, AC-Vector >= 2.3.0
   HS-Source-Dirs:  .
Data/Vector/Fancy.hs view
@@ -2,7 +2,7 @@   Various facilities for dealing with vectors, vector spaces and coordinate axies generically.
 -}
 
-{-# LANGUAGE MultiParamTypeClasses, TypeFamilies #-}
+{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses, TypeFamilies #-}
 
 module Data.Vector.Fancy where
 
@@ -37,6 +37,8 @@ instance HasSpace Vector4 where
   type Point Vector4 = Vector4
 
+
+
 -- * Vector axies
 
 -- | The X-axis (first axis).
@@ -59,22 +61,6 @@   -- | Replace the existing value of the given coordinate axis.
   set_coord :: axis -> Scalar -> vector -> vector
 
--- | This class relates two vector types having consecutive sizes.
-class Project lo hi where
-  -- | Reduce number of dimensions by one. (Return the dropped dimension as a @Scalar@.)
-  orthographic_down ::  hi          -> (lo, Scalar)
-
-  -- | Increase number of dimensions by one. (Supply value for new dimension as a @Scalar@.)
-  orthographic_up   :: (lo, Scalar) ->  hi
-
-  -- | Perspective-project to N-1 dimensions. (Also return the distance from the camera as a @Scalar@.)
-  perspective_down ::  hi          -> (lo, Scalar)
-
-  -- | Inverse-perspective project into N+1 dimension. (Supply the distance from the camera as a @Scalar@.)
-  perspective_up   :: (lo, Scalar) ->  hi
-
-
-
 instance VectorAxis Vector1 AxisX where
   get_coord _ = v1x
   set_coord _ x _ = Vector1 x
@@ -117,23 +103,49 @@ 
 
 
-instance Project Vector1 Vector2 where
+-- * Vector projection
+
+{- |
+  This class enables you to take a vector with N dimensions and
+  project it into an N+1 dimensional space (and also take the inverse
+  projection to get back again).
+-}
+class (Vector v, Vector (ProjectTo v)) => Project v where
+  -- | The next-largest vector type. (E.g., 'ProjectTo' 'Vector2' = 'Vector3'.)
+  type ProjectTo v :: *
+
+  -- | Reduce number of dimensions by one. (Return the dropped dimension as a @Scalar@.)
+  orthographic_down ::  ProjectTo v -> (v, Scalar)
+
+  -- | Increase number of dimensions by one. (Supply value for new dimension as a @Scalar@.)
+  orthographic_up   :: (v, Scalar)  -> ProjectTo v
+
+  -- | Perspective-project to N-1 dimensions. (Also return the distance from the camera as a @Scalar@.)
+  perspective_down ::  ProjectTo v  -> (v, Scalar)
+
+  -- | Inverse-perspective project into N+1 dimension. (Supply the distance from the camera as a @Scalar@.)
+  perspective_up   :: (v, Scalar)   ->  ProjectTo v
+
+instance Project Vector1 where
+  type ProjectTo Vector1 = Vector2
   orthographic_down (Vector2 x  y) = (Vector1 x, y)
   orthographic_up   (Vector1 x, y) = (Vector2 x  y)
 
-  perspective_down (Vector2 x  y) = (Vector1 (x/y), y)
-  perspective_up   (Vector1 x, y) = (Vector2 (x*y)  y)
+  perspective_down  (Vector2 x  y) = (Vector1 (x/y), y)
+  perspective_up    (Vector1 x, y) = (Vector2 (x*y)  y)
 
-instance Project Vector2 Vector3 where
+instance Project Vector2 where
+  type ProjectTo Vector2 = Vector3
   orthographic_down (Vector3 x y  z) = (Vector2 x y, z)
   orthographic_up   (Vector2 x y, z) = (Vector3 x y  z)
 
-  perspective_down (Vector3 x y  z) = (Vector2 (x/z) (y/z), z)
-  perspective_up   (Vector2 x y, z) = (Vector3 (x*z) (y*z)  z)
+  perspective_down  (Vector3 x y  z) = (Vector2 (x/z) (y/z), z)
+  perspective_up    (Vector2 x y, z) = (Vector3 (x*z) (y*z)  z)
 
-instance Project Vector3 Vector4 where
+instance Project Vector3 where
+  type ProjectTo Vector3 = Vector4
   orthographic_down (Vector4 x y z  w) = (Vector3 x y z, w)
   orthographic_up   (Vector3 x y z, w) = (Vector4 x y z  w)
 
-  perspective_down (Vector4 x y z  w) = (Vector3 (x/w) (y/w) (z/w), w)
-  perspective_up   (Vector3 x y z, w) = (Vector4 (x*w) (y*w) (z*w)  w)
+  perspective_down  (Vector4 x y z  w) = (Vector3 (x/w) (y/w) (z/w), w)
+  perspective_up    (Vector3 x y z, w) = (Vector4 (x*w) (y*w) (z*w)  w)