Copyright | (C) Frank Staals |
---|---|

License | see the LICENSE file |

Maintainer | Frank Staals |

Safe Haskell | None |

Language | Haskell2010 |

\(d\)-dimensional points.

## Synopsis

- newtype Point d r = Point {}
- readPt :: forall d r. (Arity d, Read r) => ReadP (Point d r)
- origin :: (Arity d, Num r) => Point d r
- vector :: Lens' (Point d r) (Vector d r)
- unsafeCoord :: Arity d => Int -> Lens' (Point d r) r
- coord :: forall proxy i d r. (1 <= i, i <= d, ((i - 1) + 1) ~ i, Arity (i - 1), Arity d) => proxy i -> Lens' (Point d r) r
- pointFromList :: Arity d => [r] -> Maybe (Point d r)
- projectPoint :: (Arity i, Arity d, i <= d) => Point d r -> Point i r
- pattern Point2 :: r -> r -> Point 2 r
- pattern Point3 :: r -> r -> r -> Point 3 r
- point2 :: r -> r -> Point 2 r
- _point2 :: Point 2 r -> (r, r)
- point3 :: r -> r -> r -> Point 3 r
- _point3 :: Point 3 r -> (r, r, r)
- xCoord :: (1 <= d, Arity d) => Lens' (Point d r) r
- yCoord :: (2 <= d, Arity d) => Lens' (Point d r) r
- zCoord :: (3 <= d, Arity d) => Lens' (Point d r) r
- class PointFunctor g where
- data CCW
- ccw :: (Ord r, Num r) => Point 2 r -> Point 2 r -> Point 2 r -> CCW
- ccw' :: (Ord r, Num r) => (Point 2 r :+ a) -> (Point 2 r :+ b) -> (Point 2 r :+ c) -> CCW
- sortArround :: (Ord r, Num r) => (Point 2 r :+ q) -> [Point 2 r :+ p] -> [Point 2 r :+ p]
- data Quadrant
- quadrantWith :: (Ord r, 1 <= d, 2 <= d, Arity d) => (Point d r :+ q) -> (Point d r :+ p) -> Quadrant
- quadrant :: (Ord r, Num r, 1 <= d, 2 <= d, Arity d) => (Point d r :+ p) -> Quadrant
- partitionIntoQuadrants :: (Ord r, 1 <= d, 2 <= d, Arity d) => (Point d r :+ q) -> [Point d r :+ p] -> ([Point d r :+ p], [Point d r :+ p], [Point d r :+ p], [Point d r :+ p])
- ccwCmpAround :: (Num r, Ord r) => (Point 2 r :+ qc) -> (Point 2 r :+ p) -> (Point 2 r :+ q) -> Ordering
- cwCmpAround :: (Num r, Ord r) => (Point 2 r :+ qc) -> (Point 2 r :+ p) -> (Point 2 r :+ q) -> Ordering
- insertIntoCyclicOrder :: (Ord r, Num r) => (Point 2 r :+ q) -> (Point 2 r :+ p) -> CList (Point 2 r :+ p) -> CList (Point 2 r :+ p)
- squaredEuclideanDist :: (Num r, Arity d) => Point d r -> Point d r -> r
- euclideanDist :: (Floating r, Arity d) => Point d r -> Point d r -> r

# Documentation

`>>>`

let myVector :: Vector 3 Int myVector = Vector3 1 2 3 myPoint = Point myVector :}`:{`

# A d-dimensional Point

A d-dimensional point.

## Instances

Arity d => Functor (Point d) Source # | |

Arity d => Foldable (Point d) Source # | |

Defined in Data.Geometry.Point fold :: Monoid m => Point d m -> m # foldMap :: Monoid m => (a -> m) -> Point d a -> m # foldr :: (a -> b -> b) -> b -> Point d a -> b # foldr' :: (a -> b -> b) -> b -> Point d a -> b # foldl :: (b -> a -> b) -> b -> Point d a -> b # foldl' :: (b -> a -> b) -> b -> Point d a -> b # foldr1 :: (a -> a -> a) -> Point d a -> a # foldl1 :: (a -> a -> a) -> Point d a -> a # elem :: Eq a => a -> Point d a -> Bool # maximum :: Ord a => Point d a -> a # minimum :: Ord a => Point d a -> a # | |

Arity d => Traversable (Point d) Source # | |

(Arity d, Ord r) => Semigroup (CWMin (Point d r)) Source # | |

(Arity d, Ord r) => Semigroup (CWMax (Point d r)) Source # | |

Arity d => Affine (Point d) Source # | |

PointFunctor (Point d) Source # | |

(Eq r, Arity d) => Eq (Point d r) Source # | |

(Ord r, Arity d) => Ord (Point d r) Source # | |

Defined in Data.Geometry.Point | |

(Read r, Arity d) => Read (Point d r) Source # | |

(Show r, Arity d) => Show (Point d r) Source # | |

Generic (Point d r) Source # | |

(Arity d, NFData r) => NFData (Point d r) Source # | |

Defined in Data.Geometry.Point | |

(Arity d, Arbitrary r) => Arbitrary (Point d r) Source # | |

(FromJSON r, Arity d, KnownNat d) => FromJSON (Point d r) Source # | |

Defined in Data.Geometry.Point parseJSON :: Value -> Parser (Point d r) parseJSONList :: Value -> Parser [Point d r] | |

(ToJSON r, Arity d) => ToJSON (Point d r) Source # | |

Defined in Data.Geometry.Point toEncoding :: Point d r -> Encoding toJSONList :: [Point d r] -> Value toEncodingList :: [Point d r] -> Encoding | |

(Fractional r, Arity d, Arity (d + 1)) => IsTransformable (Point d r) Source # | |

Defined in Data.Geometry.Transformation transformBy :: Transformation (Dimension (Point d r)) (NumType (Point d r)) -> Point d r -> Point d r Source # | |

IsBoxable (Point d r) Source # | |

Defined in Data.Geometry.Box.Internal | |

(Eq r, Fractional r, Arity d) => IsIntersectableWith (Point d r) (Line d r) | |

(Num r, Eq r, Arity d) => IsIntersectableWith (Point d r) (HyperPlane d r) | |

Defined in Data.Geometry.HyperPlane intersect :: Point d r -> HyperPlane d r -> Intersection (Point d r) (HyperPlane d r) intersects :: Point d r -> HyperPlane d r -> Bool nonEmptyIntersection :: proxy (Point d r) -> proxy (HyperPlane d r) -> Intersection (Point d r) (HyperPlane d r) -> Bool | |

(Num r, Ord r, Arity d) => IsIntersectableWith (Point d r) (HalfSpace d r) | |

(Ord r, Num r) => IsIntersectableWith (Point 2 r) (Line 2 r) | |

(Arity d, Ord r) => IsIntersectableWith (Point d r) (Box d p r) | |

(Fractional r, Ord r) => IsIntersectableWith (Point 2 r) (Polygon t p r) | |

type Diff (Point d) Source # | |

Defined in Data.Geometry.Point | |

type Rep (Point d r) Source # | |

Defined in Data.Geometry.Point | |

type NumType (Point d r) Source # | |

Defined in Data.Geometry.Point | |

type Dimension (Point d r) Source # | |

Defined in Data.Geometry.Point | |

type IntersectionOf (Point d r) (Line d r) | |

Defined in Data.Geometry.Line | |

type IntersectionOf (Point d r) (HyperPlane d r) | |

Defined in Data.Geometry.HyperPlane | |

type IntersectionOf (Point d r) (HalfSpace d r) | |

Defined in Data.Geometry.HalfSpace | |

type IntersectionOf (Point d r) (Box d p r) | |

Defined in Data.Geometry.Box.Internal | |

type IntersectionOf (Point 2 r) (Polygon t p r) | |

Defined in Data.Geometry.Polygon |

origin :: (Arity d, Num r) => Point d r Source #

Point representing the origin in d dimensions

`>>>`

Point4 [0,0,0,0]`origin :: Point 4 Int`

## Accessing points

vector :: Lens' (Point d r) (Vector d r) Source #

Lens to access the vector corresponding to this point.

`>>>`

Vector3 [1,2,3]`(point3 1 2 3) ^. vector`

`>>>`

Point3 [1,2,3]`origin & vector .~ Vector3 1 2 3`

unsafeCoord :: Arity d => Int -> Lens' (Point d r) 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.

`>>>`

2`point3 1 2 3 ^. unsafeCoord 2`

coord :: forall proxy i d r. (1 <= i, i <= d, ((i - 1) + 1) ~ i, Arity (i - 1), Arity d) => proxy i -> Lens' (Point d r) r Source #

Get the coordinate in a given dimension

`>>>`

2`point3 1 2 3 ^. coord (C :: C 2)`

`>>>`

Point3 [10,2,3]`point3 1 2 3 & coord (C :: C 1) .~ 10`

`>>>`

Point3 [1,2,4]`point3 1 2 3 & coord (C :: C 3) %~ (+1)`

pointFromList :: Arity d => [r] -> Maybe (Point d r) Source #

Constructs a point from a list of coordinates

`>>>`

Just Point3 [1,2,3]`pointFromList [1,2,3] :: Maybe (Point 3 Int)`

projectPoint :: (Arity i, Arity d, i <= d) => Point d r -> Point i r Source #

Project a point down into a lower dimension.

# Convenience functions to construct 2 and 3 dimensional points

pattern Point2 :: r -> r -> Point 2 r Source #

We provide pattern synonyms Point2 and Point3 for 2 and 3 dimensional points. i.e. we can write:

`>>>`

let f :: Point 2 r -> r f (Point2 x y) = x in f (point2 1 2) :} 1`:{`

if we want.

pattern Point3 :: r -> r -> r -> Point 3 r Source #

Similarly, we can write:

`>>>`

let g :: Point 3 r -> r g (Point3 x y z) = z in g myPoint :} 3`:{`

point3 :: r -> r -> r -> Point 3 r Source #

Construct a 3 dimensional point

`>>>`

Point3 [1,2,3]`point3 1 2 3`

_point3 :: Point 3 r -> (r, r, r) Source #

Destruct a 3 dimensional point

`>>>`

(1,2,3)`_point3 $ point3 1 2 3`

xCoord :: (1 <= d, Arity d) => Lens' (Point d r) r Source #

Shorthand to access the first coordinate C 1

`>>>`

1`point3 1 2 3 ^. xCoord`

`>>>`

Point2 [10,2]`point2 1 2 & xCoord .~ 10`

yCoord :: (2 <= d, Arity d) => Lens' (Point d r) r Source #

Shorthand to access the second coordinate C 2

`>>>`

2`point2 1 2 ^. yCoord`

`>>>`

Point3 [1,3,3]`point3 1 2 3 & yCoord %~ (+1)`

zCoord :: (3 <= d, Arity d) => Lens' (Point d r) r Source #

Shorthand to access the third coordinate C 3

`>>>`

3`point3 1 2 3 ^. zCoord`

`>>>`

Point3 [1,2,4]`point3 1 2 3 & zCoord %~ (+1)`

# Point Functors

class PointFunctor g where Source #

Types that we can transform by mapping a function on each point in the structure

## Instances

PointFunctor (Point d) Source # | |

PointFunctor (ConvexPolygon p) Source # | |

Defined in Data.Geometry.Polygon.Convex pmap :: (Point (Dimension (ConvexPolygon p r)) r -> Point (Dimension (ConvexPolygon p s)) s) -> ConvexPolygon p r -> ConvexPolygon p s Source # | |

PointFunctor (Box d p) Source # | |

PointFunctor (LineSegment d p) Source # | |

Defined in Data.Geometry.LineSegment pmap :: (Point (Dimension (LineSegment d p r)) r -> Point (Dimension (LineSegment d p s)) s) -> LineSegment d p r -> LineSegment d p s Source # | |

PointFunctor (PolyLine d p) Source # | |

PointFunctor (Triangle d p) Source # | |

PointFunctor (Polygon t p) Source # | |

# Functions specific to Two Dimensional points

ccw :: (Ord r, Num r) => Point 2 r -> Point 2 r -> Point 2 r -> CCW Source #

Given three points p q and r determine the orientation when going from p to r via q.

ccw' :: (Ord r, Num r) => (Point 2 r :+ a) -> (Point 2 r :+ b) -> (Point 2 r :+ c) -> CCW Source #

Given three points p q and r determine the orientation when going from p to r via q.

sortArround :: (Ord r, Num r) => (Point 2 r :+ q) -> [Point 2 r :+ p] -> [Point 2 r :+ p] Source #

Sort the points arround the given point p in counter clockwise order with respect to the rightward horizontal ray starting from p. If two points q and r are colinear with p, the closest one to p is reported first. running time: O(n log n)

Quadrants of two dimensional points. in CCW order

## Instances

Bounded Quadrant Source # | |

Enum Quadrant Source # | |

Eq Quadrant Source # | |

Ord Quadrant Source # | |

Defined in Data.Geometry.Point | |

Read Quadrant Source # | |

Show Quadrant Source # | |

quadrantWith :: (Ord r, 1 <= d, 2 <= d, Arity d) => (Point d r :+ q) -> (Point d r :+ p) -> Quadrant Source #

Quadrants around point c; quadrants are closed on their "previous" boundary (i..e the boundary with the previous quadrant in the CCW order), open on next boundary. The origin itself is assigned the topRight quadrant

quadrant :: (Ord r, Num r, 1 <= d, 2 <= d, Arity d) => (Point d r :+ p) -> Quadrant Source #

Quadrants with respect to the origin

partitionIntoQuadrants :: (Ord r, 1 <= d, 2 <= d, Arity d) => (Point d r :+ q) -> [Point d r :+ p] -> ([Point d r :+ p], [Point d r :+ p], [Point d r :+ p], [Point d r :+ p]) Source #

Given a center point c, and a set of points, partition the points into quadrants around c (based on their x and y coordinates). The quadrants are reported in the order topLeft, topRight, bottomLeft, bottomRight. The points are in the same order as they were in the original input lists. Points with the same x-or y coordinate as p, are "rounded" to above.

ccwCmpAround :: (Num r, Ord r) => (Point 2 r :+ qc) -> (Point 2 r :+ p) -> (Point 2 r :+ q) -> Ordering Source #

Counter clockwise ordering of the points around c. Points are ordered with respect to the positive x-axis. Points nearer to the center come before points further away.

cwCmpAround :: (Num r, Ord r) => (Point 2 r :+ qc) -> (Point 2 r :+ p) -> (Point 2 r :+ q) -> Ordering Source #

Clockwise ordering of the points around c. Points are ordered with respect to the positive x-axis. Points nearer to the center come before points further away.

insertIntoCyclicOrder :: (Ord r, Num r) => (Point 2 r :+ q) -> (Point 2 r :+ p) -> CList (Point 2 r :+ p) -> CList (Point 2 r :+ p) Source #

Given a center c, a new point p, and a list of points ps, sorted in counter clockwise order around c. Insert p into the cyclic order. The focus of the returned cyclic list is the new point p.

running time: O(n)