AC-Vector-Fancy 2.1.2 → 2.2.0
raw patch · 8 files changed
+248/−145 lines, 8 filesdep ~AC-VectorPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: AC-Vector
API changes (from Hackage documentation)
- Data.BoundingBox: bounds :: (BoundingBox b) => Point b -> Point b -> b
- Data.BoundingBox: class BoundingBox b where { type family Point b :: *; }
- Data.BoundingBox: class HasBBox x where { type family BBox x :: *; }
- Data.BoundingBox: data Range :: *
- Data.BoundingBox: get_bbox :: (HasBBox x) => x -> BBox x
- Data.BoundingBox: instance BoundingBox BBox1
- Data.BoundingBox: instance BoundingBox BBox2
- Data.BoundingBox: instance BoundingBox BBox3
- Data.BoundingBox: instance BoundingBox BBox4
- Data.BoundingBox: instance BoundingBox Range
- Data.BoundingBox: isect :: (BoundingBox b) => b -> b -> Maybe b
- Data.BoundingBox: max_bound :: (BoundingBox b) => b -> Point b
- Data.BoundingBox: min_bound :: (BoundingBox b) => b -> Point b
- Data.BoundingBox: points_bounds :: (BoundingBox b) => [Point b] -> b
- Data.BoundingBox: union :: (BoundingBox b) => b -> b -> b
- Data.BoundingBox: within_bounds :: (BoundingBox b) => Point b -> b -> Bool
- Data.Vector.Axis: AxisW :: AxisW
- Data.Vector.Axis: AxisX :: AxisX
- Data.Vector.Axis: AxisY :: AxisY
- Data.Vector.Axis: AxisZ :: AxisZ
- Data.Vector.Axis: data AxisW
- Data.Vector.Axis: data AxisX
- Data.Vector.Axis: data AxisY
- Data.Vector.Axis: data AxisZ
- Data.Vector.Axis: instance Show AxisW
- Data.Vector.Axis: instance Show AxisX
- Data.Vector.Axis: instance Show AxisY
- Data.Vector.Axis: instance Show AxisZ
- Data.Vector.Transform.Fancy: instance Transformable Transform1 Vector1
- Data.Vector.Transform.Fancy: instance Transformable Transform2 Vector2
- Data.Vector.Transform.Fancy: instance Transformable Transform3 Vector3
- Data.Vector.Transform.Fancy: instance Transformable Transform4 Vector4
+ Data.BoundingBox.Fancy: bound_corners :: (BoundingBox b) => Point b -> Point b -> b
+ Data.BoundingBox.Fancy: bound_points :: (BoundingBox b) => [Point b] -> b
+ Data.BoundingBox.Fancy: class (HasSpace b) => BoundingBox b
+ Data.BoundingBox.Fancy: class (HasSpace x) => HasBBox x
+ Data.BoundingBox.Fancy: get_bbox :: (HasBBox x, BoundingBox b, (Point b) ~ (Point x)) => x -> b
+ Data.BoundingBox.Fancy: instance BoundingBox BBox1
+ Data.BoundingBox.Fancy: instance BoundingBox BBox2
+ Data.BoundingBox.Fancy: instance BoundingBox BBox3
+ Data.BoundingBox.Fancy: instance BoundingBox BBox4
+ Data.BoundingBox.Fancy: instance BoundingBox Range
+ Data.BoundingBox.Fancy: instance HasSpace BBox1
+ Data.BoundingBox.Fancy: instance HasSpace BBox2
+ Data.BoundingBox.Fancy: instance HasSpace BBox3
+ Data.BoundingBox.Fancy: instance HasSpace BBox4
+ Data.BoundingBox.Fancy: instance HasSpace Range
+ Data.BoundingBox.Fancy: isect :: (BoundingBox b) => b -> b -> Maybe b
+ Data.BoundingBox.Fancy: max_point :: (BoundingBox b) => b -> Point b
+ Data.BoundingBox.Fancy: min_point :: (BoundingBox b) => b -> Point b
+ Data.BoundingBox.Fancy: union :: (BoundingBox b) => b -> b -> b
+ Data.BoundingBox.Fancy: within_bounds :: (BoundingBox b) => Point b -> b -> Bool
+ Data.Vector.Fancy: AxisW :: AxisW
+ Data.Vector.Fancy: AxisX :: AxisX
+ Data.Vector.Fancy: AxisY :: AxisY
+ Data.Vector.Fancy: AxisZ :: AxisZ
+ Data.Vector.Fancy: class HasSpace x where { type family Point x :: *; }
+ Data.Vector.Fancy: data AxisW
+ Data.Vector.Fancy: data AxisX
+ Data.Vector.Fancy: data AxisY
+ Data.Vector.Fancy: data AxisZ
+ Data.Vector.Fancy: instance HasSpace Vector1
+ Data.Vector.Fancy: instance HasSpace Vector2
+ Data.Vector.Fancy: instance HasSpace Vector3
+ Data.Vector.Fancy: instance HasSpace Vector4
+ Data.Vector.Fancy: instance Show AxisW
+ Data.Vector.Fancy: instance Show AxisX
+ Data.Vector.Fancy: instance Show AxisY
+ Data.Vector.Fancy: instance Show AxisZ
+ Data.Vector.Transform: data Transform1 :: *
+ Data.Vector.Transform: data Transform2 :: *
+ Data.Vector.Transform: data Transform3 :: *
+ Data.Vector.Transform: data Transform4 :: *
+ Data.Vector.Transform.Fancy: instance HasSpace Transform1
+ Data.Vector.Transform.Fancy: instance HasSpace Transform2
+ Data.Vector.Transform.Fancy: instance HasSpace Transform3
+ Data.Vector.Transform.Fancy: instance HasSpace Transform4
+ Data.Vector.Transform.Fancy: instance Transformable Vector1
+ Data.Vector.Transform.Fancy: instance Transformable Vector2
+ Data.Vector.Transform.Fancy: instance Transformable Vector3
+ Data.Vector.Transform.Fancy: instance Transformable Vector4
- Data.Vector.Transform.Fancy: class Transform t where { type family Point t :: *; }
+ Data.Vector.Transform.Fancy: class (HasSpace t) => Transform t
- Data.Vector.Transform.Fancy: class (Transform t) => Transformable t x
+ Data.Vector.Transform.Fancy: class (HasSpace x) => Transformable x
- Data.Vector.Transform.Fancy: transform :: (Transformable t x) => t -> x -> x
+ Data.Vector.Transform.Fancy: transform :: (Transformable x, Transform t, (Point t) ~ (Point x)) => t -> x -> x
Files
- AC-Vector-Fancy.cabal +14/−7
- Data/BoundingBox.hs +11/−110
- Data/BoundingBox/Fancy.hs +104/−0
- Data/Vector.hs +21/−0
- Data/Vector/Axis.hs +0/−8
- Data/Vector/Fancy.hs +41/−3
- Data/Vector/Transform.hs +35/−0
- Data/Vector/Transform/Fancy.hs +22/−17
AC-Vector-Fancy.cabal view
@@ -1,16 +1,21 @@ Cabal-Version: >= 1.6 Name: AC-Vector-Fancy -Version: 2.1.2 +Version: 2.2.0 Stability: Experimental -Synopsis: Fancy type system stuff for AC-Vector +Synopsis: Fancy type-system stuff for AC-Vector Description: - Adds various type system tricks to AC-Vector. + Adds various type-system tricks to AC-Vector. (Requires several language extensions, including type families.) - Now includes @points_bounds@ method. + 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). Category: Data, Math, Numerical, Graphics License: BSD3 @@ -22,9 +27,11 @@ Library Exposed-modules: - Data.Vector.Axis, + Data.Vector, Data.Vector.Fancy, + Data.Vector.Transform, Data.Vector.Transform.Fancy, - Data.BoundingBox - Build-Depends: base >= 4 && < 5, AC-Angle >= 1.0, AC-Vector >= 2.1.1 + Data.BoundingBox, + Data.BoundingBox.Fancy + Build-Depends: base >= 4 && < 5, AC-Angle >= 1.0, AC-Vector >= 2.2.0 HS-Source-Dirs: .
Data/BoundingBox.hs view
@@ -1,118 +1,19 @@ {- | - Bounding boxes of various numbers of dimensions, plus a class for generically handling them. + Convinience module providing all bounding box functionallity in one place. -} -{-# LANGUAGE TypeFamilies #-} - module Data.BoundingBox ( - -- * Classes - BoundingBox (..), HasBBox (..), - - -- * Types - - -- ** 1 dimension - R.Range (), B1.BBox1 (), - - -- ** 2 dimensions - B2.BBox2 (), - - -- ** 3 dimensions - B3.BBox3 (), - - -- ** 4 dimensions - B4.BBox4 () + module Data.BoundingBox.Fancy, + BBox1 (), + BBox2 (), + BBox3 (), + BBox4 () ) where -import Data.Vector -import qualified Data.BoundingBox.Range as R -import qualified Data.BoundingBox.B1 as B1 -import qualified Data.BoundingBox.B2 as B2 -import qualified Data.BoundingBox.B3 as B3 -import qualified Data.BoundingBox.B4 as B4 - --- | Class for dealing with bounding boxes. -class BoundingBox b where - -- | The type of vectors that this bounding box deals with. - type Point b :: * - - -- | Given two corner points, construct a bounding box containing them both. (You can use any two points, given in any order, provided that they are from /opposite/ corners.) - bounds :: Point b -> Point b -> b - - -- | Given a list of points, construct a bounding box containing them all. (Throws an exception if the list is empty.) - points_bounds :: [Point b] -> b - - -- | Return a point containing the minimum values for all coordinates. - min_bound :: b -> Point b - - -- | Return a point containing the maximum values for all coordinates. - max_bound :: b -> Point b - - -- | Test whether a given point lies within a given bounding box. - within_bounds :: Point b -> b -> Bool - - -- | Take the union of two bounding boxes. The result is a new bounding box that contains every point that the original pair of boxes contained, and probably some extra space as well. - union :: b -> b -> b - - -- | Take the intersection of two bounding boxes. If the boxes do not overlap, return 'Nothing'. Otherwise return a bounding box containing only the points common to both original bounding boxes. - isect :: b -> b -> Maybe b - -instance BoundingBox R.Range where - type Point R.Range = Scalar - bounds = R.bounds - points_bounds = R.points_bounds - min_bound = R.min_bound - max_bound = R.max_bound - within_bounds = R.within_bounds - union = R.union - isect = R.isect - -instance BoundingBox B1.BBox1 where - type Point B1.BBox1 = Vector1 - bounds = B1.bounds - points_bounds = B1.points_bounds - min_bound = B1.min_bound - max_bound = B1.max_bound - within_bounds = B1.within_bounds - union = B1.union - isect = B1.isect - -instance BoundingBox B2.BBox2 where - type Point B2.BBox2 = Vector2 - bounds = B2.bounds - points_bounds = B2.points_bounds - min_bound = B2.min_bound - max_bound = B2.max_bound - within_bounds = B2.within_bounds - union = B2.union - isect = B2.isect - -instance BoundingBox B3.BBox3 where - type Point B3.BBox3 = Vector3 - bounds = B3.bounds - points_bounds = B3.points_bounds - min_bound = B3.min_bound - max_bound = B3.max_bound - within_bounds = B3.within_bounds - union = B3.union - isect = B3.isect - -instance BoundingBox B4.BBox4 where - type Point B4.BBox4 = Vector4 - bounds = B4.bounds - points_bounds = B4.points_bounds - min_bound = B4.min_bound - max_bound = B4.max_bound - within_bounds = B4.within_bounds - union = B4.union - isect = B4.isect - - --- | Class representing things that possess a bounding box. -class HasBBox x where - -- | The type of bounding box. (Varies depending in the required number of dimensions.) - type BBox x :: * - - -- | Get an object's bounding box. - get_bbox :: x -> BBox x +import Data.BoundingBox.B1 +import Data.BoundingBox.B2 +import Data.BoundingBox.B3 +import Data.BoundingBox.B4 +import Data.BoundingBox.Fancy
+ Data/BoundingBox/Fancy.hs view
@@ -0,0 +1,104 @@+{- | + Classes for generically handling bounding boxes, and things that possess bounding boxes. +-} + +{-# LANGUAGE TypeFamilies #-} + +module Data.BoundingBox.Fancy where + +import Data.Vector +import qualified Data.BoundingBox.Range as R +import qualified Data.BoundingBox.B1 as B1 +import qualified Data.BoundingBox.B2 as B2 +import qualified Data.BoundingBox.B3 as B3 +import qualified Data.BoundingBox.B4 as B4 + +-- | Class for dealing with bounding boxes. +class HasSpace b => BoundingBox b where + -- | Given two corner points, construct a bounding box containing them both. (You can use any two points, given in any order, provided that they are from /opposite/ corners.) + bound_corners :: Point b -> Point b -> b + + -- | Given a list of points, construct a bounding box containing them all. (Throws an exception if the list is empty.) + bound_points :: [Point b] -> b + + -- | Return a point containing the minimum values for all coordinates. + min_point :: b -> Point b + + -- | Return a point containing the maximum values for all coordinates. + max_point :: b -> Point b + + -- | Test whether a given point lies within a given bounding box. + within_bounds :: Point b -> b -> Bool + + -- | Take the union of two bounding boxes. The result is a new bounding box that contains every point that the original pair of boxes contained, and probably some extra space as well. + union :: b -> b -> b + + -- | Take the intersection of two bounding boxes. If the boxes do not overlap, return 'Nothing'. Otherwise return a bounding box containing only the points common to both original bounding boxes. + isect :: b -> b -> Maybe b + +instance HasSpace R.Range where + type Point R.Range = Scalar + +instance BoundingBox R.Range where + bound_corners = R.bound_corners + bound_points = R.bound_points + min_point = R.min_point + max_point = R.max_point + within_bounds = R.within_bounds + union = R.union + isect = R.isect + +instance HasSpace B1.BBox1 where + type Point B1.BBox1 = Vector1 + +instance BoundingBox B1.BBox1 where + bound_corners = B1.bound_corners + bound_points = B1.bound_points + min_point = B1.min_point + max_point = B1.max_point + within_bounds = B1.within_bounds + union = B1.union + isect = B1.isect + +instance HasSpace B2.BBox2 where + type Point B2.BBox2 = Vector2 + +instance BoundingBox B2.BBox2 where + bound_corners = B2.bound_corners + bound_points = B2.bound_points + min_point = B2.min_point + max_point = B2.max_point + within_bounds = B2.within_bounds + union = B2.union + isect = B2.isect + +instance HasSpace B3.BBox3 where + type Point B3.BBox3 = Vector3 + +instance BoundingBox B3.BBox3 where + bound_corners = B3.bound_corners + bound_points = B3.bound_points + min_point = B3.min_point + max_point = B3.max_point + within_bounds = B3.within_bounds + union = B3.union + isect = B3.isect + +instance HasSpace B4.BBox4 where + type Point B4.BBox4 = Vector4 + +instance BoundingBox B4.BBox4 where + bound_corners = B4.bound_corners + bound_points = B4.bound_points + min_point = B4.min_point + max_point = B4.max_point + within_bounds = B4.within_bounds + union = B4.union + isect = B4.isect + + + +-- | Class representing things that possess a bounding box. +class HasSpace x => HasBBox x where + -- | Get an object's bounding box. + get_bbox :: (BoundingBox b, Point b ~ Point x) => x -> b
+ Data/Vector.hs view
@@ -0,0 +1,21 @@+{- | + Convinience module providing all directly vector-related functionallity in one place. +-} + +module Data.Vector + ( + module Data.Vector.Class, + module Data.Vector.V1, + module Data.Vector.V2, + module Data.Vector.V3, + module Data.Vector.V4, + module Data.Vector.Fancy, + ) + where + +import Data.Vector.Class +import Data.Vector.V1 +import Data.Vector.V2 +import Data.Vector.V3 +import Data.Vector.V4 +import Data.Vector.Fancy
− Data/Vector/Axis.hs
@@ -1,8 +0,0 @@--- | Types denoting coordinate axies. - -module Data.Vector.Axis where - -data AxisX = AxisX deriving Show -data AxisY = AxisY deriving Show -data AxisZ = AxisZ deriving Show -data AxisW = AxisW deriving Show
Data/Vector/Fancy.hs view
@@ -1,8 +1,8 @@ {- | - Various facilities for dealing with vectors generically. + Various facilities for dealing with vectors, vector spaces and coordinate axies generically. -} -{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE MultiParamTypeClasses, TypeFamilies #-} module Data.Vector.Fancy where @@ -11,7 +11,45 @@ import Data.Vector.V2 import Data.Vector.V3 import Data.Vector.V4 -import Data.Vector.Axis + +-- * Vector spaces + +{- | + This class deals with any type that has a spatial dimensionallity. + This includes coordinate transforms, bounding boxes, and so on. + + Null instances are provided for all the vector types. (E.g., + @Point Vector3 = Vector3@.) +-} +class HasSpace x where + -- | Give the appropriate kind of vector for this type. + type Point x :: * + +instance HasSpace Vector1 where + type Point Vector1 = Vector1 + +instance HasSpace Vector2 where + type Point Vector2 = Vector2 + +instance HasSpace Vector3 where + type Point Vector3 = Vector3 + +instance HasSpace Vector4 where + type Point Vector4 = Vector4 + +-- * Vector axies + +-- | The X-axis (first axis). +data AxisX = AxisX deriving Show + +-- | The Y-axis (second axis). +data AxisY = AxisY deriving Show + +-- | The Z-axis (third axis). +data AxisZ = AxisZ deriving Show + +-- | The W-axis (fourth axis). +data AxisW = AxisW deriving Show -- | Class for generically reading/writing vector coordinates. class VectorAxis vector axis where
+ Data/Vector/Transform.hs view
@@ -0,0 +1,35 @@+{- | + Convinience module providing all transform functionallity in one place. + + Note that the transform constructors and fields are not exported from here, + since the names clash. However, "Data.Vector.Transform.Fancy" provides + methods for constructing transforms generically, so that shouldn't be + an issue. +-} + +module Data.Vector.Transform + ( + -- * Transform classes + module Data.Vector.Transform.Fancy, + + -- * Transformation types + + -- ** 1-dimensional transforms + Transform1 (), + + -- ** 2-dimensional transforms + Transform2 (), + + -- ** 3-dimensional transforms + Transform3 (), + + -- ** 4-dimensional transforms + Transform4 (), + ) + where + +import Data.Vector.Transform.T1 +import Data.Vector.Transform.T2 +import Data.Vector.Transform.T3 +import Data.Vector.Transform.T4 +import Data.Vector.Transform.Fancy
Data/Vector/Transform/Fancy.hs view
@@ -13,17 +13,14 @@ import Data.Vector.V2 import Data.Vector.V3 import Data.Vector.V4 -import Data.Vector.Axis +import Data.Vector.Fancy import Data.Vector.Transform.T1 import Data.Vector.Transform.T2 import Data.Vector.Transform.T3 import Data.Vector.Transform.T4 -- | Class for transforms. -class Transform t where - -- | The type of vector that can be transformed. (E.g., for @Transform3@, this would be @Vector3@.) - type Point t :: * - +class HasSpace t => Transform t where -- | Transform a vector. transformP :: t -> Point t -> Point t @@ -41,36 +38,44 @@ -- | Build transform: rotate in the plane defined by the two axies. rotateT :: (Angle a) => axis1 -> axis2 -> a Scalar -> t --- | Class for things that can be transformed (by a specific type of transform). -class (Transform t) => Transformable t x where - -- | Transform anything that can be transformed (for a given type of transform). - transform :: t -> x -> x +-- | Class for things that can be transformed. Includes instances for all the vector types. +class HasSpace x => Transformable x where + -- | Apply a transformation. + transform :: (Transform t, Point t ~ Point x) => t -> x -> x -instance Transform Transform1 where +instance HasSpace Transform1 where type Point Transform1 = Vector1 + +instance Transform Transform1 where transformP = transformP1 translateT (Vector1 x) = Transform1 1 x scaleT (Vector1 x) = Transform1 x 0 scaleT_ k = Transform1 k 0 -instance Transform Transform2 where +instance HasSpace Transform2 where type Point Transform2 = Vector2 + +instance Transform Transform2 where transformP = transformP2 translateT (Vector2 x y) = Transform2 1 0 x 0 1 y scaleT (Vector2 x y) = Transform2 x 0 0 0 y 0 scaleT_ k = Transform2 k 0 0 0 k 0 -instance Transform Transform3 where +instance HasSpace Transform3 where type Point Transform3 = Vector3 + +instance Transform Transform3 where transformP = transformP3 translateT (Vector3 x y z) = Transform3 1 0 0 x 0 1 0 y 0 0 1 z scaleT (Vector3 x y z) = Transform3 x 0 0 0 0 y 0 0 0 0 z 0 scaleT_ k = Transform3 k 0 0 0 0 k 0 0 0 0 k 0 -instance Transform Transform4 where +instance HasSpace Transform4 where type Point Transform4 = Vector4 + +instance Transform Transform4 where transformP = transformP4 translateT (Vector4 x y z w) = Transform4 1 0 0 0 x 0 1 0 0 y 0 0 1 0 z 0 0 0 1 w scaleT (Vector4 x y z w) = Transform4 x 0 0 0 0 0 y 0 0 0 0 0 z 0 0 0 0 0 w 0 @@ -78,10 +83,10 @@ -instance Transformable Transform1 Vector1 where transform = transformP1 -instance Transformable Transform2 Vector2 where transform = transformP2 -instance Transformable Transform3 Vector3 where transform = transformP3 -instance Transformable Transform4 Vector4 where transform = transformP4 +instance Transformable Vector1 where transform = transformP +instance Transformable Vector2 where transform = transformP +instance Transformable Vector3 where transform = transformP +instance Transformable Vector4 where transform = transformP