summaryrefslogtreecommitdiffstats
path: root/src/2geom/generic-rect.h
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2015-04-27 23:39:29 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2015-04-27 23:39:29 +0000
commitc883d7627a479c8c5b6a9f77b9841fa5631572ad (patch)
treefba1186e26a8cc85a1b0728425bef6f2e9aeccd9 /src/2geom/generic-rect.h
parentextensions. ink2canvas.py - do not parse html comments. (Bug 1446204) (diff)
downloadinkscape-c883d7627a479c8c5b6a9f77b9841fa5631572ad.tar.gz
inkscape-c883d7627a479c8c5b6a9f77b9841fa5631572ad.zip
2Geom sync - initial commit
(bzr r14059.2.1)
Diffstat (limited to 'src/2geom/generic-rect.h')
-rw-r--r--src/2geom/generic-rect.h36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/2geom/generic-rect.h b/src/2geom/generic-rect.h
index 9ad0e60b0..f7d722757 100644
--- a/src/2geom/generic-rect.h
+++ b/src/2geom/generic-rect.h
@@ -64,6 +64,10 @@ class GenericRect
protected:
CInterval f[2];
public:
+ typedef CInterval D1Value;
+ typedef CInterval &D1Reference;
+ typedef CInterval const &D1ConstReference;
+
/// @name Create rectangles.
/// @{
/** @brief Create a rectangle that contains only the point at (0,0). */
@@ -180,12 +184,34 @@ public:
/** @brief Compute rectangle's area. */
C area() const { return f[X].extent() * f[Y].extent(); }
/** @brief Check whether the rectangle has zero area. */
- bool hasZeroArea() const { return (area() == 0); }
+ bool hasZeroArea() const { return f[X].isSingular() || f[Y].isSingular(); }
/** @brief Get the larger extent (width or height) of the rectangle. */
C maxExtent() const { return std::max(f[X].extent(), f[Y].extent()); }
/** @brief Get the smaller extent (width or height) of the rectangle. */
C minExtent() const { return std::min(f[X].extent(), f[Y].extent()); }
+
+ /** @brief Clamp point to the rectangle. */
+ CPoint clamp(CPoint const &p) const {
+ CPoint result(f[X].clamp(p[X]), f[Y].clamp(p[Y]));
+ return result;
+ }
+ /** @brief Get the nearest point on the edge of the rectangle. */
+ CPoint nearestEdgePoint(CPoint const &p) const {
+ CPoint result = p;
+ if (!contains(p)) {
+ result = clamp(p);
+ } else {
+ C cx = f[X].nearestEnd(p[X]);
+ C cy = f[Y].nearestEnd(p[Y]);
+ if (std::abs(cx - p[X]) <= std::abs(cy - p[Y])) {
+ result[X] = cx;
+ } else {
+ result[Y] = cy;
+ }
+ }
+ return result;
+ }
/// @}
/// @name Test other rectangles and points for inclusion.
@@ -328,6 +354,10 @@ class GenericOptRect
typedef typename CoordTraits<C>::OptRectType OptCRect;
typedef boost::optional<CRect> Base;
public:
+ typedef CInterval D1Value;
+ typedef CInterval &D1Reference;
+ typedef CInterval const &D1ConstReference;
+
/// @name Create potentially empty rectangles.
/// @{
GenericOptRect() : Base() {}
@@ -483,13 +513,13 @@ inline bool GenericRect<C>::contains(OptCRect const &r) const {
return !r || contains(*r);
}
-//#ifdef _GLIBCXX_IOSTREAM
+#ifdef _GLIBCXX_IOSTREAM
template <typename C>
inline std::ostream &operator<<(std::ostream &out, GenericRect<C> const &r) {
out << "X: " << r[X] << " Y: " << r[Y];
return out;
}
-//#endif
+#endif
} // end namespace Geom