hgeometry-0.12.0.1: Geometric Algorithms, Data structures, and Data types.
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageHaskell2010

Data.Geometry.Line.Internal

Description

\(d\)-dimensional lines.

Synopsis

d-dimensional Lines

data Line d r Source #

A line is given by an anchor point and a vector indicating the direction.

Constructors

Line 

Fields

Instances

Instances details
Arity d => Functor (Line d) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

fmap :: (a -> b) -> Line d a -> Line d b #

(<$) :: a -> Line d b -> Line d a #

Arity d => Foldable (Line d) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

fold :: Monoid m => Line d m -> m #

foldMap :: Monoid m => (a -> m) -> Line d a -> m #

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

foldr :: (a -> b -> b) -> b -> Line d a -> b #

foldr' :: (a -> b -> b) -> b -> Line d a -> b #

foldl :: (b -> a -> b) -> b -> Line d a -> b #

foldl' :: (b -> a -> b) -> b -> Line d a -> b #

foldr1 :: (a -> a -> a) -> Line d a -> a #

foldl1 :: (a -> a -> a) -> Line d a -> a #

toList :: Line d a -> [a] #

null :: Line d a -> Bool #

length :: Line d a -> Int #

elem :: Eq a => a -> Line d a -> Bool #

maximum :: Ord a => Line d a -> a #

minimum :: Ord a => Line d a -> a #

sum :: Num a => Line d a -> a #

product :: Num a => Line d a -> a #

Arity d => Traversable (Line d) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

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

sequenceA :: Applicative f => Line d (f a) -> f (Line d a) #

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

sequence :: Monad m => Line d (m a) -> m (Line d a) #

(Arity d, Eq r, Fractional r) => Eq (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

(==) :: Line d r -> Line d r -> Bool #

(/=) :: Line d r -> Line d r -> Bool #

(Show r, Arity d) => Show (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

showsPrec :: Int -> Line d r -> ShowS #

show :: Line d r -> String #

showList :: [Line d r] -> ShowS #

Generic (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Associated Types

type Rep (Line d r) :: Type -> Type #

Methods

from :: Line d r -> Rep (Line d r) x #

to :: Rep (Line d r) x -> Line d r #

(Arbitrary r, Arity d, Num r, Eq r) => Arbitrary (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

arbitrary :: Gen (Line d r) #

shrink :: Line d r -> [Line d r] #

(NFData r, Arity d) => NFData (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

rnf :: Line d r -> () #

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

Lines are transformable, via line segments

Instance details

Defined in Data.Geometry.Line

Methods

transformBy :: Transformation (Dimension (Line d r)) (NumType (Line d r)) -> Line d r -> Line d r Source #

OnSideUpDownTest (Line 2 r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

onSideUpDown :: forall (d :: Nat) r0. (d ~ Dimension (Line 2 r), r0 ~ NumType (Line 2 r), Ord r0, Num r0) => Point d r0 -> Line 2 r -> SideTestUpDown Source #

HasSupportingLine (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

supportingLine :: Line d r -> Line (Dimension (Line d r)) (NumType (Line d r)) Source #

(Ord r, Fractional r) => IsIntersectableWith (Line 2 r) (Boundary (Rectangle p r)) Source # 
Instance details

Defined in Data.Geometry.Line

Methods

intersect :: Line 2 r -> Boundary (Rectangle p r) -> Intersection (Line 2 r) (Boundary (Rectangle p r)) #

intersects :: Line 2 r -> Boundary (Rectangle p r) -> Bool #

nonEmptyIntersection :: proxy (Line 2 r) -> proxy (Boundary (Rectangle p r)) -> Intersection (Line 2 r) (Boundary (Rectangle p r)) -> Bool #

(Eq r, Fractional r) => IsIntersectableWith (Line 3 r) (Plane r) Source # 
Instance details

Defined in Data.Geometry.HyperPlane

Methods

intersect :: Line 3 r -> Plane r -> Intersection (Line 3 r) (Plane r) #

intersects :: Line 3 r -> Plane r -> Bool #

nonEmptyIntersection :: proxy (Line 3 r) -> proxy (Plane r) -> Intersection (Line 3 r) (Plane r) -> Bool #

(Eq r, Fractional r, Arity d) => IsIntersectableWith (Point d r) (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line

Methods

intersect :: Point d r -> Line d r -> Intersection (Point d r) (Line d r) #

intersects :: Point d r -> Line d r -> Bool #

nonEmptyIntersection :: proxy (Point d r) -> proxy (Line d r) -> Intersection (Point d r) (Line d r) -> Bool #

(Ord r, Num r) => IsIntersectableWith (Point 2 r) (Line 2 r) Source # 
Instance details

Defined in Data.Geometry.Line

Methods

intersect :: Point 2 r -> Line 2 r -> Intersection (Point 2 r) (Line 2 r) #

intersects :: Point 2 r -> Line 2 r -> Bool #

nonEmptyIntersection :: proxy (Point 2 r) -> proxy (Line 2 r) -> Intersection (Point 2 r) (Line 2 r) -> Bool #

(Eq r, Fractional r) => IsIntersectableWith (Line 2 r) (Line 2 r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

intersect :: Line 2 r -> Line 2 r -> Intersection (Line 2 r) (Line 2 r) #

intersects :: Line 2 r -> Line 2 r -> Bool #

nonEmptyIntersection :: proxy (Line 2 r) -> proxy (Line 2 r) -> Intersection (Line 2 r) (Line 2 r) -> Bool #

(Ord r, Fractional r) => IsIntersectableWith (Line 2 r) (Rectangle p r) Source # 
Instance details

Defined in Data.Geometry.Line

Methods

intersect :: Line 2 r -> Rectangle p r -> Intersection (Line 2 r) (Rectangle p r) #

intersects :: Line 2 r -> Rectangle p r -> Bool #

nonEmptyIntersection :: proxy (Line 2 r) -> proxy (Rectangle p r) -> Intersection (Line 2 r) (Rectangle p r) -> Bool #

(Fractional r, Ord r) => IsIntersectableWith (Line 2 r) (HalfSpace 2 r) Source # 
Instance details

Defined in Data.Geometry.HalfSpace

Methods

intersect :: Line 2 r -> HalfSpace 2 r -> Intersection (Line 2 r) (HalfSpace 2 r) #

intersects :: Line 2 r -> HalfSpace 2 r -> Bool #

nonEmptyIntersection :: proxy (Line 2 r) -> proxy (HalfSpace 2 r) -> Intersection (Line 2 r) (HalfSpace 2 r) -> Bool #

(Ord r, Floating r) => IsIntersectableWith (Line 2 r) (Circle p r) Source # 
Instance details

Defined in Data.Geometry.Ball

Methods

intersect :: Line 2 r -> Circle p r -> Intersection (Line 2 r) (Circle p r) #

intersects :: Line 2 r -> Circle p r -> Bool #

nonEmptyIntersection :: proxy (Line 2 r) -> proxy (Circle p r) -> Intersection (Line 2 r) (Circle p r) -> Bool #

(Ord r, Fractional r) => IsIntersectableWith (HalfLine 2 r) (Line 2 r) Source # 
Instance details

Defined in Data.Geometry.HalfLine

Methods

intersect :: HalfLine 2 r -> Line 2 r -> Intersection (HalfLine 2 r) (Line 2 r) #

intersects :: HalfLine 2 r -> Line 2 r -> Bool #

nonEmptyIntersection :: proxy (HalfLine 2 r) -> proxy (Line 2 r) -> Intersection (HalfLine 2 r) (Line 2 r) -> Bool #

(Fractional r, Ord r, HasBoundingLines o) => IsIntersectableWith (Line 2 r) (Slab o a r) Source # 
Instance details

Defined in Data.Geometry.Slab

Methods

intersect :: Line 2 r -> Slab o a r -> Intersection (Line 2 r) (Slab o a r) #

intersects :: Line 2 r -> Slab o a r -> Bool #

nonEmptyIntersection :: proxy (Line 2 r) -> proxy (Slab o a r) -> Intersection (Line 2 r) (Slab o a r) -> Bool #

(Fractional r, Ord r) => IsIntersectableWith (Line 2 r) (Triangle 2 p r) Source # 
Instance details

Defined in Data.Geometry.Triangle

Methods

intersect :: Line 2 r -> Triangle 2 p r -> Intersection (Line 2 r) (Triangle 2 p r) #

intersects :: Line 2 r -> Triangle 2 p r -> Bool #

nonEmptyIntersection :: proxy (Line 2 r) -> proxy (Triangle 2 p r) -> Intersection (Line 2 r) (Triangle 2 p r) -> Bool #

(Fractional r, Ord r) => IsIntersectableWith (Line 3 r) (Triangle 3 p r) Source # 
Instance details

Defined in Data.Geometry.Triangle

Methods

intersect :: Line 3 r -> Triangle 3 p r -> Intersection (Line 3 r) (Triangle 3 p r) #

intersects :: Line 3 r -> Triangle 3 p r -> Bool #

nonEmptyIntersection :: proxy (Line 3 r) -> proxy (Triangle 3 p r) -> Intersection (Line 3 r) (Triangle 3 p r) -> Bool #

(Ord r, Fractional r) => IsIntersectableWith (LineSegment 2 p r) (Line 2 r) Source # 
Instance details

Defined in Data.Geometry.LineSegment.Internal

Methods

intersect :: LineSegment 2 p r -> Line 2 r -> Intersection (LineSegment 2 p r) (Line 2 r) #

intersects :: LineSegment 2 p r -> Line 2 r -> Bool #

nonEmptyIntersection :: proxy (LineSegment 2 p r) -> proxy (Line 2 r) -> Intersection (LineSegment 2 p r) (Line 2 r) -> Bool #

type Rep (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

type Rep (Line d r) = D1 ('MetaData "Line" "Data.Geometry.Line.Internal" "hgeometry-0.12.0.1-744QXwUb5uS54emseMX1Co" 'False) (C1 ('MetaCons "Line" 'PrefixI 'True) (S1 ('MetaSel ('Just "_anchorPoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Point d r)) :*: S1 ('MetaSel ('Just "_direction") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Vector d r))))
type NumType (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

type NumType (Line d r) = r
type Dimension (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

type Dimension (Line d r) = d
type IntersectionOf (Line 2 r) (Boundary (Rectangle p r)) Source # 
Instance details

Defined in Data.Geometry.Line

type IntersectionOf (Line 2 r) (Boundary (Rectangle p r)) = '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r), LineSegment 2 () r]
type IntersectionOf (Line 2 r) (Boundary (Polygon t p r)) Source # 
Instance details

Defined in Data.Geometry.Polygon

type IntersectionOf (Line 2 r) (Boundary (Polygon t p r)) = '[Seq (Either (Point 2 r) (LineSegment 2 () r))]
type IntersectionOf (Line 3 r) (Plane r) Source # 
Instance details

Defined in Data.Geometry.HyperPlane

type IntersectionOf (Line 3 r) (Plane r) = '[NoIntersection, Point 3 r, Line 3 r]
type IntersectionOf (Point d r) (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line

type IntersectionOf (Point d r) (Line d r) = '[NoIntersection, Point d r]
type IntersectionOf (Line d r) (HalfSpace d r) Source # 
Instance details

Defined in Data.Geometry.HalfSpace

type IntersectionOf (Line d r) (HalfSpace d r) = '[NoIntersection, HalfLine d r, Line d r]
type IntersectionOf (Line 2 r) (Line 2 r) Source #

The intersection of two lines is either: NoIntersection, a point or a line.

Instance details

Defined in Data.Geometry.Line.Internal

type IntersectionOf (Line 2 r) (Line 2 r) = '[NoIntersection, Point 2 r, Line 2 r]
type IntersectionOf (Line 2 r) (Rectangle p r) Source # 
Instance details

Defined in Data.Geometry.Line

type IntersectionOf (Line 2 r) (Rectangle p r) = '[NoIntersection, Point 2 r, LineSegment 2 () r]
type IntersectionOf (Line 2 r) (Circle p r) Source #

No intersection, one touching point, or two points

Instance details

Defined in Data.Geometry.Ball

type IntersectionOf (Line 2 r) (Circle p r) = '[NoIntersection, Touching (Point 2 r), (Point 2 r, Point 2 r)]
type IntersectionOf (HalfLine d r) (Line d r) Source # 
Instance details

Defined in Data.Geometry.HalfLine

type IntersectionOf (HalfLine d r) (Line d r) = '[NoIntersection, Point d r, HalfLine d r]
type IntersectionOf (Line 2 r) (Slab o a r) Source # 
Instance details

Defined in Data.Geometry.Slab

type IntersectionOf (Line 2 r) (Slab o a r) = '[NoIntersection, Line 2 r, LineSegment 2 a r]
type IntersectionOf (Line 2 r) (Triangle 2 p r) Source # 
Instance details

Defined in Data.Geometry.Triangle

type IntersectionOf (Line 2 r) (Triangle 2 p r) = '[NoIntersection, Point 2 r, LineSegment 2 () r]
type IntersectionOf (Line 3 r) (Triangle 3 p r) Source # 
Instance details

Defined in Data.Geometry.Triangle

type IntersectionOf (Line 3 r) (Triangle 3 p r) = '[NoIntersection, Point 3 r, LineSegment 3 () r]
type IntersectionOf (LineSegment 2 p r) (Line 2 r) Source # 
Instance details

Defined in Data.Geometry.LineSegment.Internal

type IntersectionOf (LineSegment 2 p r) (Line 2 r) = '[NoIntersection, Point 2 r, LineSegment 2 p r]

anchorPoint :: Lens' (Line d r) (Point d r) Source #

Line anchor point.

direction :: Lens' (Line d r) (Vector d r) Source #

Line direction.

Functions on lines

lineThrough :: (Num r, Arity d) => Point d r -> Point d r -> Line d r Source #

A line may be constructed from two points.

verticalLine :: Num r => r -> Line 2 r Source #

Vertical line with a given X-coordinate.

horizontalLine :: Num r => r -> Line 2 r Source #

Horizontal line with a given Y-coordinate.

perpendicularTo :: Num r => Line 2 r -> Line 2 r Source #

Given a line l with anchor point p and vector v, get the line perpendicular to l that also goes through p. The resulting line m is oriented such that v points into the left halfplane of m.

>>> perpendicularTo $ Line (Point2 3 4) (Vector2 (-1) 2)
Line (Point2 3 4) (Vector2 (-2) (-1))

isPerpendicularTo :: (Num r, Eq r) => Vector 2 r -> Line 2 r -> Bool Source #

Test if a vector is perpendicular to the line.

isIdenticalTo :: (Eq r, Arity d) => Line d r -> Line d r -> Bool Source #

Test if two lines are identical, meaning; if they have exactly the same anchor point and directional vector.

isParallelTo :: (Eq r, Fractional r, Arity d) => Line d r -> Line d r -> Bool Source #

Test if the two lines are parallel.

>>> lineThrough origin (Point2 1 0) `isParallelTo` lineThrough (Point2 1 1) (Point2 2 1)
True
>>> lineThrough origin (Point2 1 0) `isParallelTo` lineThrough (Point2 1 1) (Point2 2 2)
False

onLine :: (Eq r, Fractional r, Arity d) => Point d r -> Line d r -> Bool Source #

Test if point p lies on line l

>>> origin `onLine` lineThrough origin (Point2 1 0)
True
>>> Point2 10 10 `onLine` lineThrough origin (Point2 2 2)
True
>>> Point2 10 5 `onLine` lineThrough origin (Point2 2 2)
False

onLine2 :: (Ord r, Num r) => Point 2 r -> Line 2 r -> Bool Source #

Specific 2d version of testing if apoint lies on a line.

pointAt :: (Num r, Arity d) => r -> Line d r -> Point d r Source #

Get the point at the given position along line, where 0 corresponds to the anchorPoint of the line, and 1 to the point anchorPoint .+^ directionVector

toOffset :: (Eq r, Fractional r, Arity d) => Point d r -> Line d r -> Maybe r Source #

Given point p and a line (Line q v), Get the scalar lambda s.t. p = q + lambda v. If p does not lie on the line this returns a Nothing.

toOffset' :: (Eq r, Fractional r, Arity d) => Point d r -> Line d r -> r Source #

Given point p near a line (Line q v), get the scalar lambda s.t. the distance between p and 'q + lambda v' is minimized.

>>> toOffset' (Point2 1 1) (lineThrough origin $ Point2 10 10)
0.1
>>> toOffset' (Point2 5 5) (lineThrough origin $ Point2 10 10)
0.5

<6,4> is not on the line but we can still point closest to it. >>> toOffset' (Point2 6 4) (lineThrough origin $ Point2 10 10) 0.5

sqDistanceTo :: (Fractional r, Arity d) => Point d r -> Line d r -> r Source #

Squared distance from point p to line l

sqDistanceToArg :: (Fractional r, Arity d) => Point d r -> Line d r -> (r, Point d r) Source #

The squared distance between the point p and the line l, and the point m realizing this distance.

Supporting Lines

class HasSupportingLine t where Source #

Types for which we can compute a supporting line, i.e. a line that contains the thing of type t.

Methods

supportingLine :: t -> Line (Dimension t) (NumType t) Source #

Instances

Instances details
HasSupportingLine (Line d r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

supportingLine :: Line d r -> Line (Dimension (Line d r)) (NumType (Line d r)) Source #

HasSupportingLine (HalfLine d r) Source # 
Instance details

Defined in Data.Geometry.HalfLine

(Num r, Arity d) => HasSupportingLine (LineSegment d p r) Source # 
Instance details

Defined in Data.Geometry.LineSegment.Internal

Convenience functions on Two dimensional lines

fromLinearFunction :: Num r => r -> r -> Line 2 r Source #

Create a line from the linear function ax + b

toLinearFunction :: forall r. (Fractional r, Eq r) => Line 2 r -> Maybe (r, r) Source #

get values a,b s.t. the input line is described by y = ax + b. returns Nothing if the line is vertical

class OnSideUpDownTest t where Source #

Methods

onSideUpDown :: (d ~ Dimension t, r ~ NumType t, Ord r, Num r) => Point d r -> t -> SideTestUpDown Source #

Instances

Instances details
OnSideUpDownTest (Plane r) Source # 
Instance details

Defined in Data.Geometry.HyperPlane

Methods

onSideUpDown :: forall (d :: Nat) r0. (d ~ Dimension (Plane r), r0 ~ NumType (Plane r), Ord r0, Num r0) => Point d r0 -> Plane r -> SideTestUpDown Source #

OnSideUpDownTest (Line 2 r) Source # 
Instance details

Defined in Data.Geometry.Line.Internal

Methods

onSideUpDown :: forall (d :: Nat) r0. (d ~ Dimension (Line 2 r), r0 ~ NumType (Line 2 r), Ord r0, Num r0) => Point d r0 -> Line 2 r -> SideTestUpDown Source #

data SideTest Source #

Result of a side test

Constructors

LeftSide 
OnLine 
RightSide 

onSide :: (Ord r, Num r) => Point 2 r -> Line 2 r -> SideTest Source #

Given a point q and a line l, compute to which side of l q lies. For vertical lines the left side of the line is interpeted as below.

>>> Point2 10 10 `onSide` (lineThrough origin $ Point2 10 5)
LeftSide
>>> Point2 10 10 `onSide` (lineThrough origin $ Point2 (-10) 5)
RightSide
>>> Point2 5 5 `onSide` (verticalLine 10)
LeftSide
>>> Point2 5 5 `onSide` (lineThrough origin $ Point2 (-3) (-3))
OnLine

liesAbove :: (Ord r, Num r) => Point 2 r -> Line 2 r -> Bool Source #

Test if the query point q lies (strictly) above line l

liesBelow :: (Ord r, Num r) => Point 2 r -> Line 2 r -> Bool Source #

Test if the query point q lies (strictly) above line l

bisector :: Fractional r => Point 2 r -> Point 2 r -> Line 2 r Source #

Get the bisector between two points

cmpSlope :: (Num r, Ord r) => Line 2 r -> Line 2 r -> Ordering Source #

Compares the lines on slope. Vertical lines are considered larger than anything else.

>>> (Line origin (Vector2 5 1)) `cmpSlope` (Line origin (Vector2 3 3))
LT
>>> (Line origin (Vector2 5 1)) `cmpSlope` (Line origin (Vector2 (-3) 3))
GT
>>> (Line origin (Vector2 5 1)) `cmpSlope` (Line origin (Vector2 0 1))
LT