Module
Linear.Affine
- Package
- purescript-linear
- Repository
- afcondon/purescript-linear
Affine spaces and points.
This module provides the Affine typeclass for affine spaces,
where points and vectors are distinguished at the type level.
Points can be subtracted to yield vectors, and vectors can be
added to points, but points cannot be added to each other.
#Point Source
newtype Point :: forall k. (k -> Type) -> k -> Typenewtype Point f a
A point in an affine space.
The Point newtype distinguishes points from vectors at the type level.
This prevents nonsensical operations like adding two points together.
origin = P (V2 0.0 0.0)
position = P (V2 3.0 4.0)
Constructors
P (f a)
Instances
Newtype (Point f a) _(Eq (f a)) => Eq (Point f a)(Ord (f a)) => Ord (Point f a)(Show (f a)) => Show (Point f a)(Functor f) => Functor (Point f)(Apply f) => Apply (Point f)(Applicative f) => Applicative (Point f)(Foldable f) => Foldable (Point f)(Traversable f) => Traversable (Point f)(Additive f, Epsilon (f a)) => Epsilon (Point f a)(Additive f) => Affine (Point f) f
#Affine Source
class Affine :: (Type -> Type) -> (Type -> Type) -> Constraintclass (Additive d) <= Affine p d | p -> d where
An affine space is a set of points with associated difference vectors.
Laws:
p .+^ (q .-. p) = q(p .+^ u) .+^ v = p .+^ (u ^+^ v)p .-. p = zero
Members
diff :: forall a. Ring a => p a -> p a -> d aThe vector from the first point to the second.
moveBy :: forall a. Semiring a => p a -> d a -> p aAdd a vector to a point.
moveByNeg :: forall a. Ring a => p a -> d a -> p aSubtract a vector from a point.
Instances
#origin Source
origin :: forall f a. Applicative f => Semiring a => Point f aThe origin point (all coordinates zero).
origin :: Point V3 Number
origin = P (V3 0.0 0.0 0.0)
Points form an affine space over their underlying vectors.