Rasterific-0.6.1.1: A pure haskell drawing engine.

Safe HaskellSafe
LanguageHaskell2010

Graphics.Rasterific.Linear

Description

This module is a reduction of the Linear package from Edward Kmett to match just the need of Rasterific.

If the flag embed_linear is disabled, this module is just a reexport from the real linear package.

Synopsis

Documentation

data V2 a Source #

A 2-dimensional vector

>>> pure 1 :: V2 Int
V2 1 1
>>> V2 1 2 + V2 3 4
V2 4 6
>>> V2 1 2 * V2 3 4
V2 3 8
>>> sum (V2 1 2)
3

Constructors

V2 !a !a 

Instances

Functor V2 Source # 

Methods

fmap :: (a -> b) -> V2 a -> V2 b #

(<$) :: a -> V2 b -> V2 a #

Applicative V2 Source # 

Methods

pure :: a -> V2 a #

(<*>) :: V2 (a -> b) -> V2 a -> V2 b #

(*>) :: V2 a -> V2 b -> V2 b #

(<*) :: V2 a -> V2 b -> V2 a #

Metric V2 Source # 

Methods

dot :: Num a => V2 a -> V2 a -> a Source #

quadrance :: Num a => V2 a -> a Source #

qd :: Num a => V2 a -> V2 a -> a Source #

distance :: Floating a => V2 a -> V2 a -> a Source #

norm :: Floating a => V2 a -> a Source #

signorm :: Floating a => V2 a -> V2 a Source #

Additive V2 Source # 

Methods

zero :: Num a => V2 a Source #

(^+^) :: Num a => V2 a -> V2 a -> V2 a Source #

(^-^) :: Num a => V2 a -> V2 a -> V2 a Source #

lerp :: Num a => a -> V2 a -> V2 a -> V2 a Source #

PointFoldable Point Source #

Just apply the function

Methods

foldPoints :: (b -> Point -> b) -> b -> Point -> b Source #

Transformable Point Source #

Just apply the function

Methods

transform :: (Point -> Point) -> Point -> Point Source #

PlaneBoundable Point Source # 
Eq a => Eq (V2 a) Source # 

Methods

(==) :: V2 a -> V2 a -> Bool #

(/=) :: V2 a -> V2 a -> Bool #

Num a => Num (V2 a) Source # 

Methods

(+) :: V2 a -> V2 a -> V2 a #

(-) :: V2 a -> V2 a -> V2 a #

(*) :: V2 a -> V2 a -> V2 a #

negate :: V2 a -> V2 a #

abs :: V2 a -> V2 a #

signum :: V2 a -> V2 a #

fromInteger :: Integer -> V2 a #

Show a => Show (V2 a) Source # 

Methods

showsPrec :: Int -> V2 a -> ShowS #

show :: V2 a -> String #

showList :: [V2 a] -> ShowS #

Epsilon a => Epsilon (V2 a) Source # 

Methods

nearZero :: V2 a -> Bool Source #

newtype V1 a Source #

A 1-dimensional vector

Constructors

V1 a 

Instances

Functor V1 Source # 

Methods

fmap :: (a -> b) -> V1 a -> V1 b #

(<$) :: a -> V1 b -> V1 a #

Applicative V1 Source # 

Methods

pure :: a -> V1 a #

(<*>) :: V1 (a -> b) -> V1 a -> V1 b #

(*>) :: V1 a -> V1 b -> V1 b #

(<*) :: V1 a -> V1 b -> V1 a #

Additive V1 Source # 

Methods

zero :: Num a => V1 a Source #

(^+^) :: Num a => V1 a -> V1 a -> V1 a Source #

(^-^) :: Num a => V1 a -> V1 a -> V1 a Source #

lerp :: Num a => a -> V1 a -> V1 a -> V1 a Source #

Eq a => Eq (V1 a) Source # 

Methods

(==) :: V1 a -> V1 a -> Bool #

(/=) :: V1 a -> V1 a -> Bool #

Show a => Show (V1 a) Source # 

Methods

showsPrec :: Int -> V1 a -> ShowS #

show :: V1 a -> String #

showList :: [V1 a] -> ShowS #

class Functor f => Additive f where Source #

A vector is an additive group with additional structure.

Minimal complete definition

zero, (^+^), (^-^), lerp

Methods

zero :: Num a => f a Source #

The zero vector

(^+^) :: Num a => f a -> f a -> f a infixl 6 Source #

Compute the sum of two vectors

>>> V2 1 2 ^+^ V2 3 4
V2 4 6

(^-^) :: Num a => f a -> f a -> f a infixl 6 Source #

Compute the difference between two vectors

>>> V2 4 5 - V2 3 1
V2 1 4

lerp :: Num a => a -> f a -> f a -> f a Source #

Linearly interpolate between two vectors.

Instances

Additive V1 Source # 

Methods

zero :: Num a => V1 a Source #

(^+^) :: Num a => V1 a -> V1 a -> V1 a Source #

(^-^) :: Num a => V1 a -> V1 a -> V1 a Source #

lerp :: Num a => a -> V1 a -> V1 a -> V1 a Source #

Additive V2 Source # 

Methods

zero :: Num a => V2 a Source #

(^+^) :: Num a => V2 a -> V2 a -> V2 a Source #

(^-^) :: Num a => V2 a -> V2 a -> V2 a Source #

lerp :: Num a => a -> V2 a -> V2 a -> V2 a Source #

class Num a => Epsilon a where Source #

Provides a fairly subjective test to see if a quantity is near zero.

>>> nearZero (1e-11 :: Double)
False
>>> nearZero (1e-17 :: Double)
True
>>> nearZero (1e-5 :: Float)
False
>>> nearZero (1e-7 :: Float)
True

Minimal complete definition

nearZero

Methods

nearZero :: a -> Bool Source #

Determine if a quantity is near zero.

Instances

class Additive f => Metric f where Source #

Free and sparse inner product/metric spaces.

Minimal complete definition

dot

Methods

dot :: Num a => f a -> f a -> a Source #

Compute the inner product of two vectors or (equivalently) convert a vector f a into a covector f a -> a.

>>> V2 1 2 `dot` V2 3 4
11

quadrance :: Num a => f a -> a Source #

Compute the squared norm. The name quadrance arises from Norman J. Wildberger's rational trigonometry.

qd :: Num a => f a -> f a -> a Source #

Compute the quadrance of the difference

distance :: Floating a => f a -> f a -> a Source #

Compute the distance between two vectors in a metric space

norm :: Floating a => f a -> a Source #

Compute the norm of a vector in a metric space

signorm :: Floating a => f a -> f a Source #

Convert a non-zero vector to unit vector.

Instances

Metric V2 Source # 

Methods

dot :: Num a => V2 a -> V2 a -> a Source #

quadrance :: Num a => V2 a -> a Source #

qd :: Num a => V2 a -> V2 a -> a Source #

distance :: Floating a => V2 a -> V2 a -> a Source #

norm :: Floating a => V2 a -> a Source #

signorm :: Floating a => V2 a -> V2 a Source #

(^*) :: (Functor f, Num a) => f a -> a -> f a infixl 7 Source #

Compute the right scalar product

>>> V2 3 4 ^* 2
V2 6 8

(^/) :: (Functor f, Floating a) => f a -> a -> f a infixl 7 Source #

Compute division by a scalar on the right.

normalize :: (Floating a, Metric f, Epsilon a) => f a -> f a Source #

Normalize a Metric functor to have unit norm. This function does not change the functor if its norm is 0 or 1.