| Copyright | (C) Frank Staals |
|---|---|
| License | see the LICENSE file |
| Maintainer | Frank Staals |
| Safe Haskell | None |
| Language | GHC2024 |
HGeometry.Point.Class
Description
A class of types that can act as \(d\)-dimensional points.
Synopsis
- class HasVector point point' where
- 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
- coordinates :: IndexedTraversal1 Int point point' (NumType point) (NumType point')
- 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
- class (Affine_ point d r, HasVector point point) => Point_ point (d :: Nat) r where
- coord' :: Int -> IndexedTraversal' Int point r
- pattern Point1_ :: Point_ point 1 r => r -> point
- pattern Point2_ :: Point_ point 2 r => r -> r -> point
- pattern Point3_ :: Point_ point 3 r => r -> r -> r -> point
- pattern Point4_ :: Point_ point 4 r => r -> r -> r -> r -> point
- class Point_ point d r => ConstructablePoint_ point (d :: Nat) r where
- fromVector :: Vector d r -> point
- origin :: forall point (d :: Nat) r. (Num r, ConstructablePoint_ point d r) => point
- pointFromList :: forall point (d :: Nat) r. (ConstructablePoint_ point d r, Vector_ (Vector d r) d r) => [r] -> Maybe point
- coord :: forall (i :: Natural) point (d :: Natural) r. (1 <= i, i <= d, KnownNat i, Point_ point d r) => IndexedLens' Int point r
- xCoord :: forall (d :: Natural) point r. (1 <= d, Point_ point d r) => IndexedLens' Int point r
- yCoord :: forall (d :: Natural) point r. (2 <= d, Point_ point d r) => IndexedLens' Int point r
- zCoord :: forall (d :: Natural) point r. (3 <= d, Point_ point d r) => IndexedLens' Int point r
- wCoord :: forall (d :: Natural) point r. (4 <= d, Point_ point d r) => IndexedLens' Int point r
- dCoord :: forall point (d :: Natural) r. (1 <= d, Point_ point d r) => IndexedLens' Int point r
- class HasPoints s t point point' | s -> point, t -> point' where
- type HasPoints' s point = HasPoints s s point point
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 ^. vectorVector3 1 2 3>>>( myPoint & vector .~ Vector3 3 2 1 ) :: Point 3 IntPoint3 3 2 1>>>(myPoint & coordinates %~ show ) :: Point 3 StringPoint3 "1" "2" "3"
Instances
| (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 # | |
| HasVector point point' => HasVector (point :+ extra) (point' :+ extra) 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 # | |
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 # | |
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 IntPoint2 11 21
Instances
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
(.+^) :: point -> Vector d r -> point Source #
add a vector to a point
>>>myPoint .+^ Vector3 100 200 300Point3 101 202 303
(.-^) :: point -> Vector d r -> point Source #
subtract a vector from a point
>>>myPoint .-^ Vector3 100 200 300Point3 (-99) (-198) (-297)
Instances
| (Additive_ vector d r, Additive_ (Vector d r) d r) => Affine_ (PointF vector) d r Source # | |
| Affine_ point d r => Affine_ (point :+ extra) d r Source # | |
| (Affine_ orig d r, Affine_ extra d r) => Affine_ (OriginalOrExtra orig extra) d r Source # | |
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 # | |
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
| (Additive_ vector d r, Additive_ (Vector d r) d r) => Point_ (PointF vector) d r Source # | |
Defined in HGeometry.Point.PointF | |
| Point_ point d r => Point_ (point :+ extra) d r Source # | |
Defined in HGeometry.Point.Class | |
| (Point_ orig d r, Point_ extra d r) => Point_ (OriginalOrExtra orig extra) d r Source # | |
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 # | |
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 IntPoint4 1 2 3 4
Instances
| (Additive_ vector d r, Additive_ (Vector d r) d r) => ConstructablePoint_ (PointF vector) d r Source # | |
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 # | |
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 # | |
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 IntPoint4 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 @22>>>myPoint & coord @1 .~ 10Point3 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 ^. xCoord1>>>Point2 1 (2 :: Int) & xCoord .~ 10Point2 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) ^. yCoord2>>>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 ^. zCoord3>>>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) ^. wCoord4>>>(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) ^. dCoord2>>>(Point4 1 2 3 4 :: Point 4 Int) ^. dCoord4>>>(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]
type HasPoints' s point = HasPoints s s point point Source #
Shorthand for 'HasPoints s s point point'