# Aelve Codesearch

grep over package repositories
Please provide a string to search for.
3+ characters are required.
Index updated 4 hours ago

#### total matches: more than 1000

##### AC-Vector-2.3.2
30 matches
Data/BoundingBox/B1.hs
``````
-- | Find the bounds of a list of points. (Throws an exception if the list is empty.)
bound_points :: [Vector1] -> BBox1
bound_points = BBox1 . R.bound_points . map v1x

-- | Test whether a 'Vector1' lies within a 'BBox1'.
within_bounds :: Vector1 -> BBox1 -> Bool
within_bounds (Vector1 x) (BBox1 r) = x `R.within_bounds` r

```
```
Data/BoundingBox/B1.hs
``````
-- | Efficiently compute the union of a list of bounding boxes.
unions :: [BBox1] -> BBox1
unions = BBox1 . R.unions . map range
```
```
Data/BoundingBox/B2.hs
``````bound_points :: [Vector2] -> BBox2
bound_points ps =
let
xs = map v2x ps
ys = map v2y ps
in BBox2 (minimum xs) (minimum ys) (maximum xs) (maximum ys)

-- | Test whether a given 2D vector is inside this bounding box.
within_bounds :: Vector2 -> BBox2 -> Bool
within_bounds (Vector2 x y) b =
```
```
Data/BoundingBox/B2.hs
``````unions :: [BBox2] -> BBox2
unions bs =
let
minP = map min_point bs
maxP = map max_point bs
in
BBox2
(minimum \$ map v2x minP) (minimum \$ map v2y minP)
(maximum \$ map v2x maxP) (maximum \$ map v2y maxP)
```
```
Data/BoundingBox/B3.hs
``````bound_points :: [Vector3] -> BBox3
bound_points ps =
let
xs = map v3x ps
ys = map v3y ps
zs = map v3z ps
in BBox3 (minimum xs) (minimum ys) (minimum zs) (maximum xs) (maximum ys) (maximum zs)

-- | Test whether a given 3D vector is inside this bounding box.
within_bounds :: Vector3 -> BBox3 -> Bool
within_bounds (Vector3 x y z) b =
```
```
Data/BoundingBox/B3.hs
``````unions :: [BBox3] -> BBox3
unions bs =
let
minP = map min_point bs
maxP = map max_point bs
in
BBox3
(minimum \$ map v3x minP) (minimum \$ map v3y minP) (minimum \$ map v3z minP)
(maximum \$ map v3x maxP) (maximum \$ map v3y maxP) (maximum \$ map v3z maxP)
```
```
Data/BoundingBox/B4.hs
``````bound_points :: [Vector4] -> BBox4
bound_points ps =
let
xs = map v4x ps
ys = map v4y ps
zs = map v4z ps
ws = map v4w ps
in BBox4 (minimum xs) (minimum ys) (minimum zs) (minimum ws) (maximum xs) (maximum ys) (maximum zs) (maximum ws)

-- | Test whether a given 4D vector is inside this bounding box.
within_bounds :: Vector4 -> BBox4 -> Bool
within_bounds (Vector4 x y z w) b =
```
```
Data/BoundingBox/B4.hs
``````unions :: [BBox4] -> BBox4
unions bs =
let
minP = map min_point bs
maxP = map max_point bs
in
BBox4
(minimum \$ map v4x minP) (minimum \$ map v4y minP) (minimum \$ map v4z minP) (minimum \$ map v4w minP)
(maximum \$ map v4x maxP) (maximum \$ map v4y maxP) (maximum \$ map v4z maxP) (maximum \$ map v4w maxP)
```
```
Data/BoundingBox/Range.hs
``````
-- | Efficiently compute the union of a list of ranges.
unions :: [Range] -> Range
unions rs = Range (minimum \$ map min_point rs) (maximum \$ map max_point rs)
```
```
Data/Vector/Class.hs
``````-}
class BasicVector v where
-- | Apply a function to all vector fields.
vmap    :: (Scalar -> Scalar) -> (v -> v)

-- | Zip two vectors together field-by-field using the supplied function (in the style of @Data.List.zipWith@).
vzip    :: (Scalar -> Scalar -> Scalar) -> (v -> v -> v)

-- | Reduce a vector down to a single value using the supplied binary operator. The ordering in which this happens isn't guaranteed, so the operator should probably be associative and commutative.
```
```
Data/Vector/Class.hs
``````  The @(*|)@ and @(|*)@ operators are identical, but with their argument flipped. Just remember that the \'@|@\' denotes the scalar part.
-}
(*|) :: Vector v => Scalar -> v -> v
k *| v = vmap (k*) v

{- |
Scale a vector (i.e., change its length but not its direction). This operator has the same precedence as the usual @(*)@ operator.

The @(*|)@ and @(|*)@ operators are identical, but with their argument flipped. Just remember that the \'@|@\' denotes the scalar part.
```
```
Data/Vector/Class.hs
``````  The @(*|)@ and @(|*)@ operators are identical, but with their argument flipped. Just remember that the \'@|@\' denotes the scalar part.
-}
(|*) :: Vector v => v -> Scalar -> v
v |* k = vmap (k*) v

{- |
Scale a vector (i.e., change its length but not its direction). This operator has the same precedence as the usual @(/)@ operator.

The @(/|)@ and @(|/)@ operators are identical, but with their argument flipped. Just remember that the \'@|@\' denotes the scalar part.
```
```
Data/Vector/Transform/T1.hs
``````{- |
The type of 1D linear transformations. Essentially, this is applying a linear function to a number.

Note the @Monoid@ instance, which gives you access to the identity transform (@mempty@) and the ability to combine a series of transforms into a single transform (@mappend@).
-}
data Transform1 =
Transform1
{
t1_XX, t1_1X :: {-# UNPACK #-} !Scalar
```
```
Data/Vector/Transform/T1.hs
``````
instance Monoid Transform1 where
mempty = Transform1  1 0
mappend a b =
Transform1
{
t1_XX = t1_XX a * t1_XX b,
t1_1X = t1_1X a * t1_XX b  +  t1_1X b
}
```
```
Data/Vector/Transform/T2.hs
``````{- |
The type of 2D linear transformations.

Note the @Monoid@ instance, which gives you access to the identity transform (@mempty@) and the ability to combine a series of transforms into a single transform (@mappend@).
-}
data Transform2 =
Transform2
{
t2_XX, t2_YX, t2_1X,
```
```
Data/Vector/Transform/T2.hs
``````
instance Monoid Transform2 where
mempty = Transform2  1 0 0  0 1 0
mappend a b =
Transform2
{
t2_XX = t2_XX a * t2_XX b  +  t2_XY a * t2_YX b,
t2_YX = t2_YX a * t2_XX b  +  t2_YY a * t2_YX b,
t2_1X = t2_1X a * t2_XX b  +  t2_1Y a * t2_YX b  +  t2_1X b,
```
```
Data/Vector/Transform/T3.hs
``````{- |
The type of 3D linear transformations.

Note the @Monoid@ instance, which gives you access to the identity transform (@mempty@) and the ability to combine a series of transforms into a single transform (@mappend@).
-}
data Transform3 =
Transform3
{
t3_XX, t3_YX, t3_ZX, t3_1X,
```
```
Data/Vector/Transform/T3.hs
``````
instance Monoid Transform3 where
mempty = Transform3  1 0 0 0  0 1 0 0  0 0 1 0
mappend a b =
Transform3
{
t3_XX = t3_XX a * t3_XX b  +  t3_XY a * t3_YX b  +  t3_XZ a * t3_ZX b,
t3_YX = t3_YX a * t3_XX b  +  t3_YY a * t3_YX b  +  t3_YZ a * t3_ZX b,
t3_ZX = t3_ZX a * t3_XX b  +  t3_ZY a * t3_YX b  +  t3_ZZ a * t3_ZX b,
```
```
Data/Vector/Transform/T4.hs
``````{- |
The type of 4D linear transformations.

Note the @Monoid@ instance, which gives you access to the identity transform (@mempty@) and the ability to combine a series of transforms into a single transform (@mappend@).
-}
data Transform4 =
Transform4
{
t4_XX, t4_YX, t4_ZX, t4_WX, t4_1X,
```
```
Data/Vector/Transform/T4.hs
``````
instance Monoid Transform4 where
mempty = Transform4  1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 1 0
mappend a b =
Transform4
{
t4_XX = t4_XX a * t4_XX b  +  t4_XY a * t4_YX b  +  t4_XZ a * t4_ZX b  +  t4_XW a * t4_WX b,
t4_YX = t4_YX a * t4_XX b  +  t4_YY a * t4_YX b  +  t4_YZ a * t4_ZX b  +  t4_YW a * t4_WX b,
t4_ZX = t4_ZX a * t4_XX b  +  t4_ZY a * t4_YX b  +  t4_ZZ a * t4_ZX b  +  t4_ZW a * t4_WX b,
```
```
Data/Vector/V1.hs
``````newtype Vector1 = Vector1 {v1x :: Scalar} deriving (Eq, Ord, Enum, Show, Num, Fractional)

instance BasicVector Vector1 where
vmap  f (Vector1 x )              = Vector1 (f x)
vzip  f (Vector1 x1) (Vector1 x2) = Vector1 (f x1 x2)
vfold _ (Vector1 x )              = x

vpack (x:_) = Just \$ Vector1 x
vpack _     = Nothing
```
```
Data/Vector/V2.hs
``````data Vector2 = Vector2 {v2x, v2y :: {-# UNPACK #-} !Scalar} deriving (Eq, Show)

instance BasicVector Vector2 where
vmap  f (Vector2 x  y )                 = Vector2 (f x)     (f y)
vzip  f (Vector2 x1 y1) (Vector2 x2 y2) = Vector2 (f x1 x2) (f y1 y2)
vfold f (Vector2 x  y )                 = f x y

vpack (x:y:_) = Just \$ Vector2 x y
vpack _       = Nothing
```
```
Data/Vector/V2.hs
``````  (+) = vzip (+)
(-) = vzip (-)
(*) = vzip (*)
abs = vmap abs
signum = vmap signum
fromInteger = vpromote . fromInteger

instance Fractional Vector2 where
(/) = vzip (/)
recip = vmap recip
```
```
Data/Vector/V2.hs
``````
instance Fractional Vector2 where
(/) = vzip (/)
recip = vmap recip
fromRational = vpromote . fromRational

instance Vector Vector2 where
```
```
Data/Vector/V3.hs
``````data Vector3 = Vector3 {v3x, v3y, v3z :: {-# UNPACK #-} !Scalar} deriving (Eq, Show)

instance BasicVector Vector3 where
vmap  f (Vector3 x  y  z )                    = Vector3 (f x)     (f y)     (f z)
vzip  f (Vector3 x1 y1 z1) (Vector3 x2 y2 z2) = Vector3 (f x1 x2) (f y1 y2) (f z1 z2)
vfold f (Vector3 x  y  z )                    = f x (f y z)

vpack (x:y:z:_) = Just \$ Vector3 x y z
vpack _         = Nothing
```
```
Data/Vector/V3.hs
``````  (+) = vzip (+)
(-) = vzip (-)
(*) = vzip (*)
abs = vmap abs
signum = vmap signum
fromInteger = vpromote . fromInteger

instance Fractional Vector3 where
(/) = vzip (/)
recip = vmap recip
```
```
Data/Vector/V3.hs
``````
instance Fractional Vector3 where
(/) = vzip (/)
recip = vmap recip
fromRational = vpromote . fromRational

instance Vector Vector3 where

{- |
```
```
Data/Vector/V4.hs
``````data Vector4 = Vector4 {v4x, v4y, v4z, v4w :: {-# UNPACK #-} !Scalar} deriving (Eq, Show)

instance BasicVector Vector4 where
vmap  f (Vector4 x  y  z  w )                       = Vector4 (f x)     (f y)     (f z)     (f w)
vzip  f (Vector4 x1 y1 z1 w1) (Vector4 x2 y2 z2 w2) = Vector4 (f x1 x2) (f y1 y2) (f z1 z2) (f w1 w2)
vfold f (Vector4 x  y  z  w )                       = f (f x y) (f z w)

vpack (x:y:z:w:_) = Just \$ Vector4 x y z w
vpack _           = Nothing
```
```
Data/Vector/V4.hs
``````  (+) = vzip (+)
(-) = vzip (-)
(*) = vzip (*)
abs = vmap abs
signum = vmap signum
fromInteger = vpromote . fromInteger

instance Fractional Vector4 where
(/) = vzip (/)
recip = vmap recip
```
```
Data/Vector/V4.hs
``````
instance Fractional Vector4 where
(/) = vzip (/)
recip = vmap recip
fromRational = vpromote . fromRational

instance Vector Vector4 where
```
```