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

HGeometry.Point

Description

\(d\)-dimensional points.

Synopsis

Documentation

type Point (d :: Nat) r = PointF (Vector d r) Source #

d-dimensional points

newtype PointF v Source #

A Point wraps a vector

Constructors

Point 

Fields

Bundled Patterns

pattern Point1 :: r -> Point 1 r

A bidirectional pattern synonym for 1 dimensional points.

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

A bidirectional pattern synonym for 2 dimensional points.

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

A bidirectional pattern synonym for 3 dimensional points.

pattern Point4 :: r -> r -> r -> r -> Point 4 r

A bidirectional pattern synonym for 4 dimensional points.

Instances

Instances details
Unbox v => Vector Vector (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Unbox v => MVector MVector (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

FromJSON v => FromJSON (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

ToJSON v => ToJSON (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

NFData v => NFData (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

rnf :: PointF v -> () Source #

Bounded v => Bounded (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Enum v => Enum (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Generic (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Associated Types

type Rep (PointF v) 
Instance details

Defined in HGeometry.Point.PointF

type Rep (PointF v) = D1 ('MetaData "PointF" "HGeometry.Point.PointF" "hgeometry-point-1.0.0.0-inplace" 'True) (C1 ('MetaCons "Point" 'PrefixI 'True) (S1 ('MetaSel ('Just "toVec") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 v)))

Methods

from :: PointF v -> Rep (PointF v) x Source #

to :: Rep (PointF v) x -> PointF v Source #

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

Defined in HGeometry.Point.PointF

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

Defined in HGeometry.Point.PointF

Methods

showsPrec :: Int -> PointF vector -> ShowS Source #

show :: PointF vector -> String Source #

showList :: [PointF vector] -> ShowS Source #

Eq v => Eq (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

(==) :: PointF v -> PointF v -> Bool Source #

(/=) :: PointF v -> PointF v -> Bool Source #

Ord v => Ord (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

compare :: PointF v -> PointF v -> Ordering Source #

(<) :: PointF v -> PointF v -> Bool Source #

(<=) :: PointF v -> PointF v -> Bool Source #

(>) :: PointF v -> PointF v -> Bool Source #

(>=) :: PointF v -> PointF v -> Bool Source #

max :: PointF v -> PointF v -> PointF v Source #

min :: PointF v -> PointF v -> PointF v Source #

(Vector_ v d r, Metric_ (Vector d r) d r) => HasSquaredEuclideanDistance (PointF v) Source # 
Instance details

Defined in HGeometry.Point.EuclideanDistance

Methods

squaredEuclideanDistTo :: forall r0 (d0 :: Nat) point. (r0 ~ NumType (PointF v), d0 ~ Dimension (PointF v), Num r0, Point_ point d0 r0) => point -> PointF v -> r0 Source #

pointClosestTo :: forall r0 (d0 :: Nat) point. (r0 ~ NumType (PointF v), d0 ~ Dimension (PointF v), Num r0, Point_ point d0 r0) => point -> PointF v -> Point d0 r0 Source #

pointClosestToWithDistance :: forall r0 (d0 :: Nat) point. (r0 ~ NumType (PointF v), d0 ~ Dimension (PointF v), Num r0, Point_ point d0 r0) => point -> PointF v -> (Point d0 r0, r0) Source #

Random v => Random (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

randomR :: RandomGen g => (PointF v, PointF v) -> g -> (PointF v, g) Source #

random :: RandomGen g => g -> (PointF v, g) Source #

randomRs :: RandomGen g => (PointF v, PointF v) -> g -> [PointF v] Source #

randoms :: RandomGen g => g -> [PointF v] Source #

Uniform v => Uniform (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

uniformM :: StatefulGen g m => g -> m (PointF v) Source #

UniformRange v => UniformRange (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

uniformRM :: StatefulGen g m => (PointF v, PointF v) -> g -> m (PointF v) Source #

isInRange :: (PointF v, PointF v) -> PointF v -> Bool Source #

Unbox v => Unbox (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

IsoUnbox (PointF v) v Source # 
Instance details

Defined in HGeometry.Point.PointF

Methods

toURepr :: PointF v -> v Source #

fromURepr :: v -> PointF v Source #

(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 #

(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 #

(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 #

(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 #

(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 #

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 #

newtype MVector s (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

newtype MVector s (PointF v) = MV_PointF (MVector s v)
type Rep (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

type Rep (PointF v) = D1 ('MetaData "PointF" "HGeometry.Point.PointF" "hgeometry-point-1.0.0.0-inplace" 'True) (C1 ('MetaCons "Point" 'PrefixI 'True) (S1 ('MetaSel ('Just "toVec") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 v)))
type Dimension (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

type NumType (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

type NumType (PointF v) = IxValue v
type IxValue (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

type IxValue (PointF v) = IxValue v
newtype Vector (PointF v) Source # 
Instance details

Defined in HGeometry.Point.PointF

newtype Vector (PointF v) = V_PointF (Vector v)

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 #

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 #

asPoint :: forall point (d :: Nat) r. Point_ point d r => Lens' point (Point d r) Source #

Convert a generic point into a Point d r, dropping any additional information we may now about it.

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

projectPoint :: forall (i :: Nat) point (d :: Nat) r. (Point_ point d r, i <= d, Has_ Vector_ i r) => point -> Point i r Source #

Project a point into a lower dimension.

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 #

data CCW where Source #

Data type for expressing the orientation of three points, with the option of allowing Colinearities.

Bundled Patterns

pattern CCW :: CCW

CounterClockwise orientation. Also called a left-turn.

pattern CW :: CCW

Clockwise orientation. Also called a right-turn.

pattern CoLinear :: CCW

CoLinear orientation. Also called a straight line.

Instances

Instances details
Show CCW Source # 
Instance details

Defined in HGeometry.Point.Orientation.Degenerate

Eq CCW Source # 
Instance details

Defined in HGeometry.Point.Orientation.Degenerate

Methods

(==) :: CCW -> CCW -> Bool Source #

(/=) :: CCW -> CCW -> Bool Source #

ccw :: (Point_ point 2 r, Point_ point' 2 r, Point_ point'' 2 r, Num r, Ord r) => point -> point' -> point'' -> CCW Source #

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

Be wary of numerical instability: >>> ccw (Point2 0 0.3) (Point2 1 0.6) (Point2 2 (0.9::Double)) CCW

>>> ccw (Point2 0 0.3) (Point2 1 0.6) (Point2 2 (0.9::Rational))
CoLinear

isCoLinear :: (Point_ point 2 r, Num r, Eq r) => point -> point -> point -> Bool Source #

Given three points p q and r determine if the line from p to r via q is straight/colinear.

This is identical to `ccw p q r == CoLinear` but doesn't have the Ord constraint.

ccwCmpAround :: (Point_ center 2 r, Point_ point 2 r, Ord r, Num r) => center -> point -> point -> Ordering Source #

Counter clockwise ordering of the points around c. Points are ordered with respect to the positive x-axis.

cwCmpAround :: (Point_ center 2 r, Point_ point 2 r, Ord r, Num r) => center -> point -> point -> Ordering Source #

Clockwise ordering of the points around c. Points are ordered with respect to the positive x-axis.

ccwCmpAroundWith :: (Point_ center 2 r, Point_ point 2 r, Ord r, Num r) => Vector 2 r -> center -> point -> point -> Ordering Source #

Given a zero vector z, a center c, and two points p and q, compute the ccw ordering of p and q around c with this vector as zero direction.

pre: the points p,q /= c

cwCmpAroundWith :: (Point_ center 2 r, Point_ point 2 r, Ord r, Num r) => Vector 2 r -> center -> point -> point -> Ordering Source #

Given a zero vector z, a center c, and two points p and q, compute the cw ordering of p and q around c with this vector as zero direction.

pre: the points p,q /= c

sortAround :: (Point_ center 2 r, Point_ point 2 r, Num r, Ord r) => center -> [point] -> [point] 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.

\( O(n log n) \)

insertIntoCyclicOrder :: (Point_ center 2 r, Point_ point 2 r, Ord r, Num r) => center -> point -> CList point -> CList point Source #

\( O(n) \) 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.

data Quadrant Source #

Quadrants of two dimensional points. in CCW order

Instances

Instances details
Bounded Quadrant Source # 
Instance details

Defined in HGeometry.Point.Quadrants

Enum Quadrant Source # 
Instance details

Defined in HGeometry.Point.Quadrants

Read Quadrant Source # 
Instance details

Defined in HGeometry.Point.Quadrants

Show Quadrant Source # 
Instance details

Defined in HGeometry.Point.Quadrants

Eq Quadrant Source # 
Instance details

Defined in HGeometry.Point.Quadrants

Ord Quadrant Source # 
Instance details

Defined in HGeometry.Point.Quadrants

quadrantWith :: (Ord r, Point_ point 2 r) => point -> point -> 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, ConstructablePoint_ point 2 r) => point -> Quadrant Source #

Quadrants with respect to the origin

partitionIntoQuadrants :: (Ord r, Point_ point 2 r) => point -> [point] -> ([point], [point], [point], [point]) 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.

cmpByDistanceTo :: forall r point (d :: Nat) center. (Ord r, Num r, Point_ point d r, Point_ center d r, Metric_ (Vector d r) d r) => center -> point -> point -> Ordering Source #

Compare two points by their distance to the first argument

cmpInDirection2 :: (Num r, Ord r, Point_ point 2 r) => Vector 2 r -> point -> point -> Ordering Source #

Comparison that compares which point is larger in the direction given by the vector u.

squaredEuclideanDist :: forall r point (d :: Nat) point'. (Num r, Point_ point d r, Point_ point' d r, Metric_ (Vector d r) d r) => point -> point' -> r Source #

Squared Euclidean distance between two points

euclideanDist :: forall r point (d :: Nat). (Radical r, Point_ point d r, Metric_ (Vector d r) d r) => point -> point -> r Source #

Euclidean distance between two points

class Metric_ (Vector (Dimension g) (NumType g)) (Dimension g) (NumType g) => HasSquaredEuclideanDistance g where Source #

Types for which we can compute the squared Euclidean distance.

Minimal complete definition

pointClosestToWithDistance | pointClosestTo

Methods

squaredEuclideanDistTo :: forall r (d :: Nat) point. (r ~ NumType g, d ~ Dimension g, Num r, Point_ point d r) => point -> g -> r Source #

Given a point q and a geometry g, the squared Euclidean distance between q and g.

pointClosestTo :: forall r (d :: Nat) point. (r ~ NumType g, d ~ Dimension g, Num r, Point_ point d r) => point -> g -> Point d r Source #

Given q and g, computes the point p in g closest to q according to the Squared Euclidean distance.

pointClosestToWithDistance :: forall r (d :: Nat) point. (r ~ NumType g, d ~ Dimension g, Num r, Point_ point d r) => point -> g -> (Point d r, r) Source #

Given q and g, computes the point p in g closest to q according to the Squared Euclidean distance. Returns both the point and the distance realized by this point.

Instances

Instances details
(Vector_ v d r, Metric_ (Vector d r) d r) => HasSquaredEuclideanDistance (PointF v) Source # 
Instance details

Defined in HGeometry.Point.EuclideanDistance

Methods

squaredEuclideanDistTo :: forall r0 (d0 :: Nat) point. (r0 ~ NumType (PointF v), d0 ~ Dimension (PointF v), Num r0, Point_ point d0 r0) => point -> PointF v -> r0 Source #

pointClosestTo :: forall r0 (d0 :: Nat) point. (r0 ~ NumType (PointF v), d0 ~ Dimension (PointF v), Num r0, Point_ point d0 r0) => point -> PointF v -> Point d0 r0 Source #

pointClosestToWithDistance :: forall r0 (d0 :: Nat) point. (r0 ~ NumType (PointF v), d0 ~ Dimension (PointF v), Num r0, Point_ point d0 r0) => point -> PointF v -> (Point d0 r0, r0) Source #

HasSquaredEuclideanDistance p => HasSquaredEuclideanDistance (p :+ extra) Source # 
Instance details

Defined in HGeometry.Point.EuclideanDistance

Methods

squaredEuclideanDistTo :: forall r (d :: Nat) point. (r ~ NumType (p :+ extra), d ~ Dimension (p :+ extra), Num r, Point_ point d r) => point -> (p :+ extra) -> r Source #

pointClosestTo :: forall r (d :: Nat) point. (r ~ NumType (p :+ extra), d ~ Dimension (p :+ extra), Num r, Point_ point d r) => point -> (p :+ extra) -> Point d r Source #

pointClosestToWithDistance :: forall r (d :: Nat) point. (r ~ NumType (p :+ extra), d ~ Dimension (p :+ extra), Num r, Point_ point d r) => point -> (p :+ extra) -> (Point d r, r) Source #

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'

type CanonicalPoint geom = Point (Dimension geom) (NumType geom) Source #

Canonical point in the dimension and numtype of the geometry