generic-interval.h revision d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9
/**
* @file
* @brief Closed interval of generic values
*//*
* Copyright 2011 Krzysztof KosiĆski <tweenk.pl@gmail.com>
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*/
#ifndef LIB2GEOM_SEEN_GENERIC_INTERVAL_H
#define LIB2GEOM_SEEN_GENERIC_INTERVAL_H
#include <cassert>
#include <boost/optional.hpp>
#include <boost/operators.hpp>
/**
* @brief A range of numbers which is never empty.
* @ingroup Primitives
*/
> > > >
{
typedef GenericInterval<C> Self;
C _b[2];
/// @name Create intervals.
/// @{
/** @brief Create an interval that contains only zero. */
/** @brief Create an interval that contains a single point. */
/** @brief Create an interval that contains all points between @c u and @c v. */
GenericInterval(C u, C v) {
if (u <= v) {
} else {
}
}
/** @brief 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 C. The given range
* must not be empty. For potentially empty ranges, see GenericOptInterval.
* @param start Beginning of the range
* @param end End of the range
* @return Interval that contains all values from [start, end). */
return result;
}
/** @brief Create an interval from a C-style array of values it should contain. */
static Self from_array(C const *c, unsigned n) {
return result;
}
/// @}
/// @name Inspect endpoints.
/// @{
/// @}
/// @name Test coordinates and other intervals for inclusion.
/// @{
/** @brief Check whether the interval includes this number. */
}
/** @brief Check whether the interval includes the given interval. */
}
/** @brief Check whether the intervals have any common elements. */
}
/// @}
/// @name Modify the interval.
/// @{
//TODO: NaN handleage for the next two?
/** @brief Set the lower boundary of the interval.
* When the given number is larger than the interval's largest element,
* it will be reduced to the single number @c val. */
} else {
}
}
/** @brief Set the upper boundary of the interval.
* When the given number is smaller than the interval's smallest element,
* it will be reduced to the single number @c val. */
} else {
}
}
/** @brief Extend the interval to include the given number. */
}
/** @brief Expand or shrink the interval in both directions by the given amount.
* After this method, the interval's length (extent) will be increased by
* <code>amount * 2</code>. Negative values can be given; they will shrink the interval.
* Shrinking by a value larger than half the interval's length will create a degenerate
* interval containing only the midpoint of the original. */
}
}
/** @brief Union the interval with another one.
* The resulting interval will contain all points of both intervals.
* It might also contain some points which didn't belong to either - this happens
* when the intervals did not have any common elements. */
}
/// @}
/// @name Operators
/// @{
//IMPL: OffsetableConcept
//TODO: rename output_type to something else in the concept
typedef C output_type;
/** @brief Offset the interval by a specified amount */
return *this;
}
/** @brief Offset the interval by the negation of the specified amount */
return *this;
}
/** @brief Return an interval mirrored about 0 */
// IMPL: AddableConcept
/** @brief Add two intervals.
* Sum is defined as the set of points that can be obtained by adding any two values
* from both operands: \f$S = \{x \in A, y \in B: x + y\}\f$ */
return *this;
}
/** @brief Subtract two intervals.
* Difference is defined as the set of points that can be obtained by subtracting
* any value from the second operand from any value from the first operand:
* \f$S = \{x \in A, y \in B: x - y\}\f$ */
// equal to *this += -o
return *this;
}
/** @brief Union two intervals.
* Note that the intersection-and-assignment operator is not defined,
* because the result of an intersection can be empty, while Interval cannot. */
unionWith(o);
return *this;
}
/** @brief Test for interval equality. */
}
/// @}
};
/** @brief Union two intervals
* @relates GenericInterval */
return a | b;
}
/**
* @brief A range of numbers that can be empty.
* @ingroup Primitives
*/
> >
{
/// @name Create optionally empty intervals of integers.
/// @{
/** @brief Create an empty interval. */
GenericOptInterval() : Base() {}
/** @brief Wrap an existing interval. */
/** @brief Create an interval containing a single point. */
/** @brief Create an interval containing a range of numbers. */
/** @brief Create a possibly empty 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 C. The given range
* may be empty.
* @param start Beginning of the range
* @param end End of the range
* @return Interval that contains all values from [start, end), or nothing if the range
* is empty. */
return ret;
}
return ret;
}
/// @}
/** @brief Check whether this interval is empty. */
/** @brief Union with another interval, gracefully handling empty ones. */
void unionWith(GenericOptInterval<C> const &a) {
if (*this) { // check that we are not empty
} else if (a) {
*this = *a;
}
}
void intersectWith(GenericOptInterval<C> const &o) {
if (o && *this) {
if (!*this) return;
if (u <= v) {
return;
}
}
}
unionWith(o);
return *this;
}
intersectWith(o);
return *this;
}
};
/** @brief Intersect two intervals and return a possibly empty range of numbers
* @relates GenericOptInterval */
return GenericOptInterval<C>(a) & GenericOptInterval<C>(b);
}
/** @brief Intersect two intervals and return a possibly empty range of numbers
* @relates GenericOptInterval */
return GenericOptInterval<C>(a) & GenericOptInterval<C>(b);
}
#ifdef _GLIBCXX_IOSTREAM
Geom::GenericInterval<C> const &I) {
return os;
}
#endif
} // namespace Geom
#endif // !LIB2GEOM_SEEN_GENERIC_INTERVAL_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :