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

HGeometry.Interval.Class

Description

Intervals

Synopsis

Documentation

class (IntervalLike_ interval r, NumType interval ~ r) => Interval_ interval r | interval -> r Source #

A class for types representing Intervals

Instances

Instances details
Interval_ (HalfOpenInterval r) r Source # 
Instance details

Defined in HGeometry.Interval.HalfOpen

Interval_ interval r => Interval_ (interval :+ extra) r Source # 
Instance details

Defined in HGeometry.Interval.Class

(EndPoint_ (endPoint r), IxValue (endPoint r) ~ r) => Interval_ (Interval endPoint r) r Source # 
Instance details

Defined in HGeometry.Interval.Internal

pattern Interval_ :: Interval_ interval r => StartPointOf interval -> EndPointOf interval -> interval Source #

Pattern to match on intervals

class (HasStart interval point, HasStartPoint interval (StartPointOf interval), HasEnd interval point, HasEndPoint interval (EndPointOf interval), EndPoint_ (EndPointOf interval), IxValue (EndPointOf interval) ~ point, EndPoint_ (StartPointOf interval), IxValue (StartPointOf interval) ~ point) => IntervalLike_ interval point | interval -> point Source #

A class for types representing interval like objects

Instances

Instances details
IntervalLike_ (HalfOpenInterval r) r Source # 
Instance details

Defined in HGeometry.Interval.HalfOpen

(IxValue (endPoint point) ~ point, EndPoint_ (endPoint point)) => IntervalLike_ (LineSegment endPoint point) point Source # 
Instance details

Defined in HGeometry.LineSegment.Internal

IntervalLike_ interval point => IntervalLike_ (interval :+ extra) point Source # 
Instance details

Defined in HGeometry.Interval.Class

(EndPoint_ (endPoint r), IxValue (endPoint r) ~ r) => IntervalLike_ (Interval endPoint r) r Source # 
Instance details

Defined in HGeometry.Interval.Internal

class Interval_ interval point => ConstructableInterval_ interval point where Source #

A class for constructable intervals

Minimal complete definition

mkInterval

Methods

mkInterval :: StartPointOf interval -> EndPointOf interval -> interval Source #

Construct an interval given its start and end point.

pre: start < end

buildInterval :: StartPointOf interval -> EndPointOf interval -> interval Source #

Construct an interval given two points. This makes sure the start-point comes before the endpoint.

pre: it is possible to construct a valid, non-empty interval this way. so if either endpoint is open the endpoints should not coincide.

Instances

Instances details
ConstructableInterval_ (HalfOpenInterval r) r Source # 
Instance details

Defined in HGeometry.Interval.HalfOpen

(ConstructableInterval_ interval point, Default extra) => ConstructableInterval_ (interval :+ extra) point Source # 
Instance details

Defined in HGeometry.Interval.Class

Methods

mkInterval :: StartPointOf (interval :+ extra) -> EndPointOf (interval :+ extra) -> interval :+ extra Source #

buildInterval :: StartPointOf (interval :+ extra) -> EndPointOf (interval :+ extra) -> interval :+ extra Source #

(EndPoint_ (endPoint r), IxValue (endPoint r) ~ r) => ConstructableInterval_ (Interval endPoint r) r Source # 
Instance details

Defined in HGeometry.Interval.Internal

Methods

mkInterval :: StartPointOf (Interval endPoint r) -> EndPointOf (Interval endPoint r) -> Interval endPoint r Source #

buildInterval :: StartPointOf (Interval endPoint r) -> EndPointOf (Interval endPoint r) -> Interval endPoint r Source #

class (Interval_ interval r, StartPointOf interval ~ EndPoint 'Closed r, EndPointOf interval ~ EndPoint 'Closed r) => ClosedInterval_ interval r Source #

A class representing closed intervals, i.e. intervals that include their endpoints

Instances

Instances details
ClosedInterval_ (ClosedInterval r) r Source # 
Instance details

Defined in HGeometry.Interval.Internal

ClosedInterval_ interval r => ClosedInterval_ (interval :+ extra) r Source # 
Instance details

Defined in HGeometry.Interval.Class

pattern ClosedInterval_ :: ClosedInterval_ interval r => r -> r -> interval Source #

Pattern matching on an arbitrary closed interval

class (ClosedInterval_ interval r, ConstructableInterval_ interval r) => ConstructableClosedInterval_ interval r where Source #

A class representing constructable closed intervals

Minimal complete definition

Nothing

Methods

mkClosedInterval :: r -> r -> interval Source #

Construct an interval given its start and end point.

buildClosedInterval :: r -> r -> interval Source #

Construct an interval given two points. This makes sure the start-point comes before the endpoint.

Instances

Instances details
ConstructableClosedInterval_ (ClosedInterval r) r Source # 
Instance details

Defined in HGeometry.Interval.Internal

(ConstructableClosedInterval_ interval r, Default extra) => ConstructableClosedInterval_ (interval :+ extra) r Source # 
Instance details

Defined in HGeometry.Interval.Class

Methods

mkClosedInterval :: r -> r -> interval :+ extra Source #

buildClosedInterval :: r -> r -> interval :+ extra Source #

clampTo :: (ClosedInterval_ interval r, Ord r) => interval -> r -> r Source #

Clamps a value to an interval. I.e. if the value lies outside the range we report the closest value "in the range".

>>> clampTo (ClosedInterval 0 10) 20
10
>>> clampTo (ClosedInterval 0 10) (-20)
0
>>> clampTo (ClosedInterval 0 10) 5
5

class (Interval_ interval r, StartPointOf interval ~ EndPoint 'Open r, EndPointOf interval ~ EndPoint 'Open r) => OpenInterval_ interval r | interval -> r Source #

A class representing open intervals, i.e. intervals that exclude their endpoints

Instances

Instances details
OpenInterval_ (OpenInterval r) r Source # 
Instance details

Defined in HGeometry.Interval.Internal

OpenInterval_ interval r => OpenInterval_ (interval :+ extra) r Source # 
Instance details

Defined in HGeometry.Interval.Class

pattern OpenInterval_ :: OpenInterval_ interval r => r -> r -> interval Source #

Pattern matching on an arbitrary open interval

class (OpenInterval_ interval r, ConstructableInterval_ interval r) => ConstructableOpenInterval_ interval r | interval -> r where Source #

Constructable Open intervals

Minimal complete definition

Nothing

Methods

mkOpenInterval :: r -> r -> interval Source #

Construct an interval given its start s and end point t.

pre: s < t

Instances

Instances details
ConstructableOpenInterval_ (OpenInterval r) r Source # 
Instance details

Defined in HGeometry.Interval.Internal

Methods

mkOpenInterval :: r -> r -> OpenInterval r Source #

(ConstructableOpenInterval_ interval r, Default extra) => ConstructableOpenInterval_ (interval :+ extra) r Source # 
Instance details

Defined in HGeometry.Interval.Class

Methods

mkOpenInterval :: r -> r -> interval :+ extra Source #

class HasStart seg p | seg -> p where Source #

Things that have a start point

Methods

start :: Lens' seg p Source #

Lens to access the start point

Instances

Instances details
HasStart (HalfLine point) point Source # 
Instance details

Defined in HGeometry.HalfLine

Methods

start :: Lens' (HalfLine point) point Source #

HasStart (HalfOpenInterval r) r Source # 
Instance details

Defined in HGeometry.Interval.HalfOpen

(IxValue (endPoint point) ~ point, EndPoint_ (endPoint point)) => HasStart (LineSegment endPoint point) point Source # 
Instance details

Defined in HGeometry.LineSegment.Internal

Methods

start :: Lens' (LineSegment endPoint point) point Source #

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

Defined in HGeometry.Interval.Class

Methods

start :: Lens' (seg :+ extra) p Source #

(EndPoint_ (endPoint r), IxValue (endPoint r) ~ r) => HasStart (Interval endPoint r) r Source # 
Instance details

Defined in HGeometry.Interval.Internal

Methods

start :: Lens' (Interval endPoint r) r Source #

class HasEnd seg p | seg -> p where Source #

Things that have an end point

Methods

end :: Lens' seg p Source #

Lens to access the ending point

Instances

Instances details
HasEnd (HalfOpenInterval r) r Source # 
Instance details

Defined in HGeometry.Interval.HalfOpen

(IxValue (endPoint point) ~ point, EndPoint_ (endPoint point)) => HasEnd (LineSegment endPoint point) point Source # 
Instance details

Defined in HGeometry.LineSegment.Internal

Methods

end :: Lens' (LineSegment endPoint point) point Source #

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

Defined in HGeometry.Interval.Class

Methods

end :: Lens' (seg :+ extra) p Source #

(EndPoint_ (endPoint r), IxValue (endPoint r) ~ r) => HasEnd (Interval endPoint r) r Source # 
Instance details

Defined in HGeometry.Interval.Internal

Methods

end :: Lens' (Interval endPoint r) r Source #

startAndEnd :: (HasStart seg p, HasEnd seg p) => seg -> (p, p) Source #

Get both the start and end of something that has a start and end.

type family StartPointOf interval Source #

type family to declare the type of startpoint for an interval, the idea is to define this as one of the endpoinst form the Endpoints module

Instances

Instances details
type StartPointOf (HalfOpenInterval r) Source # 
Instance details

Defined in HGeometry.Interval.HalfOpen

type StartPointOf (LineSegment endPoint point) Source # 
Instance details

Defined in HGeometry.LineSegment.Internal

type StartPointOf (LineSegment endPoint point) = endPoint point
type StartPointOf (interval :+ extra) Source # 
Instance details

Defined in HGeometry.Interval.Class

type StartPointOf (interval :+ extra) = StartPointOf interval
type StartPointOf (Interval endPoint r) Source # 
Instance details

Defined in HGeometry.Interval.Internal

type StartPointOf (Interval endPoint r) = endPoint r

type family EndPointOf interval Source #

type family to declare the type of endpoint for an interval, the idea is to define this as one of the endpoinst form the Endpoints module

Instances

Instances details
type EndPointOf (HalfOpenInterval r) Source # 
Instance details

Defined in HGeometry.Interval.HalfOpen

type EndPointOf (LineSegment endPoint point) Source # 
Instance details

Defined in HGeometry.LineSegment.Internal

type EndPointOf (LineSegment endPoint point) = endPoint point
type EndPointOf (interval :+ extra) Source # 
Instance details

Defined in HGeometry.Interval.Class

type EndPointOf (interval :+ extra) = EndPointOf interval
type EndPointOf (Interval endPoint r) Source # 
Instance details

Defined in HGeometry.Interval.Internal

type EndPointOf (Interval endPoint r) = endPoint r

class HasStartPoint seg p | seg -> p where Source #

Things that have a start point

Methods

startPoint :: Lens' seg p Source #

Lens to access the start point

Instances

Instances details
HasStartPoint (HalfOpenInterval r) (EndPoint 'Open r) Source # 
Instance details

Defined in HGeometry.Interval.HalfOpen

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

Defined in HGeometry.Interval.Class

Methods

startPoint :: Lens' (seg :+ extra) p Source #

IxValue (endPoint point) ~ point => HasStartPoint (LineSegment endPoint point) (endPoint point) Source # 
Instance details

Defined in HGeometry.LineSegment.Internal

Methods

startPoint :: Lens' (LineSegment endPoint point) (endPoint point) Source #

HasStartPoint (Interval endPoint r) (endPoint r) Source # 
Instance details

Defined in HGeometry.Interval.Internal

Methods

startPoint :: Lens' (Interval endPoint r) (endPoint r) Source #

class HasEndPoint seg p | seg -> p where Source #

Things that have an end point

Methods

endPoint :: Lens' seg p Source #

Lens to access the ending point

Instances

Instances details
HasEndPoint (HalfOpenInterval r) (EndPoint 'Closed r) Source # 
Instance details

Defined in HGeometry.Interval.HalfOpen

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

Defined in HGeometry.Interval.Class

Methods

endPoint :: Lens' (seg :+ extra) p Source #

IxValue (endPoint point) ~ point => HasEndPoint (LineSegment endPoint point) (endPoint point) Source # 
Instance details

Defined in HGeometry.LineSegment.Internal

Methods

endPoint :: Lens' (LineSegment endPoint point) (endPoint point) Source #

HasEndPoint (Interval endPoint r) (endPoint r) Source # 
Instance details

Defined in HGeometry.Interval.Internal

Methods

endPoint :: Lens' (Interval endPoint r) (endPoint r) Source #

startAndEndPoint :: (HasStartPoint seg s, HasEndPoint seg e) => seg -> (s, e) Source #

Get both the start and end of something that has a start and end.

inInterval :: forall interval r. (Ord r, Interval_ interval r) => r -> interval -> PointLocationResult Source #

Compute where the given query value is with respect to the interval.

Note that even if the boundary of the interval is open we may return OnBoundary.

stabsInterval :: forall interval r. (Ord r, Interval_ interval r) => r -> interval -> Bool Source #

Test if the point lies inside in,or on the boundary of, the interval.

Note that even if the boundary of the interval is open we may return OnBoundary.

compareInterval :: (Ord r, Interval_ interval r) => r -> interval -> Ordering Source #

test if te point appears before (=LT), in (=EQ), or after (=GT) te interval.

>>> 1 `compareInterval` (OpenInterval 0 2)
EQ
>>> 1 `compareInterval` (OpenInterval 0 1)
GT
>>> 1 `compareInterval` (ClosedInterval 0 1)
EQ
>>> 10 `compareInterval` (OpenInterval 1 10)
GT
>>> 10 `compareInterval` (ClosedInterval 0 1)
GT

compareIntervalExact :: (Ord r, Interval_ interval r) => r -> interval -> CompareInterval Source #

test if te point appears before, in, or after te interval, or on one of its endpoints.

>>> 1 `compareIntervalExact` (OpenInterval 0 2)
Interior
>>> 1 `compareIntervalExact` (OpenInterval 0 1)
OnEnd
>>> 1 `compareIntervalExact` (ClosedInterval 0 1)
OnEnd
>>> 10 `compareIntervalExact` (OpenInterval 1 10)
OnEnd
>>> 10 `compareIntervalExact` (ClosedInterval 0 1)
After

shiftLeft :: (Num r, Interval_ interval r) => r -> interval -> interval Source #

Shifts the interval to the left by delta

shiftRight :: (Num r, Interval_ interval r) => r -> interval -> interval Source #

Shifts the interval to the right by delta

duration :: (Interval_ interval r, Num r) => interval -> r Source #

Get the duration, or length of an interval.