37#ifndef LIB2GEOM_SEEN_INTERVAL_H
38#define LIB2GEOM_SEEN_INTERVAL_H
40#include <boost/none.hpp>
41#include <boost/operators.hpp>
81 template <
typename InputIterator>
95 return std::isfinite(
min()) && std::isfinite(
max());
109 if (v <=
min())
return 0;
110 if (v >=
max())
return 1;
134 return std::max(
min(), val.
min()) < std::min(
max(), val.
max());
146 if (s < 0) swap(
_b[0],
_b[1]);
154 if (s < 0) swap(
_b[0],
_b[1]);
187 if (u > v)
return {};
203 using Base::operator==;
204 using Base::operator!=;
227template <>
struct std::tuple_size<
Geom::
Interval> : std::integral_constant<size_t, 2> {};
231template <>
struct std::hash<
Geom::
Interval> : std::hash<Geom::GenericInterval<Geom::Coord>> {};
A range of numbers which is never empty.
constexpr Coord extent() const
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.
constexpr bool operator==(CInterval const &other) const
Test for interval equality.
constexpr void expandTo(Coord val)
Extend the interval to include the given number.
constexpr Coord min() const
constexpr Coord max() const
A range of numbers that can be empty.
std::optional< CInterval > Base
Range of real numbers that is never empty.
constexpr bool operator==(IntInterval const &ii) const
constexpr Coord nearestTime(Coord v) const
Find closest time in [0,1] that maps to the given value. */.
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 Interval & operator*=(Coord s)
Scale an interval.
constexpr bool interiorContains(Coord val) const
Check whether the interior of the interval includes this number.
constexpr Coord valueAt(Coord t) const
Map the interval [0,1] onto this one.
constexpr Interval(Base const &b)
constexpr bool lowerContains(Coord val) const
Check whether the number is contained in the union of the interior and the lower boundary.
constexpr Coord timeAt(Coord v) const
Compute a time value that maps to the given value.
constexpr Interval(Coord u, Coord v)
Create an interval that contains all points between u and v.
constexpr bool lowerContains(Interval const &val) const
Check whether the given interval is contained in the union of the interior and the lower boundary.
OptIntInterval roundInwards() const
Return the largest integer interval which is contained in this one.
constexpr Interval & operator*=(Interval const &o)
Multiply two intervals.
constexpr Interval(Coord u)
Create an interval that contains a single point.
constexpr bool operator==(Interval const &other) const
constexpr Interval & operator/=(Coord s)
Scale an interval by the inverse of the specified value.
constexpr Interval(IntInterval const &i)
Convert from integer interval.
constexpr Interval()=default
Create an interval that contains only zero.
constexpr bool interiorContains(Interval const &val) const
Check whether the interior of the interval includes the given interval.
IntInterval roundOutwards() const
Return the smallest integer interval which contains this one.
constexpr bool interiorIntersects(Interval const &val) const
Check whether the interiors of the intervals have any common elements.
static Interval from_array(Coord const *c, unsigned n)
Create an interval from a C-style array of values it should contain.
constexpr bool upperContains(Coord val)
Check whether the number is contained in the union of the interior and the upper boundary.
static Interval from_range(InputIterator start, InputIterator end)
Create an interval containing a range of values.
Range of real numbers that can be empty.
constexpr OptInterval(OptIntInterval const &i)
Promote from OptIntInterval.
constexpr OptInterval(IntInterval const &i)
Promote from IntInterval.
constexpr OptInterval(Base const &b)
Integral and real coordinate types and some basic utilities.
Closed interval of generic values.
constexpr Coord lerp(Coord t, Coord a, Coord b)
Numerically stable linear interpolation.
int IntCoord
Type used for integral coordinates.
double Coord
Floating point type used to store coordinates.
GenericInterval< IntCoord > IntInterval
Range of integers that is never empty.
auto floor(Geom::Rect const &rect)
Closed interval of integer values.
Low level math functions and compatibility wrappers.
Various utility functions.
IntRect unify(IntRect const &a, IntRect const &b)
std::vector< Point > intersect(const xAx &C1, const xAx &C2)