summaryrefslogtreecommitdiffstats
path: root/src/2geom/interval.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/interval.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/interval.h')
-rw-r--r--src/2geom/interval.h39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/2geom/interval.h b/src/2geom/interval.h
index 1714435be..09ea46923 100644
--- a/src/2geom/interval.h
+++ b/src/2geom/interval.h
@@ -91,19 +91,23 @@ public:
}
/// @}
- /// @name Inspect endpoints.
+ /// @name Inspect contained values.
/// @{
- /** @brief Access endpoints by value.
- * @deprecated Use min() and max() instead */
- Coord operator[](unsigned i) const { return _b[i]; }
- /** @brief Access endpoints by reference.
- * @deprecated Use min() and max() instead
- * @todo Remove Interval index operator, which can be used to break the invariant */
- Coord& operator[](unsigned i) { return _b[i]; }
-
+ /** @brief Check whether both endpoints are finite. */
bool isFinite() const {
return IS_FINITE(min()) && IS_FINITE(max());
}
+ /** @brief Map the interval [0,1] onto this one.
+ * This method simply performs 1D linear interpolation between endpoints. */
+ Coord valueAt(Coord t) {
+ return lerp(t, min(), max());
+ }
+ /** @brief Find closest time in [0,1] that maps to the given value. */
+ Coord nearestTime(Coord t) {
+ if (t < min()) return 0;
+ if (t > max()) return 1;
+ return (t - min()) / extent();
+ }
/// @}
/// @name Test coordinates and other intervals for inclusion.
@@ -114,7 +118,16 @@ public:
/** @brief Check whether the interior of the interval includes the given interval.
* Interior means all numbers in the interval except its ends. */
bool interiorContains(Interval const &val) const { return min() < val.min() && val.max() < max(); }
- /** @brief Check whether the interiors of the intervals have any common elements. A single point in common is not considered an intersection. */
+ /// Check whether the number is contained in the union of the interior and the lower boundary.
+ bool lowerContains(Coord val) { return min() <= val && val < max(); }
+ /// Check whether the given interval is contained in the union of the interior and the lower boundary.
+ bool lowerContains(Interval const &val) const { return min() <= val.min() && val.max() < max(); }
+ /// Check whether the number is contained in the union of the interior and the upper boundary.
+ bool upperContains(Coord val) { return min() < val && val <= max(); }
+ /// Check whether the given interval is contained in the union of the interior and the upper boundary.
+ bool upperContains(Interval const &val) const { return min() < val.min() && val.max() <= max(); }
+ /** @brief Check whether the interiors of the intervals have any common elements.
+ * A single point in common is not considered an intersection. */
bool interiorIntersects(Interval const &val) const {
return std::max(min(), val.min()) < std::min(max(), val.max());
}
@@ -125,16 +138,18 @@ public:
// IMPL: ScalableConcept
/** @brief Scale an interval */
Interval &operator*=(Coord s) {
+ using std::swap;
_b[0] *= s;
_b[1] *= s;
- if(s < 0) std::swap(_b[0], _b[1]);
+ if(s < 0) swap(_b[0], _b[1]);
return *this;
}
/** @brief Scale an interval by the inverse of the specified value */
Interval &operator/=(Coord s) {
+ using std::swap;
_b[0] /= s;
_b[1] /= s;
- if(s < 0) std::swap(_b[0], _b[1]);
+ if(s < 0) swap(_b[0], _b[1]);
return *this;
}
/** @brief Multiply two intervals.