Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Geom::Interval Class Reference

Range of real numbers that is never empty. More...

#include <interval.h>

Inheritance diagram for Geom::Interval:
Geom::GenericInterval< Coord >

Public Member Functions

Inspect contained values.

Check whether both endpoints are finite.

bool isFinite () const
 
constexpr Coord valueAt (Coord t) const
 Map the interval [0,1] onto this one.
 
constexpr Coord timeAt (Coord v) const
 Compute a time value that maps to the given value.
 
constexpr Coord nearestTime (Coord v) const
 Find closest time in [0,1] that maps to the given value. *‍/.
 
Test coordinates and other intervals for inclusion.
constexpr bool interiorContains (Coord val) const
 Check whether the interior of the interval includes this number.
 
constexpr bool interiorContains (Interval const &val) const
 Check whether the interior of the interval includes the given interval.
 
constexpr bool lowerContains (Coord val) const
 Check whether the number is contained in the union of the interior and the lower boundary.
 
constexpr bool lowerContains (Interval const &val) const
 Check whether the given interval is contained in the union of the interior and the lower boundary.
 
constexpr bool upperContains (Coord val)
 Check whether the number is contained in the union of the interior and the upper boundary.
 
constexpr bool upperContains (Interval const &val) const
 Check whether the given interval is contained in the union of the interior and the upper boundary.
 
constexpr bool interiorIntersects (Interval const &val) const
 Check whether the interiors of the intervals have any common elements.
 
Operators
constexpr Intervaloperator*= (Coord s)
 Scale an interval.
 
constexpr Intervaloperator/= (Coord s)
 Scale an interval by the inverse of the specified value.
 
constexpr Intervaloperator*= (Interval const &o)
 Multiply two intervals.
 
constexpr bool operator== (IntInterval const &ii) const
 
constexpr bool operator== (Interval const &other) const
 
Rounding to integer values
IntInterval roundOutwards () const
 Return the smallest integer interval which contains this one.
 
OptIntInterval roundInwards () const
 Return the largest integer interval which is contained in this one.
 
- Public Member Functions inherited from Geom::GenericInterval< Coord >
constexpr Coord min () const
 
constexpr Coord max () const
 
constexpr Coord extent () const
 
constexpr Coord middle () const
 
constexpr bool isSingular () const
 
Coord operator[] (unsigned i) const
 
constexpr Coord operator[] (Dim2 d) const
 
constexpr Coord clamp (Coord val) const
 
Coord nearestEnd (Coord val) const
 Return the closer end of the interval.
 
constexpr Coord get () const
 
constexpr bool contains (Coord val) const
 Check whether the interval includes this number.
 
constexpr bool contains (CInterval const &val) const
 Check whether the interval includes the given interval.
 
constexpr bool intersects (CInterval const &val) const
 Check whether the intervals have any common elements.
 
constexpr void setMin (Coord val)
 Set the lower boundary of the interval.
 
constexpr void setMax (Coord val)
 Set the upper boundary of the interval.
 
constexpr void setEnds (Coord a, Coord b)
 Set both ends of the interval simultaneously.
 
constexpr void expandTo (Coord val)
 Extend the interval to include the given number.
 
constexpr void expandBy (Coord amount)
 Expand or shrink the interval in both directions by the given amount.
 
constexpr void unionWith (CInterval const &a)
 Union the interval with another one.
 
constexpr Selfoperator+= (Coord amnt)
 Offset the interval by a specified amount.
 
constexpr Selfoperator+= (CInterval const &o)
 Add two intervals.
 
constexpr Selfoperator-= (Coord amnt)
 Offset the interval by the negation of the specified amount.
 
constexpr Selfoperator-= (CInterval const &o)
 Subtract two intervals.
 
constexpr Self operator- () const
 Return an interval mirrored about 0.
 
constexpr Selfoperator|= (CInterval const &o)
 Union two intervals.
 
constexpr bool operator== (CInterval const &other) const
 Test for interval equality.
 
constexpr GenericInterval ()=default
 Create an interval that contains only zero.
 
constexpr GenericInterval (Coord u)
 Create an interval that contains a single point.
 
constexpr GenericInterval (Coord u, Coord v)
 Create an interval that contains all points between u and v.
 

Private Types

using Base = GenericInterval< Coord >
 

Create intervals.

constexpr Interval ()=default
 Create an interval that contains only zero.
 
constexpr Interval (Coord u)
 Create an interval that contains a single point.
 
constexpr Interval (Coord u, Coord v)
 Create an interval that contains all points between u and v.
 
constexpr Interval (IntInterval const &i)
 Convert from integer interval.
 
constexpr Interval (Base const &b)
 
template<typename InputIterator >
static Interval from_range (InputIterator start, InputIterator end)
 Create an interval containing a range of values.
 
static Interval from_array (Coord const *c, unsigned n)
 Create an interval from a C-style array of values it should contain.
 

Additional Inherited Members

- Public Types inherited from Geom::GenericInterval< Coord >
using output_type = Coord
 
- Static Public Member Functions inherited from Geom::GenericInterval< Coord >
static CInterval from_range (InputIterator start, InputIterator end)
 Create an interval containing a range of values.
 
static CInterval from_array (Coord const *c, unsigned n)
 Create an interval from a C-style array of values it should contain.
 
- Protected Attributes inherited from Geom::GenericInterval< Coord >
Coord _b [2]
 

Detailed Description

Range of real numbers that is never empty.

Intervals are closed ranges \([a, b]\), which means they include their endpoints. To use them as open ranges, you can use the interiorContains() methods.

Definition at line 57 of file interval.h.

Member Typedef Documentation

◆ Base

Definition at line 60 of file interval.h.

Constructor & Destructor Documentation

◆ Interval() [1/5]

constexpr Geom::Interval::Interval ( )
constexprdefault

Create an interval that contains only zero.

◆ Interval() [2/5]

constexpr Geom::Interval::Interval ( Coord  u)
inlineexplicitconstexpr

Create an interval that contains a single point.

Definition at line 67 of file interval.h.

◆ Interval() [3/5]

constexpr Geom::Interval::Interval ( Coord  u,
Coord  v 
)
inlineconstexpr

Create an interval that contains all points between u and v.

Definition at line 69 of file interval.h.

◆ Interval() [4/5]

constexpr Geom::Interval::Interval ( IntInterval const &  i)
inlineconstexpr

Convert from integer interval.

Definition at line 71 of file interval.h.

◆ Interval() [5/5]

constexpr Geom::Interval::Interval ( Base const &  b)
inlineconstexpr

Definition at line 72 of file interval.h.

Member Function Documentation

◆ from_array()

static Interval Geom::Interval::from_array ( Coord const *  c,
unsigned  n 
)
inlinestatic

Create an interval from a C-style array of values it should contain.

Definition at line 86 of file interval.h.

References c, and Geom::GenericInterval< Coord >::from_array().

Referenced by wrap_interval().

◆ from_range()

template<typename InputIterator >
static Interval Geom::Interval::from_range ( InputIterator  start,
InputIterator  end 
)
inlinestatic

Create an interval containing a range of values.

The resulting interval will contain all values from the given range. The return type of iterators must be convertible to Coord. The given range must not be empty. For potentially empty ranges, see OptInterval.

Parameters
startBeginning of the range
endEnd of the range
Returns
Interval that contains all values from [start, end).

Definition at line 82 of file interval.h.

References end, Geom::GenericInterval< Coord >::from_range(), and start.

◆ interiorContains() [1/2]

constexpr bool Geom::Interval::interiorContains ( Coord  val) const
inlineconstexpr

Check whether the interior of the interval includes this number.

Interior means all numbers in the interval except its ends.

Definition at line 119 of file interval.h.

References Geom::GenericInterval< Coord >::max(), and Geom::GenericInterval< Coord >::min().

Referenced by wrap_interiorContains_coord(), and wrap_interiorContains_ivl().

◆ interiorContains() [2/2]

constexpr bool Geom::Interval::interiorContains ( Interval const &  val) const
inlineconstexpr

Check whether the interior of the interval includes the given interval.

Interior means all numbers in the interval except its ends.

Definition at line 122 of file interval.h.

References Geom::GenericInterval< Coord >::max(), Geom::GenericInterval< C >::max(), Geom::GenericInterval< C >::min(), and Geom::GenericInterval< Coord >::min().

◆ interiorIntersects()

constexpr bool Geom::Interval::interiorIntersects ( Interval const &  val) const
inlineconstexpr

Check whether the interiors of the intervals have any common elements.

A single point in common is not considered an intersection.

Definition at line 133 of file interval.h.

References Geom::GenericInterval< C >::max(), Geom::GenericInterval< Coord >::max(), Geom::GenericInterval< C >::min(), and Geom::GenericInterval< Coord >::min().

◆ isFinite()

bool Geom::Interval::isFinite ( ) const
inline

◆ lowerContains() [1/2]

constexpr bool Geom::Interval::lowerContains ( Coord  val) const
inlineconstexpr

Check whether the number is contained in the union of the interior and the lower boundary.

Definition at line 124 of file interval.h.

References Geom::GenericInterval< Coord >::max(), and Geom::GenericInterval< Coord >::min().

Referenced by Geom::EllipticalArc::winding().

◆ lowerContains() [2/2]

constexpr bool Geom::Interval::lowerContains ( Interval const &  val) const
inlineconstexpr

Check whether the given interval is contained in the union of the interior and the lower boundary.

Definition at line 126 of file interval.h.

References Geom::GenericInterval< Coord >::max(), Geom::GenericInterval< C >::max(), Geom::GenericInterval< C >::min(), and Geom::GenericInterval< Coord >::min().

◆ nearestTime()

constexpr Coord Geom::Interval::nearestTime ( Coord  v) const
inlineconstexpr

Find closest time in [0,1] that maps to the given value. *‍/.

Definition at line 108 of file interval.h.

References Geom::GenericInterval< Coord >::max(), Geom::GenericInterval< Coord >::min(), and timeAt().

◆ operator*=() [1/2]

constexpr Interval & Geom::Interval::operator*= ( Coord  s)
inlineconstexpr

Scale an interval.

Definition at line 142 of file interval.h.

References Geom::GenericInterval< Coord >::_b.

◆ operator*=() [2/2]

constexpr Interval & Geom::Interval::operator*= ( Interval const &  o)
inlineconstexpr

Multiply two intervals.

Product is defined as the set of points that can be obtained by multiplying any value from the second operand by any value from the first operand: \(S = \{x \in A, y \in B: x * y\}\)

Definition at line 161 of file interval.h.

References Geom::GenericInterval< Coord >::expandTo(), Geom::GenericInterval< C >::max(), Geom::GenericInterval< Coord >::max(), Geom::GenericInterval< C >::min(), and Geom::GenericInterval< Coord >::min().

◆ operator/=()

constexpr Interval & Geom::Interval::operator/= ( Coord  s)
inlineconstexpr

Scale an interval by the inverse of the specified value.

Definition at line 150 of file interval.h.

References Geom::GenericInterval< Coord >::_b.

◆ operator==() [1/2]

constexpr bool Geom::Interval::operator== ( Interval const &  other) const
inlineconstexpr

Definition at line 173 of file interval.h.

References Geom::GenericInterval< Coord >::operator==().

◆ operator==() [2/2]

constexpr bool Geom::Interval::operator== ( IntInterval const &  ii) const
inlineconstexpr

◆ roundInwards()

OptIntInterval Geom::Interval::roundInwards ( ) const
inline

Return the largest integer interval which is contained in this one.

Definition at line 185 of file interval.h.

References floor(), Geom::GenericInterval< Coord >::max(), and Geom::GenericInterval< Coord >::min().

◆ roundOutwards()

IntInterval Geom::Interval::roundOutwards ( ) const
inline

Return the smallest integer interval which contains this one.

Definition at line 181 of file interval.h.

References floor(), Geom::GenericInterval< Coord >::max(), and Geom::GenericInterval< Coord >::min().

◆ timeAt()

constexpr Coord Geom::Interval::timeAt ( Coord  v) const
inlineconstexpr

Compute a time value that maps to the given value.

The supplied value does not need to be in the interval for this method to work.

Definition at line 104 of file interval.h.

References Geom::GenericInterval< Coord >::extent(), and Geom::GenericInterval< Coord >::min().

Referenced by nearestTime().

◆ upperContains() [1/2]

constexpr bool Geom::Interval::upperContains ( Coord  val)
inlineconstexpr

Check whether the number is contained in the union of the interior and the upper boundary.

Definition at line 128 of file interval.h.

References Geom::GenericInterval< Coord >::max(), and Geom::GenericInterval< Coord >::min().

◆ upperContains() [2/2]

constexpr bool Geom::Interval::upperContains ( Interval const &  val) const
inlineconstexpr

Check whether the given interval is contained in the union of the interior and the upper boundary.

Definition at line 130 of file interval.h.

References Geom::GenericInterval< Coord >::max(), Geom::GenericInterval< C >::max(), Geom::GenericInterval< C >::min(), and Geom::GenericInterval< Coord >::min().

◆ valueAt()

constexpr Coord Geom::Interval::valueAt ( Coord  t) const
inlineconstexpr

Map the interval [0,1] onto this one.

This method simply performs 1D linear interpolation between endpoints.

Definition at line 99 of file interval.h.

References Geom::lerp(), Geom::GenericInterval< Coord >::max(), and Geom::GenericInterval< Coord >::min().

Referenced by Geom::Curve::intersectSelf(), Geom::detail::bezier_clipping::map_to(), and Geom::nearest_time().


The documentation for this class was generated from the following file: