generic-rect.h revision a16a494f042310ee849a6f717ffea70846f1f22c
/**
* \file
* \brief Axis-aligned rectangle
*//*
* Authors:
* Michael Sloan <mgsloan@gmail.com>
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
* Copyright 2007-2011 Authors
*
* 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.
*
* Authors of original rect class:
* Lauris Kaplinski <lauris@kaplinski.com>
* Nathan Hurst <njh@mail.csse.monash.edu.au>
* bulia byak <buliabyak@users.sf.net>
* MenTaLguY <mental@rydia.net>
*/
#ifndef LIB2GEOM_SEEN_GENERIC_RECT_H
#define LIB2GEOM_SEEN_GENERIC_RECT_H
#include <limits>
#include <boost/optional.hpp>
/**
* @brief Axis aligned, non-empty, generic rectangle.
* @ingroup Primitives
*/
: CoordTraits<C>::RectOps
{
CInterval f[2];
typedef CInterval &D1Reference;
typedef CInterval const &D1ConstReference;
/// @name Create rectangles.
/// @{
/** @brief Create a rectangle that contains only the point at (0,0). */
GenericRect() { f[X] = f[Y] = CInterval(); }
/** @brief Create a rectangle from X and Y intervals. */
f[X] = a;
f[Y] = b;
}
/** @brief Create a rectangle from two points. */
f[X] = CInterval(a[X], b[X]);
f[Y] = CInterval(a[Y], b[Y]);
}
/** @brief Create rectangle from coordinates of two points. */
}
/** @brief Create a rectangle from a range of points.
* The resulting rectangle will contain all ponts from the range.
* The return type of iterators must be convertible to Point.
* The range must not be empty. For possibly empty ranges, see OptRect.
* @param start Beginning of the range
* @param end End of the range
* @return Rectangle that contains all points from [start, end). */
}
return result;
}
/** @brief Create a rectangle from a C-style array of points it should contain. */
return result;
}
/** @brief Create rectangle from origin and dimensions. */
return result;
}
/** @brief Create rectangle from origin and dimensions. */
return result;
}
/// Create infinite rectangle.
return result;
}
/// @}
/// @name Inspect dimensions.
/// @{
/** @brief Get the corner of the rectangle with smallest coordinate values.
* In 2Geom standard coordinate system, this means upper left. */
/** @brief Get the corner of the rectangle with largest coordinate values.
* In 2Geom standard coordinate system, this means lower right. */
/** @brief Return the n-th corner of the rectangle.
* Returns corners in the direction of growing angles, starting from
* the one given by min(). For the standard coordinate system used
* in 2Geom (+Y downwards), this means clockwise starting from
* the upper left. */
switch(i % 4) {
}
}
//We should probably remove these - they're coord sys gnostic
/** @brief Return top coordinate of the rectangle (+Y is downwards). */
/** @brief Return bottom coordinate of the rectangle (+Y is downwards). */
/** @brief Return leftmost coordinate of the rectangle (+X is to the right). */
/** @brief Return rightmost coordinate of the rectangle (+X is to the right). */
/** @brief Get the horizontal extent of the rectangle. */
/** @brief Get the vertical extent of the rectangle. */
/** @brief Get the ratio of width to height of the rectangle. */
/** @brief Get rectangle's width and height as a point.
* @return Point with X coordinate corresponding to the width and the Y coordinate
* corresponding to the height of the rectangle. */
/** @brief Get the point in the geometric center of the rectangle. */
/** @brief Compute rectangle's area. */
/** @brief Check whether the rectangle has zero area. */
/** @brief Get the larger extent (width or height) of the rectangle. */
/** @brief Get the smaller extent (width or height) of the rectangle. */
/** @brief Clamp point to the rectangle. */
return result;
}
/** @brief Get the nearest point on the edge of the rectangle. */
if (!contains(p)) {
} else {
C cx = f[X].nearestEnd(p[X]);
C cy = f[Y].nearestEnd(p[Y]);
} else {
}
}
return result;
}
/// @}
/// @name Test other rectangles and points for inclusion.
/// @{
/** @brief Check whether the rectangles have any common points. */
bool intersects(GenericRect<C> const &r) const {
return f[X].intersects(r[X]) && f[Y].intersects(r[Y]);
}
/** @brief Check whether the rectangle includes all points in the given rectangle. */
bool contains(GenericRect<C> const &r) const {
}
/** @brief Check whether the rectangles have any common points.
* Empty rectangles will not intersect with any other rectangle. */
inline bool intersects(OptCRect const &r) const;
/** @brief Check whether the rectangle includes all points in the given rectangle.
* Empty rectangles will be contained in any non-empty rectangle. */
/** @brief Check whether the given point is within the rectangle. */
}
/// @}
/// @name Modify the rectangle.
/// @{
/** @brief Set the minimum X coordinate of the rectangle. */
}
/** @brief Set the maximum X coordinate of the rectangle. */
}
/** @brief Set the minimum Y coordinate of the rectangle. */
}
/** @brief Set the maximum Y coordinate of the rectangle. */
}
/** @brief Set the upper left point of the rectangle. */
f[X].setMin(p[X]);
f[Y].setMin(p[Y]);
}
/** @brief Set the lower right point of the rectangle. */
f[X].setMax(p[X]);
f[Y].setMax(p[Y]);
}
/** @brief Enlarge the rectangle to contain the given point. */
}
/** @brief Enlarge the rectangle to contain the argument. */
}
/** @brief Enlarge the rectangle to contain the argument.
* Unioning with an empty rectangle results in no changes. */
/** @brief Expand the rectangle in both directions by the specified amount.
* Note that this is different from scaling. Negative values wil shrink the
* rectangle. If <code>-amount</code> is larger than
* half of the width, the X interval will contain only the X coordinate
* of the midpoint; same for height. */
}
/** @brief Expand the rectangle in both directions.
* Note that this is different from scaling. Negative values wil shrink the
* rectangle. If <code>-x</code> is larger than
* half of the width, the X interval will contain only the X coordinate
* of the midpoint; same for height. */
void expandBy(C x, C y) {
}
/** @brief Expand the rectangle by the coordinates of the given point.
* This will expand the width by the X coordinate of the point in both directions
* and the height by Y coordinate of the point. Negative coordinate values will
* shrink the rectangle. If <code>-p[X]</code> is larger than half of the width,
* the X interval will contain only the X coordinate of the midpoint;
* same for height. */
expandBy(p[X], p[Y]);
}
/// @}
/// @name Operators
/// @{
/** @brief Offset the rectangle by a vector. */
f[X] += p[X];
f[Y] += p[Y];
return *this;
}
/** @brief Offset the rectangle by the negation of a vector. */
f[X] -= p[X];
f[Y] -= p[Y];
return *this;
}
/** @brief Union two rectangles. */
unionWith(o);
return *this;
}
unionWith(o);
return *this;
}
/** @brief Test for equality of rectangles. */
/// @}
};
/**
* @brief Axis-aligned generic rectangle that can be empty.
* @ingroup Primitives
*/
, boost::equality_comparable< typename CoordTraits<C>::OptRectType, typename CoordTraits<C>::RectType
> > > > >
{
typedef CInterval &D1Reference;
typedef CInterval const &D1ConstReference;
/// @name Create potentially empty rectangles.
/// @{
GenericOptRect() : Base() {}
/// Creates an empty OptRect when one of the argument intervals is empty.
}
// else, stay empty.
}
/** @brief Create a rectangle from a range of points.
* The resulting rectangle will contain all ponts from the range.
* If the range contains no points, the result will be an empty rectangle.
* The return type of iterators must be convertible to the corresponding
* point type (Point or IntPoint).
* @param start Beginning of the range
* @param end End of the range
* @return Rectangle that contains all points from [start, end). */
}
return result;
}
/// @}
/// @name Check other rectangles and points for inclusion.
/// @{
/** @brief Check for emptiness. */
/** @brief Check whether the rectangles have any common points.
* Empty rectangles will not intersect with any other rectangle. */
/** @brief Check whether the rectangle includes all points in the given rectangle.
* Empty rectangles will be contained in any non-empty rectangle. */
/** @brief Check whether the rectangles have any common points.
* Empty rectangles will not intersect with any other rectangle.
* Two empty rectangles will not intersect each other. */
/** @brief Check whether the rectangle includes all points in the given rectangle.
* Empty rectangles will be contained in any non-empty rectangle.
* An empty rectangle will not contain other empty rectangles. */
/** @brief Check whether the given point is within the rectangle.
* An empty rectangle will not contain any points. */
/// @}
/// @name Modify the potentially empty rectangle.
/// @{
/** @brief Enlarge the rectangle to contain the argument.
* If this rectangle is empty, after callng this method it will
* be equal to the argument. */
if (*this) {
} else {
*this = b;
}
}
/** @brief Enlarge the rectangle to contain the argument.
* Unioning with an empty rectangle results in no changes.
* If this rectangle is empty, after calling this method it will
* be equal to the argument. */
if (b) unionWith(*b);
}
/** @brief Leave only the area overlapping with the argument.
* If the rectangles do not have any points in common, after calling
* this method the rectangle will be empty. */
void intersectWith(CRect const &b) {
if (!*this) return;
if (x && y) {
} else {
}
}
/** @brief Leave only the area overlapping with the argument.
* If the argument is empty or the rectangles do not have any points
* in common, after calling this method the rectangle will be empty. */
void intersectWith(OptCRect const &b) {
if (b) {
intersectWith(*b);
} else {
}
}
/** @brief Create or enlarge the rectangle to contain the given point.
* If the rectangle is empty, after calling this method it will be non-empty
* and it will contain only the given point. */
if (*this) {
} else {
}
}
/// @}
/// @name Operators
/// @{
/** @brief Union with @a b */
unionWith(b);
return *this;
}
/** @brief Intersect with @a b */
intersectWith(b);
return *this;
}
/** @brief Intersect with @a b */
intersectWith(b);
return *this;
}
/** @brief Test for equality.
* All empty rectangles are equal. */
}
if (!*this) return false;
}
/// @}
};
if (b) {
unionWith(*b);
}
}
return r && intersects(*r);
}
return !r || contains(*r);
}
#ifdef _GLIBCXX_IOSTREAM
return out;
}
#endif
} // end namespace Geom
#endif // LIB2GEOM_SEEN_RECT_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 :