hgeometry-point
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageGHC2024

HGeometry.Point.Class

Description

A class of types that can act as \(d\)-dimensional points.

Synopsis

Documentation

class HasVector point point' where Source #

Type class for types, usually points, that have a Lens to interpret the point as a vector.

Methods

vector :: forall (d :: Nat) r s. (Dimension point ~ d, NumType point ~ r, Dimension point' ~ d, NumType point' ~ s) => Lens point point' (Vector d r) (Vector d s) Source #

Lens to access the vector corresponding to this point.

>>> myPoint ^. vector
Vector3 1 2 3
>>> ( myPoint & vector .~ Vector3 3 2 1  ) :: Point 3 Int
Point3 3 2 1
>>> (myPoint & coordinates %~ show ) :: Point 3 String
Point3 "1" "2" "3"

Instances

Instances details
(Vector_ vector d r, Vector_ vector' d s, Has_ Vector_ d r, Has_ Vector_ d s, AsVector_ vector vector' d r s, HasComponents vector vector') => HasVector (PointF vector) (PointF vector') Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

vector :: forall (d0 :: Nat) r0 s0. (Dimension (PointF vector) ~ d0, NumType (PointF vector) ~ r0, Dimension (PointF vector') ~ d0, NumType (PointF vector') ~ s0) => Lens (PointF vector) (PointF vector') (Vector d0 r0) (Vector d0 s0) Source #

HasVector point point' => HasVector (point :+ extra) (point' :+ extra) Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

vector :: forall (d :: Nat) r s. (Dimension (point :+ extra) ~ d, NumType (point :+ extra) ~ r, Dimension (point' :+ extra) ~ d, NumType (point' :+ extra) ~ s) => Lens (point :+ extra) (point' :+ extra) (Vector d r) (Vector d s) Source #

(HasVector orig orig, HasVector extra extra, HasVector orig orig', HasVector extra extra', Dimension extra ~ Dimension orig, NumType extra ~ NumType orig, Dimension extra' ~ Dimension orig', NumType extra' ~ NumType orig') => HasVector (OriginalOrExtra orig extra) (OriginalOrExtra orig' extra') Source # 
Instance details

Defined in HGeometry.Point.Either

Methods

vector :: forall (d :: Nat) r s. (Dimension (OriginalOrExtra orig extra) ~ d, NumType (OriginalOrExtra orig extra) ~ r, Dimension (OriginalOrExtra orig' extra') ~ d, NumType (OriginalOrExtra orig' extra') ~ s) => Lens (OriginalOrExtra orig extra) (OriginalOrExtra orig' extra') (Vector d r) (Vector d s) Source #

(Vector_ (v r) d r, Vector_ (v s) d s) => HasVector (Point v r) (Point v s) Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

vector :: forall (d0 :: Nat) r0 s0. (Dimension (Point v r) ~ d0, NumType (Point v r) ~ r0, Dimension (Point v s) ~ d0, NumType (Point v s) ~ s0) => Lens (Point v r) (Point v s) (Vector d0 r0) (Vector d0 s0) Source #

class (Has_ Vector_ (Dimension point) (NumType point), Has_ Vector_ (Dimension point') (NumType point'), HasComponents (Vector (Dimension point') (NumType point)) (Vector (Dimension point') (NumType point')), Dimension point ~ Dimension point', HasVector point point') => HasCoordinates point point' where Source #

Class for point types that have a type changing traversal over all coordinates.

Minimal complete definition

Nothing

Methods

coordinates :: IndexedTraversal1 Int point point' (NumType point) (NumType point') Source #

Traversal over *all* coordinates of the points. Coordinates are 1-indexed.

>>> imapMOf_ coordinates (\i x -> print (i,x)) (Point2 10 20 :: Point 2 Int)
(1,10)
(2,20)
>>> itraverseOf coordinates (\i x -> print (i,x)) (Point2 10 20) :: IO (Point 2 ())
(1,10)
(2,20)
Point2 () ()
>>> over coordinates (+1) $ Point2 10 20 :: Point 2 Int
Point2 11 21

Instances

Instances details
(Has_ Vector_ d r, Has_ Vector_ d s, Vector_ vector d r, Vector_ vector' d s, AsVector_ vector vector' d r s, HasComponents (Vector d r) (Vector d s), HasComponents vector vector') => HasCoordinates (PointF vector) (PointF vector') Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

coordinates :: IndexedTraversal1 Int (PointF vector) (PointF vector') (NumType (PointF vector)) (NumType (PointF vector')) Source #

HasCoordinates point point' => HasCoordinates (point :+ extra) (point' :+ extra) Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

coordinates :: IndexedTraversal1 Int (point :+ extra) (point' :+ extra) (NumType (point :+ extra)) (NumType (point' :+ extra)) Source #

(HasCoordinates orig orig', HasCoordinates extra extra', HasVector orig orig, HasVector extra extra, Dimension extra ~ Dimension orig, NumType extra ~ NumType orig, Dimension extra' ~ Dimension orig', NumType extra' ~ NumType orig') => HasCoordinates (OriginalOrExtra orig extra) (OriginalOrExtra orig' extra') Source # 
Instance details

Defined in HGeometry.Point.Either

Methods

coordinates :: IndexedTraversal1 Int (OriginalOrExtra orig extra) (OriginalOrExtra orig' extra') (NumType (OriginalOrExtra orig extra)) (NumType (OriginalOrExtra orig' extra')) Source #

(d ~ Dimension (v r), r ~ IxValue (v r), s ~ IxValue (v s), d ~ Dimension (v s), Vector_ (v r) d r, Vector_ (v s) d s, Has_ Vector_ d r, Has_ Vector_ d s, HasComponents (Vector d r) (Vector d s)) => HasCoordinates (Point v r) (Point v s) Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

coordinates :: IndexedTraversal1 Int (Point v r) (Point v s) (NumType (Point v r)) (NumType (Point v s)) Source #

class (Additive_ (Vector d r) d r, HasCoordinates point point, d ~ Dimension point, r ~ NumType point) => Affine_ point (d :: Nat) r | point -> d, point -> r where Source #

Affine space; essentially the same as Linear.Affine, but for points of kind Type rather than (Type -> Type).

Minimal complete definition

Nothing

Methods

(.-.) :: point -> point -> Vector d r Source #

p .-. q represents the vector from q to p

default (.-.) :: (HasVector point point, Num r) => point -> point -> Vector d r Source #

(.+^) :: point -> Vector d r -> point Source #

add a vector to a point

>>> myPoint .+^ Vector3 100 200 300
Point3 101 202 303

default (.+^) :: (HasVector point point, Num r) => point -> Vector d r -> point Source #

(.-^) :: point -> Vector d r -> point Source #

subtract a vector from a point

>>> myPoint .-^ Vector3 100 200 300
Point3 (-99) (-198) (-297)

Instances

Instances details
(Additive_ vector d r, Additive_ (Vector d r) d r) => Affine_ (PointF vector) d r Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

(.-.) :: PointF vector -> PointF vector -> Vector d r Source #

(.+^) :: PointF vector -> Vector d r -> PointF vector Source #

(.-^) :: PointF vector -> Vector d r -> PointF vector Source #

Affine_ point d r => Affine_ (point :+ extra) d r Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

(.-.) :: (point :+ extra) -> (point :+ extra) -> Vector d r Source #

(.+^) :: (point :+ extra) -> Vector d r -> point :+ extra Source #

(.-^) :: (point :+ extra) -> Vector d r -> point :+ extra Source #

(Affine_ orig d r, Affine_ extra d r) => Affine_ (OriginalOrExtra orig extra) d r Source # 
Instance details

Defined in HGeometry.Point.Either

Methods

(.-.) :: OriginalOrExtra orig extra -> OriginalOrExtra orig extra -> Vector d r Source #

(.+^) :: OriginalOrExtra orig extra -> Vector d r -> OriginalOrExtra orig extra Source #

(.-^) :: OriginalOrExtra orig extra -> Vector d r -> OriginalOrExtra orig extra Source #

(d ~ Dimension (v r), r ~ IxValue (v r), Vector_ (v r) d r, Additive_ (Vector d r) d r) => Affine_ (Point v r) d r Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

(.-.) :: Point v r -> Point v r -> Vector d r Source #

(.+^) :: Point v r -> Vector d r -> Point v r Source #

(.-^) :: Point v r -> Vector d r -> Point v r Source #

class (Affine_ point d r, HasVector point point) => Point_ point (d :: Nat) r where Source #

A class representing points in d-dimensional space.

Minimal complete definition

Nothing

Methods

coord' :: Int -> IndexedTraversal' Int point r Source #

Get the coordinate in a given dimension. This operation is unsafe in the sense that no bounds are checked. Consider using coord instead.

>>> myPoint ^.. coord' 2
[2]

Instances

Instances details
(Additive_ vector d r, Additive_ (Vector d r) d r) => Point_ (PointF vector) d r Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

coord' :: Int -> IndexedTraversal' Int (PointF vector) r Source #

Point_ point d r => Point_ (point :+ extra) d r Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

coord' :: Int -> IndexedTraversal' Int (point :+ extra) r Source #

(Point_ orig d r, Point_ extra d r) => Point_ (OriginalOrExtra orig extra) d r Source # 
Instance details

Defined in HGeometry.Point.Either

Methods

coord' :: Int -> IndexedTraversal' Int (OriginalOrExtra orig extra) r Source #

(d ~ Dimension (v r), r ~ IxValue (v r), Vector_ (v r) d r, Additive_ (Vector d r) d r) => Point_ (Point v r) d r Source # 
Instance details

Defined in HGeometry.Point.Class

pattern Point1_ :: Point_ point 1 r => r -> point Source #

A pattern synonym for 1 dimensional points.

pattern Point2_ :: Point_ point 2 r => r -> r -> point Source #

A pattern synonym for 2 dimensional points.

pattern Point3_ :: Point_ point 3 r => r -> r -> r -> point Source #

A pattern synonym for 3 dimensional points.

pattern Point4_ :: Point_ point 4 r => r -> r -> r -> r -> point Source #

A bidirectional pattern synonym for 4 dimensional points.

class Point_ point d r => ConstructablePoint_ point (d :: Nat) r where Source #

Type class for constructable points

Methods

fromVector :: Vector d r -> point Source #

Construct a point from a vector

>>> fromVector (Vector4 1 2 3 4) :: Point 4 Int
Point4 1 2 3 4

Instances

Instances details
(Additive_ vector d r, Additive_ (Vector d r) d r) => ConstructablePoint_ (PointF vector) d r Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

fromVector :: Vector d r -> PointF vector Source #

(ConstructablePoint_ point d r, Default extra) => ConstructablePoint_ (point :+ extra) d r Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

fromVector :: Vector d r -> point :+ extra Source #

(d ~ Dimension (v r), r ~ IxValue (v r), Vector_ (v r) d r, Additive_ (Vector d r) d r) => ConstructablePoint_ (Point v r) d r Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

fromVector :: Vector d r -> Point v r Source #

origin :: forall point (d :: Nat) r. (Num r, ConstructablePoint_ point d r) => point Source #

Point representing the origin in d dimensions

>>> origin :: Point 4 Int
Point4 0 0 0 0

pointFromList :: forall point (d :: Nat) r. (ConstructablePoint_ point d r, Vector_ (Vector d r) d r) => [r] -> Maybe point Source #

Constructs a point from a list of coordinates. The length of the list has to match the dimension exactly.

>>> pointFromList [1,2,3] :: Maybe (Point 3 Int)
Just (Point3 1 2 3)
>>> pointFromList [1] :: Maybe (Point 3 Int)
Nothing
>>> pointFromList [1,2,3,4] :: Maybe (Point 3 Int)
Nothing

coord :: forall (i :: Natural) point (d :: Natural) r. (1 <= i, i <= d, KnownNat i, Point_ point d r) => IndexedLens' Int point r Source #

Get the coordinate in a given dimension

>>> myPoint ^. coord @2
2
>>> myPoint & coord @1 .~ 10
Point3 10 2 3
>>> myPoint & coord @3 %~ (+1)
Point3 1 2 4

xCoord :: forall (d :: Natural) point r. (1 <= d, Point_ point d r) => IndexedLens' Int point r Source #

Shorthand to access the first coordinate

>>> myPoint ^. xCoord
1
>>> Point2 1 (2 :: Int) & xCoord .~ 10
Point2 10 2

yCoord :: forall (d :: Natural) point r. (2 <= d, Point_ point d r) => IndexedLens' Int point r Source #

Shorthand to access the second coordinate

>>> Point2 1 (2 :: Int) ^. yCoord
2
>>> myPoint & yCoord %~ (+1)
Point3 1 3 3

zCoord :: forall (d :: Natural) point r. (3 <= d, Point_ point d r) => IndexedLens' Int point r Source #

Shorthand to access the third coordinate

>>> myPoint ^. zCoord
3
>>> myPoint & zCoord %~ (+1)
Point3 1 2 4

wCoord :: forall (d :: Natural) point r. (4 <= d, Point_ point d r) => IndexedLens' Int point r Source #

Shorthand to access the fourth coordinate

>>> (Point4 1 2 3 4 :: Point 4 Int) ^. wCoord
4
>>> (Point4 1 2 3 4 :: Point 4 Int) & wCoord %~ (+1)
Point4 1 2 3 5

dCoord :: forall point (d :: Natural) r. (1 <= d, Point_ point d r) => IndexedLens' Int point r Source #

Shorthand to access the last coordinate

>>> (Point2 1 2 :: Point 2 Int) ^. dCoord
2
>>> (Point4 1 2 3 4 :: Point 4 Int) ^. dCoord
4
>>> (Point4 1 2 3 4 :: Point 4 Int) & dCoord %~ (+1)
Point4 1 2 3 5

class HasPoints s t point point' | s -> point, t -> point' where Source #

Data types that store points

Methods

allPoints :: forall (d :: Nat) r r'. (Point_ point d r, Point_ point' d r', NumType s ~ r, NumType t ~ r', Dimension s ~ d, Dimension t ~ d) => Traversal1 s t point point' Source #

Traversal over all points in the structure

>>> let xs = NonEmpty.fromList [Point2 10 10, Point2 20 (30 :: Int)]
>>> xs^..allPoints
[Point2 10 10,Point2 20 30]
>>> over allPoints (.+^ Vector2 10 10) xs :: NonEmpty.NonEmpty (Point 2 Int)
Point2 20 20 :| [Point2 30 40]

Instances

Instances details
HasPoints (NonEmpty point) (NonEmpty point') point point' Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

allPoints :: forall (d :: Nat) r r'. (Point_ point d r, Point_ point' d r', NumType (NonEmpty point) ~ r, NumType (NonEmpty point') ~ r', Dimension (NonEmpty point) ~ d, Dimension (NonEmpty point') ~ d) => Traversal1 (NonEmpty point) (NonEmpty point') point point' Source #

HasPoints (PointF v) (PointF v') (PointF v) (PointF v') Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

allPoints :: forall (d :: Nat) r r'. (Point_ (PointF v) d r, Point_ (PointF v') d r', NumType (PointF v) ~ r, NumType (PointF v') ~ r', Dimension (PointF v) ~ d, Dimension (PointF v') ~ d) => Traversal1 (PointF v) (PointF v') (PointF v) (PointF v') Source #

HasPoints (Point v r) (Point v' r') (Point v r) (Point v' r') Source # 
Instance details

Defined in HGeometry.Point.Class

Methods

allPoints :: forall (d :: Nat) r0 r'0. (Point_ (Point v r) d r0, Point_ (Point v' r') d r'0, NumType (Point v r) ~ r0, NumType (Point v' r') ~ r'0, Dimension (Point v r) ~ d, Dimension (Point v' r') ~ d) => Traversal1 (Point v r) (Point v' r') (Point v r) (Point v' r') Source #

type HasPoints' s point = HasPoints s s point point Source #

Shorthand for 'HasPoints s s point point'