hgeometry
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageGHC2021

HGeometry.LineSegment.Intersection.Naive

Description

Line segment intersections in \(O(n^2)\) by checking all pairs.

Synopsis

Documentation

intersections :: (Ord r, Fractional r, LineSegment_ lineSegment point, Eq lineSegment, Point_ point 2 r, IntersectConstraints lineSegment, Foldable f) => f lineSegment -> Intersections r lineSegment Source #

Compute all intersections (naively)

\(O(n^2)\)

type Intersections r lineSegment = Map (Point 2 r) (Associated lineSegment) Source #

For each intersection point the segments intersecting there.

data Associated lineSegment Source #

The line segments that contain a given point p may either have p as the endpoint or have p in their interior.

if somehow the segment is degenerate, and p is both the start and end it is reported only as the start point.

Instances

Instances details
NFData lineSegment => NFData (Associated lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

rnf :: Associated lineSegment -> () #

OrdArounds lineSegment => Monoid (Associated lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

mempty :: Associated lineSegment #

mappend :: Associated lineSegment -> Associated lineSegment -> Associated lineSegment #

mconcat :: [Associated lineSegment] -> Associated lineSegment #

OrdArounds lineSegment => Semigroup (Associated lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

(<>) :: Associated lineSegment -> Associated lineSegment -> Associated lineSegment #

sconcat :: NonEmpty (Associated lineSegment) -> Associated lineSegment #

stimes :: Integral b => b -> Associated lineSegment -> Associated lineSegment #

Generic (Associated lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Associated Types

type Rep (Associated lineSegment) 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (Associated lineSegment) = D1 ('MetaData "Associated" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'False) (C1 ('MetaCons "Associated" 'PrefixI 'True) (S1 ('MetaSel ('Just "_startPointOf") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set (AroundStart lineSegment))) :*: (S1 ('MetaSel ('Just "_endPointOf") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set (AroundEnd lineSegment))) :*: S1 ('MetaSel ('Just "_interiorTo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set (AroundIntersection lineSegment))))))

Methods

from :: Associated lineSegment -> Rep (Associated lineSegment) x #

to :: Rep (Associated lineSegment) x -> Associated lineSegment #

(Read lineSegment, OrdArounds lineSegment) => Read (Associated lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

readsPrec :: Int -> ReadS (Associated lineSegment) #

readList :: ReadS [Associated lineSegment] #

readPrec :: ReadPrec (Associated lineSegment) #

readListPrec :: ReadPrec [Associated lineSegment] #

Show lineSegment => Show (Associated lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

showsPrec :: Int -> Associated lineSegment -> ShowS #

show :: Associated lineSegment -> String #

showList :: [Associated lineSegment] -> ShowS #

(Eq (AroundStart lineSegment), Eq (AroundIntersection lineSegment), Eq (AroundEnd lineSegment)) => Eq (Associated lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

(==) :: Associated lineSegment -> Associated lineSegment -> Bool #

(/=) :: Associated lineSegment -> Associated lineSegment -> Bool #

type Rep (Associated lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (Associated lineSegment) = D1 ('MetaData "Associated" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'False) (C1 ('MetaCons "Associated" 'PrefixI 'True) (S1 ('MetaSel ('Just "_startPointOf") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set (AroundStart lineSegment))) :*: (S1 ('MetaSel ('Just "_endPointOf") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set (AroundEnd lineSegment))) :*: S1 ('MetaSel ('Just "_interiorTo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set (AroundIntersection lineSegment))))))

startPointOf :: forall lineSegment f. Functor f => (Set (AroundStart lineSegment) -> f (Set (AroundStart lineSegment))) -> Associated lineSegment -> f (Associated lineSegment) Source #

Lens to access the segments for which this is a startPoint

endPointOf :: forall lineSegment f. Functor f => (Set (AroundEnd lineSegment) -> f (Set (AroundEnd lineSegment))) -> Associated lineSegment -> f (Associated lineSegment) Source #

Lens to access the segments for which this is an endPoint

interiorTo :: forall lineSegment f. Functor f => (Set (AroundIntersection lineSegment) -> f (Set (AroundIntersection lineSegment))) -> Associated lineSegment -> f (Associated lineSegment) Source #

Lens to access the segments for which this point lies in the interior of the segment

associatedSegments :: forall lineSegment f. (Contravariant f, Applicative f) => (lineSegment -> f lineSegment) -> Associated lineSegment -> f (Associated lineSegment) Source #

Fold over the segments associated with the intersection.

data AroundEnd a Source #

Assumes that two segments have the same end point

Instances

Instances details
Functor AroundEnd Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

fmap :: (a -> b) -> AroundEnd a -> AroundEnd b #

(<$) :: a -> AroundEnd b -> AroundEnd a #

NFData a => NFData (AroundEnd a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

rnf :: AroundEnd a -> () #

Generic (AroundEnd a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Associated Types

type Rep (AroundEnd a) 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (AroundEnd a) = D1 ('MetaData "AroundEnd" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'True) (C1 ('MetaCons "AroundEnd" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

Methods

from :: AroundEnd a -> Rep (AroundEnd a) x #

to :: Rep (AroundEnd a) x -> AroundEnd a #

Read a => Read (AroundEnd a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Show a => Show (AroundEnd a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

(Point_ point 2 r, Eq r, HasStart lineSegment point) => Eq (AroundEnd lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

(==) :: AroundEnd lineSegment -> AroundEnd lineSegment -> Bool #

(/=) :: AroundEnd lineSegment -> AroundEnd lineSegment -> Bool #

(LineSegment_ lineSegment point, Point_ point 2 r, Ord r, Num r, Eq lineSegment) => Ord (AroundEnd lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

compare :: AroundEnd lineSegment -> AroundEnd lineSegment -> Ordering #

(<) :: AroundEnd lineSegment -> AroundEnd lineSegment -> Bool #

(<=) :: AroundEnd lineSegment -> AroundEnd lineSegment -> Bool #

(>) :: AroundEnd lineSegment -> AroundEnd lineSegment -> Bool #

(>=) :: AroundEnd lineSegment -> AroundEnd lineSegment -> Bool #

max :: AroundEnd lineSegment -> AroundEnd lineSegment -> AroundEnd lineSegment #

min :: AroundEnd lineSegment -> AroundEnd lineSegment -> AroundEnd lineSegment #

Wrapped (AroundEnd a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Associated Types

type Unwrapped (AroundEnd a) 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Unwrapped (AroundEnd a) = a
AroundEnd a ~ t => Rewrapped (AroundEnd a) t Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (AroundEnd a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (AroundEnd a) = D1 ('MetaData "AroundEnd" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'True) (C1 ('MetaCons "AroundEnd" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type Unwrapped (AroundEnd a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Unwrapped (AroundEnd a) = a

data AroundStart a Source #

Assumes that two segments have the same start point

Instances

Instances details
Functor AroundStart Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

fmap :: (a -> b) -> AroundStart a -> AroundStart b #

(<$) :: a -> AroundStart b -> AroundStart a #

NFData a => NFData (AroundStart a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

rnf :: AroundStart a -> () #

Generic (AroundStart a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Associated Types

type Rep (AroundStart a) 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (AroundStart a) = D1 ('MetaData "AroundStart" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'True) (C1 ('MetaCons "AroundStart" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

Methods

from :: AroundStart a -> Rep (AroundStart a) x #

to :: Rep (AroundStart a) x -> AroundStart a #

Read a => Read (AroundStart a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Show a => Show (AroundStart a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

(Point_ point 2 r, Eq r, HasEnd lineSegment point) => Eq (AroundStart lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

(==) :: AroundStart lineSegment -> AroundStart lineSegment -> Bool #

(/=) :: AroundStart lineSegment -> AroundStart lineSegment -> Bool #

(LineSegment_ lineSegment point, Point_ point 2 r, Ord r, Num r) => Ord (AroundStart lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

compare :: AroundStart lineSegment -> AroundStart lineSegment -> Ordering #

(<) :: AroundStart lineSegment -> AroundStart lineSegment -> Bool #

(<=) :: AroundStart lineSegment -> AroundStart lineSegment -> Bool #

(>) :: AroundStart lineSegment -> AroundStart lineSegment -> Bool #

(>=) :: AroundStart lineSegment -> AroundStart lineSegment -> Bool #

max :: AroundStart lineSegment -> AroundStart lineSegment -> AroundStart lineSegment #

min :: AroundStart lineSegment -> AroundStart lineSegment -> AroundStart lineSegment #

Wrapped (AroundStart a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Associated Types

type Unwrapped (AroundStart a) 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Unwrapped (AroundStart a) = a
AroundStart a ~ t => Rewrapped (AroundStart a) t Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (AroundStart a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (AroundStart a) = D1 ('MetaData "AroundStart" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'True) (C1 ('MetaCons "AroundStart" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type Unwrapped (AroundStart a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Unwrapped (AroundStart a) = a

data AroundIntersection a Source #

Assumes that two segments intersect in a single point.

Instances

Instances details
Functor AroundIntersection Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

NFData a => NFData (AroundIntersection a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

rnf :: AroundIntersection a -> () #

Generic (AroundIntersection a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Associated Types

type Rep (AroundIntersection a) 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (AroundIntersection a) = D1 ('MetaData "AroundIntersection" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'True) (C1 ('MetaCons "AroundIntersection" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
Read a => Read (AroundIntersection a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Show a => Show (AroundIntersection a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Eq a => Eq (AroundIntersection a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

(LineSegment_ lineSegment point, Point_ point 2 r, Ord r, Fractional r, Eq lineSegment, IsIntersectableWith lineSegment lineSegment, Intersection lineSegment lineSegment ~ Maybe (LineSegmentLineSegmentIntersection lineSegment)) => Ord (AroundIntersection lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

compare :: AroundIntersection lineSegment -> AroundIntersection lineSegment -> Ordering #

(<) :: AroundIntersection lineSegment -> AroundIntersection lineSegment -> Bool #

(<=) :: AroundIntersection lineSegment -> AroundIntersection lineSegment -> Bool #

(>) :: AroundIntersection lineSegment -> AroundIntersection lineSegment -> Bool #

(>=) :: AroundIntersection lineSegment -> AroundIntersection lineSegment -> Bool #

max :: AroundIntersection lineSegment -> AroundIntersection lineSegment -> AroundIntersection lineSegment #

min :: AroundIntersection lineSegment -> AroundIntersection lineSegment -> AroundIntersection lineSegment #

Wrapped (AroundIntersection a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Associated Types

type Unwrapped (AroundIntersection a) 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

AroundIntersection a ~ t => Rewrapped (AroundIntersection a) t Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (AroundIntersection a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (AroundIntersection a) = D1 ('MetaData "AroundIntersection" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'True) (C1 ('MetaCons "AroundIntersection" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type Unwrapped (AroundIntersection a) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

isInteriorIntersection :: Associated lineSegment -> Bool Source #

Reports whether this associated has any interior intersections

\(O(1)\)

data IntersectionPoint point lineSegment Source #

An intersection point together with all segments intersecting at this point.

Instances

Instances details
(NFData point, NFData lineSegment) => NFData (IntersectionPoint point lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

rnf :: IntersectionPoint point lineSegment -> () #

Generic (IntersectionPoint point lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Associated Types

type Rep (IntersectionPoint point lineSegment) 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (IntersectionPoint point lineSegment) = D1 ('MetaData "IntersectionPoint" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'False) (C1 ('MetaCons "IntersectionPoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "_intersectionPoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 point) :*: S1 ('MetaSel ('Just "_associatedSegs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Associated lineSegment))))

Methods

from :: IntersectionPoint point lineSegment -> Rep (IntersectionPoint point lineSegment) x #

to :: Rep (IntersectionPoint point lineSegment) x -> IntersectionPoint point lineSegment #

(Read lineSegment, Read point, OrdArounds lineSegment) => Read (IntersectionPoint point lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

readsPrec :: Int -> ReadS (IntersectionPoint point lineSegment) #

readList :: ReadS [IntersectionPoint point lineSegment] #

readPrec :: ReadPrec (IntersectionPoint point lineSegment) #

readListPrec :: ReadPrec [IntersectionPoint point lineSegment] #

(Show point, Show lineSegment) => Show (IntersectionPoint point lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

showsPrec :: Int -> IntersectionPoint point lineSegment -> ShowS #

show :: IntersectionPoint point lineSegment -> String #

showList :: [IntersectionPoint point lineSegment] -> ShowS #

(Eq (AroundStart lineSegment), Eq (AroundIntersection lineSegment), Eq (AroundEnd lineSegment), Eq point) => Eq (IntersectionPoint point lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

Methods

(==) :: IntersectionPoint point lineSegment -> IntersectionPoint point lineSegment -> Bool #

(/=) :: IntersectionPoint point lineSegment -> IntersectionPoint point lineSegment -> Bool #

type Rep (IntersectionPoint point lineSegment) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection.Types

type Rep (IntersectionPoint point lineSegment) = D1 ('MetaData "IntersectionPoint" "HGeometry.LineSegment.Intersection.Types" "hgeometry-1.0.0.0-inplace" 'False) (C1 ('MetaCons "IntersectionPoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "_intersectionPoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 point) :*: S1 ('MetaSel ('Just "_associatedSegs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Associated lineSegment))))

intersectionPointOf :: (LineSegment_ lineSegment point, Point_ point 2 r, Ord r, Fractional r, IntersectConstraints lineSegment) => lineSegment -> lineSegment -> Maybe (IntersectionPoint (Point 2 r) lineSegment) Source #

Given two segments, compute an IntersectionPoint representing their intersection (if such an intersection exists).

intersectionPoint :: forall point lineSegment point' f. Functor f => (point -> f point') -> IntersectionPoint point lineSegment -> f (IntersectionPoint point' lineSegment) Source #

Lens to access the intersectionp oint

associatedSegs :: forall point lineSegment lineSegment' f. Functor f => (Associated lineSegment -> f (Associated lineSegment')) -> IntersectionPoint point lineSegment -> f (IntersectionPoint point lineSegment') Source #

Lens to access the associated segments

type IntersectConstraints lineSegment = (OrdArounds lineSegment, IsIntersectableWith lineSegment lineSegment, Intersection lineSegment lineSegment ~ Maybe (LineSegmentLineSegmentIntersection lineSegment)) Source #

Shorthand for the more-or-less standard constraints that we need on LineSegments

type OrdArounds lineSegment = (Ord (AroundStart lineSegment), Ord (AroundIntersection lineSegment), Ord (AroundEnd lineSegment)) Source #