# File Range1D.hpp

namespace Acts

Note

This file is foreseen for the `Geometry` module to replace `Extent`

template<typename Type>
class Range1D
#include <Acts/Utilities/Range1D.hpp>

A one-dimensional range between two points.

This type describes a one-demensional range of values, designed to be used in the construction of more complex multi-dimensional types. The class provides functionality for growing and shrinking the range, as well as some other utilities. These ranges are half-open, including the minimum but excluding the maximum.

Template Parameters

Type – The scalar type of the values contained in this range.

Public Functions

inline Range1D()

Construct a new degenerate range object.

This constructor coonstructs a degenerate range object with a maximum lower than the minimum. In other words, this range is empty.

inline Range1D(const Range1D<Type> &o)

Construct a new range object from an existing range.

This simply copies the values from the existing range to the new one. It’s the copy constructor.

Parameters

o – The range to copy

inline Range1D(const std::pair<Type, Type> &p)

Construct a new range object from a pair of bounds.

Construct a new range object from a pair of values, the first of which is taken to be the minimum, and the second of which is taken to be the maximum.

Parameters

p – The pair of values to use as the minimum and maximum

inline Range1D(Type min, Type max)

Construct a new range object from a lower and upper bound.

Construct a new range object given the values for the minimum and maximum. Note that it is perfectly possible to construct a degenerate range in this way.

Parameters
• min – The minimum value in the range (inclusive)

• max – The maximum value in the range (exclusive)

inline bool contains(const Type &v) const

Determine if the range contains a given value.

A value is inside a range if and only if it is greater than the minimum and smaller than the maximum.

Parameters

v – The value to check

Returns

true The value is inside the range

Returns

false The value is not inside the range

inline bool degenerate(void) const

Determine if this range is degenerate or not.

A degenerate range has a minimum higher than the maximum, and thus cannot contain any values.

Returns

true The range is degenerate and has size zero

Returns

false The range is not degenerate

inline void expand(const Type &min, const Type &max)

Expand a range on both ends.

Expand a range by decreasing the minimum value as well as increasing the maximum value. If either of the values are already larger or smaller (respectively) than the proposed values, then that particular boundary of the interval is not expanded.

Note

After this operation, the range is always equal to or larger than [min, max].

Parameters
• min – The proposed new minimum for the range

• max – The proposed new maximum for the range

inline void expandMax(const Type &v)

Expand a range by increasing the maximum value.

Expand the range by increasing the maximum value. If the given value is smaller than the current maximum (in other words, if the proposed new range would be smaller than the current range), this is a no-op.

Parameters

v – The proposed new maximum for the range

inline void expandMin(const Type &v)

Expand a range by decreasing the minimum value.

Expand the range by decreasing the minimum value. If the given value is larger than the current minimum (in other words, if the proposed new range would be smaller than the current range), this is a no-op.

Parameters

v – The proposed new minimum for the range

inline Type max(void) const

Return the maximum value of the range (inclusive)

inline Type min(void) const

Return the minimum value of the range (inclusive)

inline Range1D<Type> operator&(const Range1D<Type> &o) const

Compute the intersection of two ranges.

The intersection of two ranges is the range containing all values contained in both ranges. If the two ranges do not intersect, the intersection is a degenerate range. This operation is commutative.

Parameters

o – The range to compute the intersection with

Returns

The intersection range between the two ranges

inline bool operator&&(const Range1D<Type> &o) const

Determine whether the range intersects another range.

The intersection of a range is the space where both ranges overlap. If the ranges overlap at all, they are said to intersect. This operation is commutative.

Parameters

o – The other range to check

Returns

true The ranges intersect

Returns

false The ranges do not intersect

inline Range1D<Type> &operator&=(const Range1D<Type> &o)

Set the range to the intersection of itself and another range.

This is an assignment version of operator&, which updates the range on which it is called to ensure that the new range is the intersection of the old range and the new range.

Parameters

o – The range to compute the intersection with

Returns

This object

inline bool operator<=(const Range1D<Type> &o) const

Determine whether the left-hand range is a subset of the right-hand range.

A range is a subset of another range if and only if all values contained in the first range are also contained in the second range.

Parameters

o – The other range to check

Returns

true The left-hand range is a subset of the right-hand range

Returns

false The left-hand range is not a subset of the right-hand range

inline Range1D<Type> &operator=(const Range1D<Type> &o)

Assignment operator.

Copy the right-hand range into the left-hand range, which means setting the minimum and maximum to equal the minimum and maximum of the right-hand side.

Parameters

o – The range of values to copy

Returns

This range

inline bool operator==(const Range1D<Type> &o) const

Determine whether the range is equal to another range.

Two ranges are equal if and only if their minima and maxima are the same.

Warning

This method relies on the existence of a well-defined notion of equality for the underlying types. Using this method on floating ranges may have unintended effecrs.

Parameters

o – The other range to check

Returns

true The ranges are equal

Returns

false The ranges are not equal

inline bool operator>=(const Range1D<Type> &o) const

Determine whether the left-hand range is a superset of the right-hand range.

A range is a superset of another range if and only if all values contained in the second range are also contained in the first range.

Parameters

o – The other range to check

Returns

true The left-hand range is a superset of thr right-hand range

Returns

false The left-hand range is not a superset of the right-hand range

inline void set(const Type &min, const Type &max)

Set the minimum and maximum value.

Override both the minimum and maximum value of the range, regardless of what they were set to.

Note

If you want to shrink or expand the range, use the shrink and expand methods.

Note

After this operation, the range should be exactly equal to [min, max]

Parameters
• min – The new minimum value of the range

• max – The new maximum value of the range

inline void setMax(const Type &v)

Set the maximum value.

Override the maximum value of the range, regardless of what was already set.

Note

If you want to shrink or expand the range, use the shrink and expand methods.

Parameters

v – The value to use as the new maximum

inline void setMin(const Type &v)

Set the minimum value.

Override the minimum value of the range, regardless of what was already set.

Note

If you want to shrink or expand the range, use the shrink and expand methods.

Parameters

v – The value to use as the new minimum

inline void shrink(const Type &min, const Type &max)

Shrink a range on both ends.

Shrink a range by increasing the minimum value as well as decreasing the maximum value. If either of the values are already smaller or larger (respectively) than the proposed values, then that particular boundary of the interval is not shrunk.

Note

After this operation, the range is always equal to or smaller than [min, max].

Parameters
• min – The proposed new minimum for the range

• max – The proposed new maximum for the range

inline void shrinkMax(const Type &v)

Shrink a range by decreasing the maximum value.

Shrink the range by decreasing the maximum value. If the given value is larger than the current maximum (in other words, if the proposed new range would be larger than the current range), this is a no-op.

Parameters

v – The proposed new maximum for the range

inline void shrinkMin(const Type &v)

Shrink a range by increasing the minimum value.

Shrink the range by increasing the minimum value. If the given value is smaller than the current minimum (in other words, if the proposed new range would be larger than the current range), this is a no-op.

Parameters

v – The proposed new minimum for the range

inline Type size(void) const

Compute the size of the range.

The size of a range is defined as the difference between the minimum and the maximum. For degenerate ranges, this is zero.

Warning

Due to the nature of numbers, the result of this function can be somewhat ambiguous. For natural numbers, you could argue that the range [n, n] has size 0 or size 1. In this case we say it has size 0. The uncountable nature of the reals means this doesn’t matter for them, but this can be awkward when working with integers.

Returns

The size of the range

Private Members

Type m_max
Type m_min