numhask-space
Safe HaskellNone
LanguageGHC2024

NumHask.Space

Description

Mathematics does not rigorously define a space, leaving library devs free to explore.

“But who can quantify the algebra of space, or weigh those worlds that swim each in its place? Who can outdo the dark? And what computer knows how beauty comes to birth - shell star and rose?

~ Technicians by Jean Kenward” ~ John Foster

Synopsis

Usage

>>> :m -Prelude
>>> :set -XRebindableSyntax
>>> import NumHask.Prelude
>>> import NumHask.Space
>>> Point 1 1
Point 1 1
>>> one :: Range Double
Range -0.5 0.5
>>> grid OuterPos (Range 0 50 :: Range Double) 5
[0.0,10.0,20.0,30.0,40.0,50.0]

Space

Space is an interesting cross-section of many programming domains.

(+/-) :: (Space s, Subtractive (Element s)) => Element s -> Element s -> s infixl 6 Source #

create a space centered on a plus or minus b

contains :: Space s => s -> s -> Bool Source #

is a space contained within another?

(a `union` b) `contains` a
(a `union` b) `contains` b

disjoint :: Space s => s -> s -> Bool Source #

are two spaces disjoint?

eps :: (Space s, FromRational (Element s), Field (Element s)) => Element s -> Element s -> s Source #

a small space

interpolate :: (Space s, Ring (Element s)) => s -> Element s -> Element s Source #

interpolate a space

interpolate s x == project s (zero ... one) x

inverseTransform :: (Eq a, Field a) => Transform a -> Maybe (Transform a) Source #

Calculate the inverse of a transformation.

memberOf :: Space s => Element s -> s -> Bool Source #

is an element contained within a space

mid :: (Space s, Field (Element s)) => s -> Element s Source #

middle element of the space

monotone :: (Space a, Space b) => (Element a -> Element b) -> a -> b Source #

lift a monotone function (increasing or decreasing) over a given space

move :: (Additive (Element s), Space s) => Element s -> s -> s Source #

Move a Space. (scalar addition)

project :: (Space s, Field (Element s)) => s -> s -> Element s -> Element s Source #

project an element from one space to another, preserving relative position.

project o n (lower o) = lower n
project o n (upper o) = upper n
project o n (mid o) = mid n
project a a x = x

rotate :: TrigField a => a -> Transform a Source #

Rotate an Affinity (counter-clockwise)

scale :: (Multiplicative (Element s), Space s) => Element s -> s -> s Source #

Scale a Space. (scalar multiplication)

space1 :: (Space s, Traversable f) => f (Element s) -> Maybe s Source #

Maybe containing space of a traversable.

unsafeSpace1 :: (Space s, Traversable f) => f (Element s) -> s Source #

the containing space of a non-empty Traversable.

partial function.

all $ unsafeSpace1 a `contains` <$> a

widen :: (Space s, Ring (Element s)) => Element s -> s -> s Source #

widen a space

widenEps :: (Space s, FromRational (Element s), Ring (Element s)) => Element s -> s -> s Source #

widen by a small amount

width :: (Space s, Subtractive (Element s)) => s -> Element s Source #

distance between boundaries

(|.) :: Affinity a b => Transform b -> a -> a infix 3 Source #

Apply a Transform to an Affinity

class Affinity a b | a -> b where Source #

An Affinity is something that can be subjected to an affine transformation in 2-dimensional space, where affine means a linear matrix operation or a translation (+).

https://en.wikipedia.org/wiki/Affine_transformation

Methods

transform :: Transform b -> a -> a Source #

Instances

Instances details
(Multiplicative a, Additive a) => Affinity (Line a) a Source # 
Instance details

Defined in NumHask.Space.Point

Methods

transform :: Transform a -> Line a -> Line a Source #

(Multiplicative a, Additive a) => Affinity (Point a) a Source # 
Instance details

Defined in NumHask.Space.Point

Methods

transform :: Transform a -> Point a -> Point a Source #

(Multiplicative a, Additive a) => Affinity (Transform a) a Source # 
Instance details

Defined in NumHask.Space.Types

type family Element s Source #

the underlying element in the space

Instances

Instances details
type Element (Range a) Source # 
Instance details

Defined in NumHask.Space.Range

type Element (Range a) = a
type Element (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

type Element (Rect a) = Point a

class (Space s, Field (Element s)) => FieldSpace s where Source #

a space that can be divided neatly

unsafeSpace1 (grid OuterPos s g) == s
getUnion (sconcat (Union <$> (gridSpace s g))) == s

Associated Types

type Grid s Source #

the type that divides or quotients the space

Methods

grid :: Pos -> s -> Grid s -> [Element s] Source #

create equally-spaced elements across a space

gridSpace :: s -> Grid s -> [s] Source #

create equally-spaced spaces from a space

Instances

Instances details
(Field a, Ord a, FromIntegral a Int) => FieldSpace (Range a) Source # 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Grid (Range a) 
Instance details

Defined in NumHask.Space.Range

type Grid (Range a) = Int

Methods

grid :: Pos -> Range a -> Grid (Range a) -> [Element (Range a)] Source #

gridSpace :: Range a -> Grid (Range a) -> [Range a] Source #

(FromIntegral a Int, Field a, Ord a) => FieldSpace (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Grid (Rect a) 
Instance details

Defined in NumHask.Space.Rect

type Grid (Rect a) = Point Int

Methods

grid :: Pos -> Rect a -> Grid (Rect a) -> [Element (Rect a)] Source #

gridSpace :: Rect a -> Grid (Rect a) -> [Rect a] Source #

type family Grid s Source #

the type that divides or quotients the space

Instances

Instances details
type Grid (Range a) Source # 
Instance details

Defined in NumHask.Space.Range

type Grid (Range a) = Int
type Grid (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

type Grid (Rect a) = Point Int

data Pos Source #

Pos suggests where points should be placed in forming a grid across a field space.

Constructors

OuterPos

include boundaries

InnerPos

don't include boundaries

LowerPos

include the lower boundary

UpperPos

include the upper boundary

MidPos

use the mid-point of the space

Instances

Instances details
Eq Pos Source # 
Instance details

Defined in NumHask.Space.Types

Methods

(==) :: Pos -> Pos -> Bool #

(/=) :: Pos -> Pos -> Bool #

Show Pos Source # 
Instance details

Defined in NumHask.Space.Types

Methods

showsPrec :: Int -> Pos -> ShowS #

show :: Pos -> String #

showList :: [Pos] -> ShowS #

class Space s where Source #

A Space is a continuous set of numbers. Continuous here means that the set has an upper and lower bound, and an element that is between these two bounds is a member of the Space.

a `union` b == b `union` a
a `intersection` b == b `intersection` a
(a `union` b) `intersection` c == (a `intersection` b) `union` (a `intersection` c)
(a `intersection` b) `union` c == (a `union` b) `intersection` (a `union` c)
norm (norm a) = norm a
a |>| b == b |<| a
a |.| singleton a

Minimal complete definition

lower, upper, (>.<)

Associated Types

type Element s Source #

the underlying element in the space

Methods

lower :: s -> Element s Source #

lower boundary

upper :: s -> Element s Source #

upper boundary

singleton :: Element s -> s Source #

space containing a single element

intersection :: s -> s -> s Source #

the intersection of two spaces

default intersection :: Ord (Element s) => s -> s -> s Source #

union :: s -> s -> s Source #

the union of two spaces

default union :: Ord (Element s) => s -> s -> s Source #

normalise :: s -> s Source #

Normalise a space so that

lower a \/ upper a == lower a
lower a /\ upper a == upper a

(...) :: Element s -> Element s -> s infix 3 Source #

create a normalised space from two elements

default (...) :: Ord (Element s) => Element s -> Element s -> s Source #

(>.<) :: Element s -> Element s -> s infix 3 Source #

create a space from two elements without normalising

(|.|) :: Element s -> s -> Bool infixl 7 Source #

is an element in the space

default (|.|) :: Ord (Element s) => Element s -> s -> Bool Source #

(|>|) :: s -> s -> Bool infixl 7 Source #

is one space completely above the other

default (|>|) :: Ord (Element s) => s -> s -> Bool Source #

(|<|) :: s -> s -> Bool infixl 7 Source #

is one space completely below the other

default (|<|) :: Ord (Element s) => s -> s -> Bool Source #

Instances

Instances details
Ord a => Space (Range a) Source # 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Element (Range a) 
Instance details

Defined in NumHask.Space.Range

type Element (Range a) = a
Ord a => Space (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Element (Rect a) 
Instance details

Defined in NumHask.Space.Rect

type Element (Rect a) = Point a

Methods

lower :: Rect a -> Element (Rect a) Source #

upper :: Rect a -> Element (Rect a) Source #

singleton :: Element (Rect a) -> Rect a Source #

intersection :: Rect a -> Rect a -> Rect a Source #

union :: Rect a -> Rect a -> Rect a Source #

normalise :: Rect a -> Rect a Source #

(...) :: Element (Rect a) -> Element (Rect a) -> Rect a Source #

(>.<) :: Element (Rect a) -> Element (Rect a) -> Rect a Source #

(|.|) :: Element (Rect a) -> Rect a -> Bool Source #

(|>|) :: Rect a -> Rect a -> Bool Source #

(|<|) :: Rect a -> Rect a -> Bool Source #

data Transform a Source #

linear transform + translate of a point-like number

(x, y) -> (ax + by + c, dx + ey + d)

or

\[ \begin{pmatrix} a & b & c\\ d & e & f\\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x\\ y\\ 1 \end{pmatrix} \]

Constructors

Transform 

Fields

  • ta :: !a
     
  • tb :: !a
     
  • tc :: !a
     
  • td :: !a
     
  • te :: !a
     
  • tf :: !a
     

Instances

Instances details
Functor Transform Source # 
Instance details

Defined in NumHask.Space.Types

Methods

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

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

Foldable Transform Source # 
Instance details

Defined in NumHask.Space.Types

Methods

fold :: Monoid m => Transform m -> m #

foldMap :: Monoid m => (a -> m) -> Transform a -> m #

foldMap' :: Monoid m => (a -> m) -> Transform a -> m #

foldr :: (a -> b -> b) -> b -> Transform a -> b #

foldr' :: (a -> b -> b) -> b -> Transform a -> b #

foldl :: (b -> a -> b) -> b -> Transform a -> b #

foldl' :: (b -> a -> b) -> b -> Transform a -> b #

foldr1 :: (a -> a -> a) -> Transform a -> a #

foldl1 :: (a -> a -> a) -> Transform a -> a #

toList :: Transform a -> [a] #

null :: Transform a -> Bool #

length :: Transform a -> Int #

elem :: Eq a => a -> Transform a -> Bool #

maximum :: Ord a => Transform a -> a #

minimum :: Ord a => Transform a -> a #

sum :: Num a => Transform a -> a #

product :: Num a => Transform a -> a #

Traversable Transform Source # 
Instance details

Defined in NumHask.Space.Types

Methods

traverse :: Applicative f => (a -> f b) -> Transform a -> f (Transform b) #

sequenceA :: Applicative f => Transform (f a) -> f (Transform a) #

mapM :: Monad m => (a -> m b) -> Transform a -> m (Transform b) #

sequence :: Monad m => Transform (m a) -> m (Transform a) #

Eq a => Eq (Transform a) Source # 
Instance details

Defined in NumHask.Space.Types

Methods

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

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

Show a => Show (Transform a) Source # 
Instance details

Defined in NumHask.Space.Types

(Multiplicative a, Additive a) => Affinity (Transform a) a Source # 
Instance details

Defined in NumHask.Space.Types

newtype Union a Source #

a convex hull

Constructors

Union 

Fields

Instances

Instances details
Space a => Semigroup (Union a) Source # 
Instance details

Defined in NumHask.Space.Types

Methods

(<>) :: Union a -> Union a -> Union a #

sconcat :: NonEmpty (Union a) -> Union a #

stimes :: Integral b => b -> Union a -> Union a #

Charts

Instances