{-# LANGUAGE DefaultSignatures #-}
module HGeometry.Polygon.Simple.InPolygon
( HasInPolygon(..)
, inSimplePolygon
, containedIn
) where
import Control.Lens
import HGeometry.Boundary
import HGeometry.Intersection
import HGeometry.Interval
import HGeometry.LineSegment
import HGeometry.Point
import HGeometry.Polygon.Class
import HGeometry.Polygon.Simple.Class
import HGeometry.Properties
class HasInPolygon polygon point r | polygon -> point, point -> r where
inPolygon :: ( Num r, Ord r, Point_ queryPoint 2 r)
=> queryPoint -> polygon -> PointLocationResultWith (VertexIx polygon)
default inPolygon :: ( Num r, Ord r, Point_ point 2 r, Point_ queryPoint 2 r
, SimplePolygon_ polygon point r
)
=> queryPoint -> polygon
-> PointLocationResultWith (VertexIx polygon)
inPolygon = queryPoint -> polygon -> PointLocationResultWith (VertexIx polygon)
forall queryPoint simplePolygon point r.
(Num r, Ord r, Point_ point 2 r, Point_ queryPoint 2 r,
SimplePolygon_ simplePolygon point r) =>
queryPoint
-> simplePolygon
-> PointLocationResultWith (VertexIx simplePolygon)
inSimplePolygon
data AboveCount seg = OnEdge !seg
| NumStrictlyAbove {-# UNPACK #-} !Int
deriving (Int -> AboveCount seg -> ShowS
[AboveCount seg] -> ShowS
AboveCount seg -> String
(Int -> AboveCount seg -> ShowS)
-> (AboveCount seg -> String)
-> ([AboveCount seg] -> ShowS)
-> Show (AboveCount seg)
forall seg. Show seg => Int -> AboveCount seg -> ShowS
forall seg. Show seg => [AboveCount seg] -> ShowS
forall seg. Show seg => AboveCount seg -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall seg. Show seg => Int -> AboveCount seg -> ShowS
showsPrec :: Int -> AboveCount seg -> ShowS
$cshow :: forall seg. Show seg => AboveCount seg -> String
show :: AboveCount seg -> String
$cshowList :: forall seg. Show seg => [AboveCount seg] -> ShowS
showList :: [AboveCount seg] -> ShowS
Show,AboveCount seg -> AboveCount seg -> Bool
(AboveCount seg -> AboveCount seg -> Bool)
-> (AboveCount seg -> AboveCount seg -> Bool)
-> Eq (AboveCount seg)
forall seg. Eq seg => AboveCount seg -> AboveCount seg -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall seg. Eq seg => AboveCount seg -> AboveCount seg -> Bool
== :: AboveCount seg -> AboveCount seg -> Bool
$c/= :: forall seg. Eq seg => AboveCount seg -> AboveCount seg -> Bool
/= :: AboveCount seg -> AboveCount seg -> Bool
Eq)
instance Semigroup (AboveCount seg) where
l :: AboveCount seg
l@(OnEdge seg
_) <> :: AboveCount seg -> AboveCount seg -> AboveCount seg
<> AboveCount seg
_ = AboveCount seg
l
AboveCount seg
_ <> r :: AboveCount seg
r@(OnEdge seg
_) = AboveCount seg
r
(NumStrictlyAbove Int
l) <> (NumStrictlyAbove Int
r) = Int -> AboveCount seg
forall seg. Int -> AboveCount seg
NumStrictlyAbove (Int
lInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
r)
instance Monoid (AboveCount seg) where
mempty :: AboveCount seg
mempty = Int -> AboveCount seg
forall seg. Int -> AboveCount seg
NumStrictlyAbove Int
0
inSimplePolygon :: forall queryPoint simplePolygon point r.
( Num r, Ord r, Point_ point 2 r, Point_ queryPoint 2 r
, SimplePolygon_ simplePolygon point r
)
=> queryPoint -> simplePolygon
-> PointLocationResultWith (VertexIx simplePolygon)
queryPoint
q inSimplePolygon :: forall queryPoint simplePolygon point r.
(Num r, Ord r, Point_ point 2 r, Point_ queryPoint 2 r,
SimplePolygon_ simplePolygon point r) =>
queryPoint
-> simplePolygon
-> PointLocationResultWith (VertexIx simplePolygon)
`inSimplePolygon` simplePolygon
pg = case IndexedGetting
(Int, (Int, Int))
(AboveCount Int)
simplePolygon
(point, (point, point))
-> ((Int, (Int, Int)) -> (point, (point, point)) -> AboveCount Int)
-> simplePolygon
-> AboveCount Int
forall i m s a. IndexedGetting i m s a -> (i -> a -> m) -> s -> m
ifoldMapOf IndexedGetting
(Int, (Int, Int))
(AboveCount Int)
simplePolygon
(point, (point, point))
Indexed
(Int, (Int, Int))
(Vertex simplePolygon,
(Vertex simplePolygon, Vertex simplePolygon))
(Const
(AboveCount Int)
(Vertex simplePolygon,
(Vertex simplePolygon, Vertex simplePolygon)))
-> simplePolygon -> Const (AboveCount Int) simplePolygon
forall polygon.
(HasOuterBoundary polygon, VertexIx polygon ~ Int) =>
IndexedFold1
(VertexIx polygon, (VertexIx polygon, VertexIx polygon))
polygon
(Vertex polygon, (Vertex polygon, Vertex polygon))
IndexedFold1
(VertexIx simplePolygon,
(VertexIx simplePolygon, VertexIx simplePolygon))
simplePolygon
(Vertex simplePolygon,
(Vertex simplePolygon, Vertex simplePolygon))
outerBoundaryWithNeighbours (Int, (Int, Int)) -> (point, (point, point)) -> AboveCount Int
countAbove simplePolygon
pg of
OnEdge Int
s -> Int -> PointLocationResultWith Int
forall edge. edge -> PointLocationResultWith edge
OnBoundaryEdge Int
s
NumStrictlyAbove Int
m | Int -> Bool
forall a. Integral a => a -> Bool
odd Int
m -> PointLocationResultWith Int
PointLocationResultWith (VertexIx simplePolygon)
forall edge. PointLocationResultWith edge
StrictlyInside
| Bool
otherwise -> PointLocationResultWith Int
PointLocationResultWith (VertexIx simplePolygon)
forall edge. PointLocationResultWith edge
StrictlyOutside
where
countAbove :: (Int, (Int, Int)) -> (point, (point, point)) -> AboveCount Int
countAbove (Int
i,(Int, Int)
_) (point
u,(point
p,point
v)) = case (point
upoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
xCoord) r -> r -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` (queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
xCoord) of
Ordering
LT | (queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
xCoord) r -> r -> Bool
forall a. Ord a => a -> a -> Bool
< (point
vpoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
xCoord) -> Int -> point -> point -> AboveCount Int
belowLineSeg Int
i point
u point
v
| Bool
otherwise -> AboveCount Int
forall a. Monoid a => a
mempty
Ordering
GT | (queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
xCoord) r -> r -> Bool
forall a. Ord a => a -> a -> Bool
> (point
vpoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
xCoord) -> Int -> point -> point -> AboveCount Int
belowLineSeg Int
i point
v point
u
| Bool
otherwise -> AboveCount Int
forall a. Monoid a => a
mempty
Ordering
EQ -> case (point
upoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(2 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
yCoord) r -> r -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` (queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(2 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
yCoord) of
Ordering
EQ -> Int -> AboveCount Int
forall seg. seg -> AboveCount seg
OnEdge Int
i
Ordering
LT | (queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
xCoord) r -> r -> Bool
forall a. Eq a => a -> a -> Bool
== (point
vpoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
xCoord) Bool -> Bool -> Bool
&&
(queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(2 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
yCoord) r -> r -> Bool
forall a. Ord a => a -> a -> Bool
< (point
vpoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(2 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
yCoord) -> Int -> AboveCount Int
forall seg. seg -> AboveCount seg
OnEdge Int
i
| Bool
otherwise -> AboveCount Int
forall a. Monoid a => a
mempty
Ordering
GT -> case (queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
xCoord) r -> r -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` (point
vpoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
xCoord) of
Ordering
EQ | (queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(2 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
yCoord) r -> r -> Bool
forall a. Ord a => a -> a -> Bool
> (point
vpoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(2 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
yCoord) -> Int -> AboveCount Int
forall seg. seg -> AboveCount seg
OnEdge Int
i
| Bool
otherwise -> AboveCount Int
forall a. Monoid a => a
mempty
Ordering
LT | queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
xCoord r -> r -> Bool
forall a. Ord a => a -> a -> Bool
<= point
ppoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
xCoord -> AboveCount Int
forall a. Monoid a => a
mempty
| Bool
otherwise -> Int -> point -> point -> AboveCount Int
belowLineSeg Int
i point
u point
v
Ordering
GT | queryPoint
qqueryPoint -> Getting r queryPoint r -> r
forall s a. s -> Getting a s a -> a
^.Getting r queryPoint r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int queryPoint r
xCoord r -> r -> Bool
forall a. Ord a => a -> a -> Bool
>= point
ppoint -> Getting r point r -> r
forall s a. s -> Getting a s a -> a
^.Getting r point r
forall (d :: Nat) point r.
(1 <= d, Point_ point d r) =>
IndexedLens' Int point r
IndexedLens' Int point r
xCoord -> AboveCount Int
forall a. Monoid a => a
mempty
| Bool
otherwise -> Int -> point -> point -> AboveCount Int
belowLineSeg Int
i point
v point
u
belowLineSeg :: Int -> point -> point -> AboveCount Int
belowLineSeg Int
i point
l point
r = case point -> queryPoint -> point -> CCW
forall point r point' point''.
(Point_ point 2 r, Point_ point' 2 r, Point_ point'' 2 r, Num r,
Ord r) =>
point -> point' -> point'' -> CCW
ccw point
l queryPoint
q point
r of
CCW
CW -> AboveCount Int
forall a. Monoid a => a
mempty
CCW
CoLinear -> Int -> AboveCount Int
forall seg. seg -> AboveCount seg
OnEdge Int
i
CCW
CCW -> Int -> AboveCount Int
forall seg. Int -> AboveCount seg
NumStrictlyAbove Int
1
containedIn :: ( ClosedLineSegment_ lineSegment point
, SimplePolygon_ simplePolygon vertex r
, Intersection (ClosedLineSegment vertex) lineSegment
~ Maybe (LineSegmentLineSegmentIntersection lineSegment')
, IsIntersectableWith (ClosedLineSegment vertex) lineSegment
, NumType lineSegment' ~ r
, HasInPolygon simplePolygon vertex r
, Point_ point 2 r, Point_ vertex 2 r, Ord r, Fractional r
) => lineSegment -> simplePolygon -> Bool
containedIn :: forall lineSegment point simplePolygon vertex r lineSegment'.
(ClosedLineSegment_ lineSegment point,
SimplePolygon_ simplePolygon vertex r,
Intersection (ClosedLineSegment vertex) lineSegment
~ Maybe (LineSegmentLineSegmentIntersection lineSegment'),
IsIntersectableWith (ClosedLineSegment vertex) lineSegment,
NumType lineSegment' ~ r, HasInPolygon simplePolygon vertex r,
Point_ point 2 r, Point_ vertex 2 r, Ord r, Fractional r) =>
lineSegment -> simplePolygon -> Bool
containedIn lineSegment
seg simplePolygon
poly = case (lineSegment
seglineSegment -> Getting point lineSegment point -> point
forall s a. s -> Getting a s a -> a
^.Getting point lineSegment point
forall seg p. HasStart seg p => Lens' seg p
Lens' lineSegment point
start) point
-> simplePolygon
-> PointLocationResultWith (VertexIx simplePolygon)
forall queryPoint.
(Num r, Ord r, Point_ queryPoint 2 r) =>
queryPoint
-> simplePolygon
-> PointLocationResultWith (VertexIx simplePolygon)
forall polygon point r queryPoint.
(HasInPolygon polygon point r, Num r, Ord r,
Point_ queryPoint 2 r) =>
queryPoint -> polygon -> PointLocationResultWith (VertexIx polygon)
`inPolygon` simplePolygon
poly of
PointLocationResultWith (VertexIx simplePolygon)
StrictlyInside -> case (lineSegment
seglineSegment -> Getting point lineSegment point -> point
forall s a. s -> Getting a s a -> a
^.Getting point lineSegment point
forall seg p. HasEnd seg p => Lens' seg p
Lens' lineSegment point
end) point
-> simplePolygon
-> PointLocationResultWith (VertexIx simplePolygon)
forall queryPoint.
(Num r, Ord r, Point_ queryPoint 2 r) =>
queryPoint
-> simplePolygon
-> PointLocationResultWith (VertexIx simplePolygon)
forall polygon point r queryPoint.
(HasInPolygon polygon point r, Num r, Ord r,
Point_ queryPoint 2 r) =>
queryPoint -> polygon -> PointLocationResultWith (VertexIx polygon)
`inPolygon` simplePolygon
poly of
PointLocationResultWith (VertexIx simplePolygon)
StrictlyInside -> Bool -> Bool
not Bool
properIntersection
PointLocationResultWith (VertexIx simplePolygon)
StrictlyOutside -> Bool
False
OnBoundaryEdge VertexIx simplePolygon
vj -> Bool -> Bool
not Bool
properIntersection Bool -> Bool -> Bool
&& Int -> point -> Bool
inCone' Int
VertexIx simplePolygon
vj (lineSegment
seglineSegment -> Getting point lineSegment point -> point
forall s a. s -> Getting a s a -> a
^.Getting point lineSegment point
forall seg p. HasStart seg p => Lens' seg p
Lens' lineSegment point
start)
PointLocationResultWith (VertexIx simplePolygon)
StrictlyOutside -> Bool
False
OnBoundaryEdge VertexIx simplePolygon
vi -> case (lineSegment
seglineSegment -> Getting point lineSegment point -> point
forall s a. s -> Getting a s a -> a
^.Getting point lineSegment point
forall seg p. HasEnd seg p => Lens' seg p
Lens' lineSegment point
end) point
-> simplePolygon
-> PointLocationResultWith (VertexIx simplePolygon)
forall queryPoint.
(Num r, Ord r, Point_ queryPoint 2 r) =>
queryPoint
-> simplePolygon
-> PointLocationResultWith (VertexIx simplePolygon)
forall polygon point r queryPoint.
(HasInPolygon polygon point r, Num r, Ord r,
Point_ queryPoint 2 r) =>
queryPoint -> polygon -> PointLocationResultWith (VertexIx polygon)
`inPolygon` simplePolygon
poly of
PointLocationResultWith (VertexIx simplePolygon)
StrictlyInside -> Bool -> Bool
not Bool
properIntersection
PointLocationResultWith (VertexIx simplePolygon)
StrictlyOutside -> Bool
False
OnBoundaryEdge VertexIx simplePolygon
vj -> Bool -> Bool
not Bool
properIntersection
Bool -> Bool -> Bool
&& Int -> point -> Bool
inCone' Int
VertexIx simplePolygon
vi (lineSegment
seglineSegment -> Getting point lineSegment point -> point
forall s a. s -> Getting a s a -> a
^.Getting point lineSegment point
forall seg p. HasEnd seg p => Lens' seg p
Lens' lineSegment point
end)
Bool -> Bool -> Bool
&& Int -> point -> Bool
inCone' Int
VertexIx simplePolygon
vj (lineSegment
seglineSegment -> Getting point lineSegment point -> point
forall s a. s -> Getting a s a -> a
^.Getting point lineSegment point
forall seg p. HasStart seg p => Lens' seg p
Lens' lineSegment point
start)
where
properIntersection :: Bool
properIntersection = Getting Any simplePolygon (ClosedLineSegment vertex)
-> (ClosedLineSegment vertex -> Bool) -> simplePolygon -> Bool
forall s a. Getting Any s a -> (a -> Bool) -> s -> Bool
anyOf Getting Any simplePolygon (ClosedLineSegment vertex)
forall polygon point r.
(HasOuterBoundary polygon, Vertex polygon ~ point,
Point_ point 2 r) =>
IndexedFold1
(VertexIx polygon, VertexIx polygon)
polygon
(ClosedLineSegment point)
IndexedFold1
(VertexIx simplePolygon, VertexIx simplePolygon)
simplePolygon
(ClosedLineSegment vertex)
outerBoundaryEdgeSegments (\ClosedLineSegment vertex
edgeSeg ->
case ClosedLineSegment vertex
edgeSeg ClosedLineSegment vertex
-> lineSegment
-> Intersection (ClosedLineSegment vertex) lineSegment
forall g h. IsIntersectableWith g h => g -> h -> Intersection g h
`intersect` lineSegment
seg of
Just (LineSegment_x_LineSegment_Point Point 2 (NumType lineSegment')
p) -> Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$
Point 2 r
Point 2 (NumType lineSegment')
p Point 2 r -> Point 2 r -> Bool
forall a. Eq a => a -> a -> Bool
/= (ClosedLineSegment vertex
edgeSegClosedLineSegment vertex
-> Getting (Point 2 r) (ClosedLineSegment vertex) (Point 2 r)
-> Point 2 r
forall s a. s -> Getting a s a -> a
^.(vertex -> Const (Point 2 r) vertex)
-> ClosedLineSegment vertex
-> Const (Point 2 r) (ClosedLineSegment vertex)
forall seg p. HasStart seg p => Lens' seg p
Lens' (ClosedLineSegment vertex) vertex
start((vertex -> Const (Point 2 r) vertex)
-> ClosedLineSegment vertex
-> Const (Point 2 r) (ClosedLineSegment vertex))
-> ((Point 2 r -> Const (Point 2 r) (Point 2 r))
-> vertex -> Const (Point 2 r) vertex)
-> Getting (Point 2 r) (ClosedLineSegment vertex) (Point 2 r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Point 2 r -> Const (Point 2 r) (Point 2 r))
-> vertex -> Const (Point 2 r) vertex
forall point (d :: Nat) r.
Point_ point d r =>
Lens' point (Point d r)
Lens' vertex (Point 2 r)
asPoint) Bool -> Bool -> Bool
|| Point 2 r
Point 2 (NumType lineSegment')
p Point 2 r -> Point 2 r -> Bool
forall a. Eq a => a -> a -> Bool
/= (ClosedLineSegment vertex
edgeSegClosedLineSegment vertex
-> Getting (Point 2 r) (ClosedLineSegment vertex) (Point 2 r)
-> Point 2 r
forall s a. s -> Getting a s a -> a
^.(vertex -> Const (Point 2 r) vertex)
-> ClosedLineSegment vertex
-> Const (Point 2 r) (ClosedLineSegment vertex)
forall seg p. HasEnd seg p => Lens' seg p
Lens' (ClosedLineSegment vertex) vertex
end((vertex -> Const (Point 2 r) vertex)
-> ClosedLineSegment vertex
-> Const (Point 2 r) (ClosedLineSegment vertex))
-> ((Point 2 r -> Const (Point 2 r) (Point 2 r))
-> vertex -> Const (Point 2 r) vertex)
-> Getting (Point 2 r) (ClosedLineSegment vertex) (Point 2 r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Point 2 r -> Const (Point 2 r) (Point 2 r))
-> vertex -> Const (Point 2 r) vertex
forall point (d :: Nat) r.
Point_ point d r =>
Lens' point (Point d r)
Lens' vertex (Point 2 r)
asPoint)
Just LineSegmentLineSegmentIntersection lineSegment'
_ -> Bool
False
Maybe (LineSegmentLineSegmentIntersection lineSegment')
Intersection (ClosedLineSegment vertex) lineSegment
Nothing -> Bool
False
) simplePolygon
poly
inCone' :: Int -> point -> Bool
inCone' Int
i point
q = let a :: vertex
a = simplePolygon
polysimplePolygon
-> Getting (Endo vertex) simplePolygon vertex -> vertex
forall s a. HasCallStack => s -> Getting (Endo a) s a -> a
^?!VertexIx simplePolygon
-> IndexedTraversal'
(VertexIx simplePolygon) simplePolygon (Vertex simplePolygon)
forall graph.
HasVertices' graph =>
VertexIx graph
-> IndexedTraversal' (VertexIx graph) graph (Vertex graph)
vertexAt Int
VertexIx simplePolygon
i
p :: vertex
p = simplePolygon
polysimplePolygon
-> Getting (Endo vertex) simplePolygon vertex -> vertex
forall s a. HasCallStack => s -> Getting (Endo a) s a -> a
^?!VertexIx simplePolygon
-> IndexedTraversal'
(VertexIx simplePolygon) simplePolygon (Vertex simplePolygon)
forall graph.
HasVertices' graph =>
VertexIx graph
-> IndexedTraversal' (VertexIx graph) graph (Vertex graph)
vertexAt (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)
n :: vertex
n = simplePolygon
polysimplePolygon
-> Getting (Endo vertex) simplePolygon vertex -> vertex
forall s a. HasCallStack => s -> Getting (Endo a) s a -> a
^?!VertexIx simplePolygon
-> IndexedTraversal'
(VertexIx simplePolygon) simplePolygon (Vertex simplePolygon)
forall graph.
HasVertices' graph =>
VertexIx graph
-> IndexedTraversal' (VertexIx graph) graph (Vertex graph)
vertexAt (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
in point -> vertex -> vertex -> vertex -> Bool
forall queryPoint r apex point point'.
(Point_ queryPoint 2 r, Point_ apex 2 r, Point_ point 2 r,
Point_ point' 2 r, Ord r, Num r) =>
queryPoint -> apex -> point -> point' -> Bool
inCone point
q vertex
a vertex
p vertex
n
inCone :: ( Point_ queryPoint 2 r, Point_ apex 2 r, Point_ point 2 r, Point_ point' 2 r
, Ord r, Num r
) =>
queryPoint -> apex -> point -> point' -> Bool
inCone :: forall queryPoint r apex point point'.
(Point_ queryPoint 2 r, Point_ apex 2 r, Point_ point 2 r,
Point_ point' 2 r, Ord r, Num r) =>
queryPoint -> apex -> point -> point' -> Bool
inCone queryPoint
q apex
a point
l point'
r = case Vector 2 r -> apex -> Point 2 r -> Point 2 r -> Ordering
forall center r point.
(Point_ center 2 r, Point_ point 2 r, Ord r, Num r) =>
Vector 2 r -> center -> point -> point -> Ordering
cwCmpAroundWith ((point
lpoint -> Getting (Point 2 r) point (Point 2 r) -> Point 2 r
forall s a. s -> Getting a s a -> a
^.Getting (Point 2 r) point (Point 2 r)
forall point (d :: Nat) r.
Point_ point d r =>
Lens' point (Point d r)
Lens' point (Point 2 r)
asPoint) Point 2 r -> Point 2 r -> Vector 2 r
forall point (d :: Nat) r.
(Affine_ point d r, Num r) =>
point -> point -> Vector d r
.-. (apex
aapex -> Getting (Point 2 r) apex (Point 2 r) -> Point 2 r
forall s a. s -> Getting a s a -> a
^.Getting (Point 2 r) apex (Point 2 r)
forall point (d :: Nat) r.
Point_ point d r =>
Lens' point (Point d r)
Lens' apex (Point 2 r)
asPoint)) apex
a (queryPoint
qqueryPoint
-> Getting (Point 2 r) queryPoint (Point 2 r) -> Point 2 r
forall s a. s -> Getting a s a -> a
^.Getting (Point 2 r) queryPoint (Point 2 r)
forall point (d :: Nat) r.
Point_ point d r =>
Lens' point (Point d r)
Lens' queryPoint (Point 2 r)
asPoint) (point'
rpoint' -> Getting (Point 2 r) point' (Point 2 r) -> Point 2 r
forall s a. s -> Getting a s a -> a
^.Getting (Point 2 r) point' (Point 2 r)
forall point (d :: Nat) r.
Point_ point d r =>
Lens' point (Point d r)
Lens' point' (Point 2 r)
asPoint) of
Ordering
GT -> Bool
False
Ordering
_ -> Bool
True