interval.h revision 7bda77e763c0af49270427593108b66455dfd125
/**
* \file
* \brief Simple closed interval class
*//*
* Copyright 2007 Michael Sloan <mgsloan@gmail.com>
*
* Lauris Kaplinski <lauris@kaplinski.com>
* Nathan Hurst <njh@mail.csse.monash.edu.au>
* bulia byak <buliabyak@users.sf.net>
* MenTaLguY <mental@rydia.net>
*
* 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, output 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_INTERVAL_H
#define LIB2GEOM_SEEN_INTERVAL_H
#include <boost/optional.hpp>
#include <boost/operators.hpp>
/**
* @brief Range of real numbers that is never empty.
*
* Intervals are closed ranges \f$[a, b]\f$, which means they include their endpoints.
* To use them as open ranges, you can use the interiorContains() methods.
*
* @ingroup Primitives
*/
{
/// @name Create intervals.
/// @{
/** @brief Create an interval that contains only zero. */
Interval() {}
/** @brief Create an interval that contains a single point. */
/** @brief Create an interval that contains all points between @c u and @c v. */
/** @brief Convert from integer interval */
/** @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 Coord. The given range
* must not be empty. For potentially empty ranges, see OptInterval.
* @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. */
return result;
}
/// @}
/// @name Inspect endpoints.
/// @{
/** @brief Access endpoints by value.
* @deprecated Use min() and max() instead */
/** @brief Access endpoints by reference.
* @deprecated Use min() and max() instead
* @todo Remove Interval index operator, which can be used to break the invariant */
bool isFinite() const {
}
/// @}
/// @name Test coordinates and other intervals for inclusion.
/// @{
/** @brief Check whether the interior of the interval includes this number.
* Interior means all numbers in the interval except its ends. */
/** @brief Check whether the interior of the interval includes the given interval.
* Interior means all numbers in the interval except its ends. */
/** @brief Check whether the interiors of the intervals have any common elements. */
}
/// @}
/// @name Operators
/// @{
// IMPL: ScalableConcept
/** @brief Scale an interval */
_b[0] *= s;
_b[1] *= s;
return *this;
}
/** @brief Scale an interval by the inverse of the specified value */
_b[0] /= s;
_b[1] /= s;
return *this;
}
/** @brief 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:
* \f$S = \{x \in A, y \in B: x * y\}\f$ */
// TODO implement properly
return *this;
}
}
}
/// @}
/// @name Rounding to integer values
/// @{
/** @brief Return the smallest integer interval which contains this one. */
IntInterval roundOutwards() const {
return ret;
}
/** @brief Return the largest integer interval which is contained in this one. */
OptIntInterval roundInwards() const {
if (u > v) { OptIntInterval e; return e; }
IntInterval ret(u, v);
return ret;
}
/// @}
};
/**
* @brief Range of real numbers that can be empty.
* @ingroup Primitives
*/
{
/// @name Create optionally empty intervals.
/// @{
/** @brief Create an empty interval. */
OptInterval() : Base() {}
/** @brief Wrap an existing interval. */
/** @brief Create an interval containing a single point. */
/** @brief Create an interval containing a range of numbers. */
/** @brief Promote from IntInterval. */
/** @brief Promote from OptIntInterval. */
}
};
// functions required for Python bindings
{
Interval r = a | b;
return r;
}
{
OptInterval r = a & b;
return r;
}
} // end namespace Geom
#endif //SEEN_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 :