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

HGeometry.Polygon.Convex

Description

A type for representing Convex polygons, and some basic functions on Convex polygons.

Synopsis

Documentation

class SimplePolygon_ convexPolygon point r => ConvexPolygon_ convexPolygon point r Source #

Class modelling convex polygons.

Instances

Instances details
(ConvexPolygon_ convexPolygon point r, Default extra) => ConvexPolygon_ (convexPolygon :+ extra) point r Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Class

(SimplePolygon_ (SimplePolygonF f point) point r, Point_ point 2 r) => ConvexPolygon_ (ConvexPolygonF f point) point r Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type ConvexPolygon = ConvexPolygonF (Cyclic NonEmptyVector) Source #

By default we use a cyclic non-empty vector to represent convex polygons.

data ConvexPolygonF (f :: k -> Type) (point :: k) Source #

Convex polygons

Instances

Instances details
(Point_ vertex 2 r, Num r, Ord r, VertexContainer f vertex, HyperPlane_ line 2 r) => HasIntersectionWith (HalfSpaceF line) (PossiblyDegenerateSimplePolygon vertex (ConvexPolygonF f vertex)) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

(Point_ vertex 2 r, Fractional r, Ord r, VertexContainer f vertex, VertexContainer f (OriginalOrExtra vertex (Point 2 r)), HyperPlane_ line 2 r, IsIntersectableWith (HalfSpaceF line) (ConvexPolygonF f vertex), IsIntersectableWith (LinePV 2 r) line, Intersection (LinePV 2 r) line ~ Maybe (LineLineIntersectionG r line')) => IsIntersectableWith (HalfSpaceF line) (PossiblyDegenerateSimplePolygon vertex (ConvexPolygonF f vertex)) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

(Point_ point 2 r, Point_ point' 2 r, Num r, Ord r, VertexContainer f point, VertexContainer f (Point 2 r)) => HasIntersectionWith (Rectangle point') (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersects :: Rectangle point' -> ConvexPolygonF f point -> Bool Source #

(Point_ point 2 r, Num r, Ord r, VertexContainer f point, HyperPlane_ line 2 r) => HasIntersectionWith (HalfSpaceF line) (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersects :: HalfSpaceF line -> ConvexPolygonF f point -> Bool Source #

(Point_ point 2 r, Point_ point' 2 r, Num r, Ord r, VertexContainer f point, VertexContainer f (Point 2 r)) => HasIntersectionWith (Triangle point') (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersects :: Triangle point' -> ConvexPolygonF f point -> Bool Source #

(Point_ vertex 2 r, Point_ corner 2 r, Fractional r, Ord r, VertexContainer f vertex, VertexContainer f (Point 2 r), VertexContainer f (OriginalOrCanonical vertex), VertexContainer f (OriginalOrExtra (OriginalOrCanonical vertex) (Point 2 r)), HasFromFoldable1 f) => IsIntersectableWith (Rectangle corner) (ConvexPolygonF f vertex) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersect :: Rectangle corner -> ConvexPolygonF f vertex -> Intersection (Rectangle corner) (ConvexPolygonF f vertex) Source #

(Point_ vertex 2 r, Fractional r, Ord r, VertexContainer f vertex, VertexContainer f (OriginalOrExtra vertex (Point 2 r)), HasFromFoldable1 f) => IsIntersectableWith (HalfSpaceF (LinePV 2 r)) (ConvexPolygonF f vertex) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersect :: HalfSpaceF (LinePV 2 r) -> ConvexPolygonF f vertex -> Intersection (HalfSpaceF (LinePV 2 r)) (ConvexPolygonF f vertex) Source #

(Point_ vertex 2 r, Point_ corner 2 r, Fractional r, Ord r, VertexContainer f vertex, VertexContainer f (Point 2 r), VertexContainer f (OriginalOrCanonical vertex), VertexContainer f (OriginalOrExtra (OriginalOrCanonical vertex) (Point 2 r)), HasFromFoldable1 f) => IsIntersectableWith (Triangle corner) (ConvexPolygonF f vertex) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersect :: Triangle corner -> ConvexPolygonF f vertex -> Intersection (Triangle corner) (ConvexPolygonF f vertex) Source #

Foldable1 f => Foldable1 (ConvexPolygonF f) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

fold1 :: Semigroup m => ConvexPolygonF f m -> m Source #

foldMap1 :: Semigroup m => (a -> m) -> ConvexPolygonF f a -> m Source #

foldMap1' :: Semigroup m => (a -> m) -> ConvexPolygonF f a -> m Source #

toNonEmpty :: ConvexPolygonF f a -> NonEmpty a Source #

maximum :: Ord a => ConvexPolygonF f a -> a Source #

minimum :: Ord a => ConvexPolygonF f a -> a Source #

head :: ConvexPolygonF f a -> a Source #

last :: ConvexPolygonF f a -> a Source #

foldrMap1 :: (a -> b) -> (a -> b -> b) -> ConvexPolygonF f a -> b Source #

foldlMap1' :: (a -> b) -> (b -> a -> b) -> ConvexPolygonF f a -> b Source #

foldlMap1 :: (a -> b) -> (b -> a -> b) -> ConvexPolygonF f a -> b Source #

foldrMap1' :: (a -> b) -> (a -> b -> b) -> ConvexPolygonF f a -> b Source #

Eq1 f => Eq1 (ConvexPolygonF f) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

liftEq :: (a -> b -> Bool) -> ConvexPolygonF f a -> ConvexPolygonF f b -> Bool Source #

Functor f => Functor (ConvexPolygonF f) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

fmap :: (a -> b) -> ConvexPolygonF f a -> ConvexPolygonF f b Source #

(<$) :: a -> ConvexPolygonF f b -> ConvexPolygonF f a Source #

Foldable f => Foldable (ConvexPolygonF f) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

fold :: Monoid m => ConvexPolygonF f m -> m Source #

foldMap :: Monoid m => (a -> m) -> ConvexPolygonF f a -> m Source #

foldMap' :: Monoid m => (a -> m) -> ConvexPolygonF f a -> m Source #

foldr :: (a -> b -> b) -> b -> ConvexPolygonF f a -> b Source #

foldr' :: (a -> b -> b) -> b -> ConvexPolygonF f a -> b Source #

foldl :: (b -> a -> b) -> b -> ConvexPolygonF f a -> b Source #

foldl' :: (b -> a -> b) -> b -> ConvexPolygonF f a -> b Source #

foldr1 :: (a -> a -> a) -> ConvexPolygonF f a -> a Source #

foldl1 :: (a -> a -> a) -> ConvexPolygonF f a -> a Source #

toList :: ConvexPolygonF f a -> [a] Source #

null :: ConvexPolygonF f a -> Bool Source #

length :: ConvexPolygonF f a -> Int Source #

elem :: Eq a => a -> ConvexPolygonF f a -> Bool Source #

maximum :: Ord a => ConvexPolygonF f a -> a Source #

minimum :: Ord a => ConvexPolygonF f a -> a Source #

sum :: Num a => ConvexPolygonF f a -> a Source #

product :: Num a => ConvexPolygonF f a -> a Source #

Traversable f => Traversable (ConvexPolygonF f) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

traverse :: Applicative f0 => (a -> f0 b) -> ConvexPolygonF f a -> f0 (ConvexPolygonF f b) Source #

sequenceA :: Applicative f0 => ConvexPolygonF f (f0 a) -> f0 (ConvexPolygonF f a) Source #

mapM :: Monad m => (a -> m b) -> ConvexPolygonF f a -> m (ConvexPolygonF f b) Source #

sequence :: Monad m => ConvexPolygonF f (m a) -> m (ConvexPolygonF f a) Source #

Traversable1 f => Traversable1 (ConvexPolygonF f) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

traverse1 :: Apply f0 => (a -> f0 b) -> ConvexPolygonF f a -> f0 (ConvexPolygonF f b) Source #

sequence1 :: Apply f0 => ConvexPolygonF f (f0 b) -> f0 (ConvexPolygonF f b) Source #

(IsIntersectableWith (HalfSpaceF line) (ConvexPolygonF f vertex), HasIntersectionWith (HalfSpaceF line :+ extra) (ConvexPolygonF f vertex :+ extra')) => IsIntersectableWith (HalfSpaceF line :+ extra) (ConvexPolygonF f vertex :+ extra') Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersect :: (HalfSpaceF line :+ extra) -> (ConvexPolygonF f vertex :+ extra') -> Intersection (HalfSpaceF line :+ extra) (ConvexPolygonF f vertex :+ extra') Source #

(Fractional r, Ord r, ConvexPolygon_ (ConvexPolygonF nonEmpty vertex) vertex r) => IsIntersectableWith (LinePV 2 r) (PossiblyDegenerateSimplePolygon vertex (ConvexPolygonF nonEmpty vertex)) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersect :: LinePV 2 r -> PossiblyDegenerateSimplePolygon vertex (ConvexPolygonF nonEmpty vertex) -> Intersection (LinePV 2 r) (PossiblyDegenerateSimplePolygon vertex (ConvexPolygonF nonEmpty vertex)) Source #

(Num r, Ord r, ConvexPolygon_ (ConvexPolygonF nonEmpty vertex) vertex r) => HasIntersectionWith (LinePV 2 r) (ConvexPolygonF nonEmpty vertex) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersects :: LinePV 2 r -> ConvexPolygonF nonEmpty vertex -> Bool Source #

(HasInPolygon (ConvexPolygonF f point) point r, Num r, Ord r) => HasIntersectionWith (Point 2 r) (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersects :: Point 2 r -> ConvexPolygonF f point -> Bool Source #

(Fractional r, Ord r, ConvexPolygon_ (ConvexPolygonF nonEmpty vertex) vertex r) => IsIntersectableWith (LinePV 2 r) (ConvexPolygonF nonEmpty vertex) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersect :: LinePV 2 r -> ConvexPolygonF nonEmpty vertex -> Intersection (LinePV 2 r) (ConvexPolygonF nonEmpty vertex) Source #

(HasInPolygon (ConvexPolygonF f point) point r, Num r, Ord r) => IsIntersectableWith (Point 2 r) (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

intersect :: Point 2 r -> ConvexPolygonF f point -> Intersection (Point 2 r) (ConvexPolygonF f point) Source #

NFData (f point) => NFData (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

rnf :: ConvexPolygonF f point -> () Source #

(Read point, SimplePolygon_ (ConvexPolygonF f point) point r) => Read (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

(Show point, SimplePolygon_ (ConvexPolygonF f point) point r) => Show (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Eq (f point) => Eq (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

(==) :: ConvexPolygonF f point -> ConvexPolygonF f point -> Bool Source #

(/=) :: ConvexPolygonF f point -> ConvexPolygonF f point -> Bool Source #

(ShiftedEq (f point), ElemCyclic (f point) ~ point) => ShiftedEq (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Associated Types

type ElemCyclic (ConvexPolygonF f point) 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type ElemCyclic (ConvexPolygonF f point) = point

Methods

isShiftOf :: ConvexPolygonF f point -> ConvexPolygonF f point -> Bool Source #

(VertexContainer f point, Point_ point 2 r, Num r, HasFromFoldable1 f) => IsBoxable (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

boundingBox :: forall (d :: Nat) r0. (d ~ Dimension (ConvexPolygonF f point), r0 ~ NumType (ConvexPolygonF f point), Ord r0) => ConvexPolygonF f point -> Box (Point d r0) Source #

(VertexContainer f point, DefaultTransformByConstraints (ConvexPolygonF f point) 2 r, Point_ point 2 r) => IsTransformable (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

HasHoles (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Associated Types

type HoleIx (ConvexPolygonF f point) 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type HoleIx (ConvexPolygonF f point) = Void
type HoleF (ConvexPolygonF f point) 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

(HasOuterBoundary (SimplePolygonF f point), VertexIx (SimplePolygonF f point) ~ Int) => HasOuterBoundary (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

HasVertices' (SimplePolygonF f point) => HasVertices' (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Associated Types

type Vertex (ConvexPolygonF f point) 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Vertex (ConvexPolygonF f point) = Vertex (SimplePolygonF f point)
type VertexIx (ConvexPolygonF f point) 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type VertexIx (ConvexPolygonF f point) = VertexIx (SimplePolygonF f point)
(SimplePolygon_ (SimplePolygonF f point) point r, Point_ point 2 r) => Polygon_ (ConvexPolygonF f point) point r Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

(SimplePolygon_ (SimplePolygonF f point) point r, Point_ point 2 r) => ConvexPolygon_ (ConvexPolygonF f point) point r Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

(SimplePolygon_ (SimplePolygonF f point) point r, Point_ point 2 r) => SimplePolygon_ (ConvexPolygonF f point) point r Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Associated Types

type ConstructableSimplePolygon (ConvexPolygonF f point) point r 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type ConstructableSimplePolygon (ConvexPolygonF f point) point r = (VertexContainer f point, Ord r, Num r)

Methods

uncheckedFromCCWPoints :: Foldable1 f0 => f0 point -> ConvexPolygonF f point Source #

fromPoints :: (Foldable f0, ConstructableSimplePolygon (ConvexPolygonF f point) point r) => f0 point -> Maybe (ConvexPolygonF f point) Source #

centroid :: (Fractional r, ConstructablePoint_ point' 2 r) => ConvexPolygonF f point -> point' Source #

ConvexPolygon_ (ConvexPolygonF f point) point r => HasInPolygon (ConvexPolygonF f point) point r Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

inPolygon :: (Num r, Ord r, Point_ queryPoint 2 r) => queryPoint -> ConvexPolygonF f point -> PointLocationResultWith (VertexIx (ConvexPolygonF f point)) Source #

HasVertices (SimplePolygonF f point) (SimplePolygonF f point') => HasVertices (ConvexPolygonF f point) (ConvexPolygonF f point') Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

VertexContainer f point => HasPoints (ConvexPolygonF f point) (ConvexPolygonF f point') point point' Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

Methods

allPoints :: forall (d :: Nat) r r'. (Point_ point d r, Point_ point' d r', NumType (ConvexPolygonF f point) ~ r, NumType (ConvexPolygonF f point') ~ r', Dimension (ConvexPolygonF f point) ~ d, Dimension (ConvexPolygonF f point') ~ d) => Traversal1 (ConvexPolygonF f point) (ConvexPolygonF f point') point point' Source #

type Intersection (HalfSpaceF line) (PossiblyDegenerateSimplePolygon vertex (ConvexPolygonF f vertex)) Source #

Intersecting a halfplane witha possibly degenerate convex polygon gives us a possibly degenerate polygon again.

Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Intersection (Rectangle corner) (ConvexPolygonF f vertex) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Intersection (HalfSpaceF line) (ConvexPolygonF f point) Source #

A HalfPlane and a Convex polygon intersect in a single component, which is a possiblyDegenerate convex polygon.

Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Intersection (Triangle corner) (ConvexPolygonF f vertex) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Intersection (HalfSpaceF line :+ extra) (ConvexPolygonF f point :+ extra') Source #

If we drag along extra information in the halfplane polygon intersection we lose it

Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Intersection (HalfSpaceF line :+ extra) (ConvexPolygonF f point :+ extra') = Intersection (HalfSpaceF line) (ConvexPolygonF f point)
type Intersection (LinePV 2 r) (PossiblyDegenerateSimplePolygon vertex (ConvexPolygonF nonEmpty vertex)) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Intersection (LinePV 2 r) (ConvexPolygonF nonEmpty vertex) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Intersection (Point 2 r) (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Intersection (Point 2 r) (ConvexPolygonF f point) = Maybe (Point 2 r)
type ElemCyclic (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type ElemCyclic (ConvexPolygonF f point) = point
type HoleF (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type HoleIx (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type HoleIx (ConvexPolygonF f point) = Void
type Dimension (ConvexPolygonF f point) Source #

Polygons are per definition 2 dimensional

Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Dimension (ConvexPolygonF f point) = 2
type NumType (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type NumType (ConvexPolygonF f point) = NumType point
type Vertex (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type Vertex (ConvexPolygonF f point) = Vertex (SimplePolygonF f point)
type VertexIx (ConvexPolygonF f point) Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type VertexIx (ConvexPolygonF f point) = VertexIx (SimplePolygonF f point)
type ConstructableSimplePolygon (ConvexPolygonF f point) point r Source # 
Instance details

Defined in HGeometry.Polygon.Convex.Internal

type ConstructableSimplePolygon (ConvexPolygonF f point) point r = (VertexContainer f point, Ord r, Num r)

fromSimplePolygon :: forall r point (f :: Type -> Type). (Ord r, Num r, Point_ point 2 r, VertexContainer f point) => SimplePolygonF f point -> Maybe (ConvexPolygonF f point) Source #

Smart constructor to construct a strictly convex polygon from a simple polygon.

toSimplePolygon :: ConvexPolygonF f point -> SimplePolygonF f point Source #

Convert to a simple polygon, i.e. forget the polygon is convex.

_ConvexPolygon :: forall (f :: Type -> Type) point r. (Num r, Ord r, Point_ point 2 r, VertexContainer f point) => Prism' (SimplePolygonF f point) (ConvexPolygonF f point) Source #

Prism that can forget that the polygon is convex

isStrictlyConvex :: forall r point (f :: Type -> Type). (Ord r, Num r, Point_ point 2 r, VertexContainer f point) => SimplePolygonF f point -> Bool Source #

\( O(n) \) Check if a polygon is strictly convex.

isConvex :: forall r point (f :: Type -> Type). (Ord r, Num r, Point_ point 2 r, VertexContainer f point) => SimplePolygonF f point -> Bool Source #

\( O(n) \) Check if a polygon is convex.

verifyConvex :: forall r point (f :: Type -> Type). (Ord r, Num r, Point_ point 2 r, VertexContainer f point) => ConvexPolygonF f point -> Bool Source #

Verify that a convex polygon is strictly convex.

running time \( O(n) \)

maxInDirection :: (Num r, Ord r, ConvexPolygon_ convexPolygon point r) => Vector 2 r -> convexPolygon -> point Source #

Finds the extreme maximum point in the given direction. Based on http://geomalgorithms.com/a14-_extreme_pts.html

pre: The input polygon is strictly convex.

running time: \(O(\log n)\)

_UncheckedConvexPolygon :: forall {k1} {k2} (f1 :: k1 -> Type) (point :: k1) (f' :: k2 -> Type) (point' :: k2) p f2. (Profunctor p, Functor f2) => p (SimplePolygonF f1 point) (f2 (SimplePolygonF f' point')) -> p (ConvexPolygonF f1 point) (f2 (ConvexPolygonF f' point')) Source #

ConvexPolygons are isomorphic to SimplePolygons with the added constraint that all vertices are strictly convex.

Note that this is unchecked; i.e. one can turn an arbitrary simple polygon into a suposedly convex one.

findMaxWith :: ConvexPolygon_ convexPolygon point r => (point -> point -> Ordering) -> convexPolygon -> point Source #

Find the maximum vertex in a convex polygon using a binary search. \( O(\log n) \)