Ranger.src.Range package

Submodules

Ranger.src.Range.Cut module

class Ranger.src.Range.Cut.Cut(theType, aboveAll=False, belowAll=False, point=None, below=False)[source]

Bases: object

Class used to represent a cutpoint in a range, such that any range can be represented by 2 Cuts

Methods

aboveAll(theType) Create a cut point outside the upper end of the domain
aboveValue(val[, theType]) Create a cut point, where everything above some value is
belowAll(theType) Create a cut point outside the lower end of the domain
belowValue(val[, theType]) Create a cut point, where everything below some value is
isGreaterThan(val) Returns whether the cutpoint is greater than a specified value
isLessThan(val) Returns whether the cutpoint is less than a specified value
static aboveAll(theType)[source]

Create a cut point outside the upper end of the domain

Parameters:

theType : type

Most inclusive type that can be used for comparison

Returns:

The cut object

static aboveValue(val, theType=None)[source]

Create a cut point, where everything above some value is included

Parameters:

val : value in the domain

Cut point, where everything above value is included

theType : type

Most inclusive type that can be used for comparison. If None, then the type of the value is used

Returns:

The cut object

static belowAll(theType)[source]

Create a cut point outside the lower end of the domain

Parameters:

theType : type

Most inclusive type that can be used for comparison.

Returns:

The cut object

static belowValue(val, theType=None)[source]

Create a cut point, where everything below some value is included

Parameters:

val : value in the domain

Cut point, where everything below value is included

theType : type

Most inclusive type that can be used for comparison. If None, then the type of the value is used

Returns

——-

The cut object

isGreaterThan(val)[source]

Returns whether the cutpoint is greater than a specified value

Parameters:

val : Comparable, of compatible type

The value to compare the cutpoint to

Returns:

True if the cutpoint is strictly greater than the specified value

Raises:

ValueError

If the value type not compatible with cutpoint type

isLessThan(val)[source]

Returns whether the cutpoint is less than a specified value

Parameters:

val : Comparable, of compatible type

The value to compare the cutpoint to

Returns:

True if the cutpoint is strictly less than the specified value

Raises:

ValueError

If the value type not compatible with cutpoint type

Ranger.src.Range.Range module

class Ranger.src.Range.Range.Range(lowerCut, upperCut)[source]

Bases: object

Class used to represent a range along some 1-D domain. The range is represented by 2 cutpoints can can be unbounded by specifying an aboveAll or belowAll Cut.

Methods

atLeast(val) Makes range including all values greater than or equal to some value (i.e.
atMost(val) Makes range including all values less than or equal to some value (i.e.
closed(lower, upper) Creates a range including the endpoints (i.e.
closedOpen(lower, upper) Creates a range including the lower endpoint (i.e.
contains(val) Returns true if the range contains the value
containsAll(vals) Returns True if the range contains all values in some
encloses(other) Returns True if the bounds of the other range do not extend
getDistanceFromPoint(val[, distFunc]) Returns the minimum distance of a Range from a Point, returning 0 if there is an overlap.
getDistanceFromRange(other[, distFunc]) Returns the minimum distance of a Range from another Range, returning
greaterThan(val) Makes range including all values greater than some value (i.e.
hasLowerBound() Returns True if the range has a lower endpoint (not unbounded
hasUpperBound() Returns True if the range has an upper endpoint (not unbounded
intersection(other) Returns the maximal range enclosed by both this range and the
isConnected(other) Returns True if there is a (possibly empty) range that is
isEmpty() Returns True if the range is of form [v, v) or (v, v]
isLowerBoundClosed() Returns whether the lower bound is closed (if there is a
isUpperBoundClosed() Returns whether the upper bound is closed (if there is an
lessThan(val) Makes range including all values less than some value (i.e.
lowerEndpoint() Returns the lower endpoint of the range if it exists.
open(lower, upper) Creates a range excluding the endpoints (i.e.
openClosed(lower, upper) Creates a range including the upper (i.e.
span(other) Returns the minimal range that encloses both this range and the other.
upperEndpoint() Returns the upper endpoint of the range if it exists.
static atLeast(val)[source]

Makes range including all values greater than or equal to some value (i.e. [val, inf))

Parameters:

val : comparable

The lower bound

Returns:

A Range object [val, inf)

Raises:

ValueError

If type not comparable

static atMost(val)[source]

Makes range including all values less than or equal to some value (i.e. (-inf, val])

Parameters:

val : comparable

The upper bound

Returns:

A Range object (-inf, val]

Raises:

ValueError

If type not comparable

static closed(lower, upper)[source]

Creates a range including the endpoints (i.e. [lower, upper])

Parameters:

lower : comparable, of same type as or subclass of upper type

The lower bound

upper : comparable, of same type as or subclass of lower type

The upper bound

Returns:

A Range object [lower, upper]

Raises:

ValueError

If type(s) are not comparable or compatible

static closedOpen(lower, upper)[source]

Creates a range including the lower endpoint (i.e. [lower, upper))

Parameters:

lower : comparable, of same type as or subclass of upper type

The lower bound

upper : comparable, of same type as or subclass of lower type

The upper bound

Returns:

A Range object [lower, upper)

Raises:

ValueError

If type(s) are not comparable or compatible

contains(val)[source]

Returns true if the range contains the value

Parameters:

val : Comparable object of the appropriate type for the range

Value to query whether in the range

Returns:

True if the range contains the value

Raises:

ValueError

If the value type not compatible with cutpoint type

containsAll(vals)[source]

Returns True if the range contains all values in some iterable

Parameters:

vals : Iterable of comparable object of appropriate type for range

Values to query against the range

Returns:

True if the range contains all values

Raises:

ValueError

If there is a value type not compatible with the cutpoint type

encloses(other)[source]

Returns True if the bounds of the other range do not extend outside the bounds of this range

Examples:
[3,6] encloses [4,5] (3,6) encloses (3,6) [3,6] encloses [4,4] (3,6] does not enclose [3,6] [4,5] does not enclose (3,6)
Parameters:

other : A Range

The range to compare to

Returns:

True if the bounds of the other range do not extend outside

the bounds of this range

Raises:

ValueError

If object passed in is not a Range

getDistanceFromPoint(val, distFunc=<function <lambda> at 0x2b95996f1de8>)[source]

Returns the minimum distance of a Range from a Point, returning 0 if there is an overlap.

Note that both upper and lower bounds must be closed for this function to work

Parameters:

val : comparable, compatible with cutpoint type

The value of the point where the distance is desired

distFunc : callable

Function that calculates the distance between two points in the domain of the Range

Returns:

The minimum distance between the Range and the Point. Returns 0

if there is an overlap

Raises:

TypeError

If the upper and/or lower bounds of this Range are not closed or if the distFunc not compatible with the type

getDistanceFromRange(other, distFunc=<function <lambda> at 0x2b95996f1ed8>)[source]

Returns the minimum distance of a Range from another Range, returning 0 if there is any overlap

Note that both Ranges must be closed for this function to work

Parameters:

other : Range, compatible with this Range’s domain

The Range to compare to

distFunc : callable

Function that calculates the distance between two points in the domain of the Range

Returns:

Minimum distance between the ranges

Raises:

TypeError

If the upper and/or lower bounds of this Range are not closed or if the distFunc not compatible with the type

static greaterThan(val)[source]

Makes range including all values greater than some value (i.e. (val, inf])

Parameters:

val : comparable

The lower bound

Returns:

A Range object (val, inf)

Raises:

ValueError

If type not comparable

hasLowerBound()[source]

Returns True if the range has a lower endpoint (not unbounded at the lower end)

Returns:True if the range has a lower endpoint
hasUpperBound()[source]

Returns True if the range has an upper endpoint (not unbounded at the upper end)

Returns:True if the range has an upper endpoint
intersection(other)[source]

Returns the maximal range enclosed by both this range and the other range, if such a range exists

Examples:
Intersection of [1,5] and [3,7] is [3,5] Intersection of [1,5] and [5,7] is [5,5]
Parameters:

other : A range

The range to compare to

Returns:

The intersection range

Raises:

ValueError

If object passed in is not a Range or if there is no intersection

isConnected(other)[source]

Returns True if there is a (possibly empty) range that is enclosed by both this range and other

Examples:
[2,4] and [5,7] are not connected [2,4] and [3,5] are connected [2,4] and [4,6] are connected [3,5] and (5,10) are connected
Parameters:

other : A range

The range to compare to

Returns:

True if there is a (possibly empty) range that is enclosed by

both this range and other

Raises:

ValueError

If object passed in is not a Range

isEmpty()[source]

Returns True if the range is of form [v, v) or (v, v]

Returns:True if the range is of the form [v,v) or (v,v]
isLowerBoundClosed()[source]

Returns whether the lower bound is closed (if there is a lower bound)

Returns:

True if the lower bound is closed

Raises:

TypeError

If the range is unbounded below

isUpperBoundClosed()[source]

Returns whether the upper bound is closed (if there is an upper bound)

Returns:

True if the upper bound is closed

Raises:

TypeError

If the range is unbounded above

static lessThan(val)[source]

Makes range including all values less than some value (i.e. (-inf, val))

Parameters:

val : comparable

The upper bound

Returns:

A Range object (-inf, val)

Raises:

ValueError

If type not comparable

lowerEndpoint()[source]

Returns the lower endpoint of the range if it exists. Otherwise raises a TypeError

Returns:

The lower endpoint of the range

Raises:

TypeError

If the range is unbounded below

static open(lower, upper)[source]

Creates a range excluding the endpoints (i.e. (lower, upper))

Parameters:

lower : comparable, of same type as or subclass of upper type

The lower bound

upper : comparable, of same type as or subclass of lower type

The upper bound

Returns:

A Range object (lower, upper)

Raises:

ValueError

If type(s) are not comparable or compatible or if constructing a range of type (v,v), which is invalid

static openClosed(lower, upper)[source]

Creates a range including the upper (i.e. (lower, upper])

Parameters:

lower : comparable, of same type as or subclass of upper type

The lower bound

upper : comparable, of same type as or subclass of lower type

The upper bound

Returns:

A Range object (lower, upper]

Raises:

ValueError

If type(s) are not comparable or compatible

span(other)[source]

Returns the minimal range that encloses both this range and the other. Note that if the input ranges are not connected, the span can contain values that are not contained within either input range

Examples:
Span of [1,3] and [5,7] is [1,7]
Parameters:

other : A range

A range to span with

Returns:

The minimal range enclosing both with and the other range

Raises:

ValueError

If object passed in is not a Range or if there is no intersection

upperEndpoint()[source]

Returns the upper endpoint of the range if it exists. Otherwise raises a TypeError

Returns:

The upper endpoint of the range

Raises:

TypeError

If the range is unbounded above

Module contents

Table Of Contents

This Page