X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Finterval.hh;h=8160b37c2ca4b943cca8cbd4805642e3e0ca462a;hb=47db9a3883d726ca53e2133a3b2298f78dd6a32e;hp=2d3bf4128114466bced1d52c9eb6c69350018410;hpb=2c22efe5a46a37065b10c3f51c5d7db00d07d318;p=lilypond.git
diff --git a/flower/include/interval.hh b/flower/include/interval.hh
index 2d3bf41281..8160b37c2c 100644
--- a/flower/include/interval.hh
+++ b/flower/include/interval.hh
@@ -1,44 +1,58 @@
/*
- interval.hh -- part of flowerlib
+ This file is part of LilyPond, the GNU music typesetter.
- (c) 1996--2005 Han-Wen Nienhuys
+ Copyright (C) 1996--2015 Han-Wen Nienhuys
+
+ LilyPond is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LilyPond is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LilyPond. If not, see .
*/
#ifndef INTERVAL_HH
#define INTERVAL_HH
+#include
+
#include "flower-proto.hh"
#include "drul-array.hh"
/* A T interval. This represents the closed interval [left,right].
No invariants. T must be a totally ordered ring (with division, anyway ..)
- At instantiation, the function infinity () has to be defined explicitely. */
+ At instantiation, the function infinity () has to be defined explicitly. */
template
struct Interval_t : public Drul_array
{
- Drul_array::elem;
- Drul_array::elem_ref;
+ using Drul_array::at;
static T infinity ();
- static String T_to_string (T arg);
+ static string T_to_string (T arg);
T center () const;
void translate (T t)
{
- elem_ref (LEFT) += t;
- elem_ref (RIGHT) += t;
+ at (LEFT) += t;
+ at (RIGHT) += t;
}
void widen (T t)
{
- elem_ref (LEFT) -= t;
- elem_ref (RIGHT) += t;
+ at (LEFT) -= t;
+ at (RIGHT) += t;
}
T distance (T t) const
{
- if (t > elem (RIGHT))
- return T (t - elem (RIGHT));
- else if (t < elem (LEFT))
- return T (elem (LEFT) - t);
+ if (t > at (RIGHT))
+ return T (t - at (RIGHT));
+ else if (t < at (LEFT))
+ return T (at (LEFT) - t);
else
return T (0);
}
@@ -50,20 +64,22 @@ struct Interval_t : public Drul_array
void intersect (Interval_t h);
void add_point (T p)
{
- elem_ref (LEFT) = min (elem (LEFT), p);
- elem_ref (RIGHT) = max (elem (RIGHT), p);
+ at (LEFT) = min (at (LEFT), p);
+ at (RIGHT) = max (at (RIGHT), p);
}
T length () const;
+
+ // Returns RIGHT - LEFT, even if the interval is empty.
T delta () const;
void set_empty ();
void set_full ();
- /*
- TODO: strip hungarian suffix.
- */
+ void unite_disjoint (Interval_t h, T padding, Direction d);
+ Interval_t union_disjoint (Interval_t h, T padding, Direction d) const;
+
bool is_empty () const
{
- return elem (LEFT) > elem (RIGHT);
+ return at (LEFT) > at (RIGHT);
}
bool superset (Interval_t const &) const;
Interval_t ()
@@ -86,48 +102,44 @@ struct Interval_t : public Drul_array
Interval_t &operator += (T r)
{
- elem_ref (LEFT) += r;
- elem_ref (RIGHT) += r;
+ at (LEFT) += r;
+ at (RIGHT) += r;
return *this;
}
Interval_t &operator *= (T r)
{
if (!is_empty ())
{
- elem_ref (LEFT) *= r;
- elem_ref (RIGHT) *= r;
- if (r < T (0))
- swap ();
+ at (LEFT) *= r;
+ at (RIGHT) *= r;
+ if (r < T (0))
+ swap ();
}
return *this;
}
- Real linear_combination (Real x) const
- {
- Drul_array da (elem (LEFT), elem (RIGHT));
- return ::linear_combination (da, x);
- }
- String to_string () const;
+ Real linear_combination (Real x) const;
+ string to_string () const;
- bool contains (T r);
+ bool contains (T r) const;
void negate ()
{
- T r = -elem (LEFT);
- T l = -elem (RIGHT);
- elem_ref (LEFT) = l;
- elem_ref (RIGHT) = r;
+ T r = -at (LEFT);
+ T l = -at (RIGHT);
+ at (LEFT) = l;
+ at (RIGHT) = r;
}
void swap ()
{
- T t = elem (LEFT);
- elem_ref (LEFT) = elem (RIGHT);
- elem_ref (RIGHT) = t;
+ T t = at (LEFT);
+ at (LEFT) = at (RIGHT);
+ at (RIGHT) = t;
}
- static int left_comparison (Interval_t const &a, Interval_t const &b)
+ static bool left_less (Interval_t const &a, Interval_t const &b)
{
- return sign (a[LEFT] - b[RIGHT]);
+ return a[LEFT] < b[LEFT];
}
};
@@ -212,11 +224,11 @@ inline T
Interval_t::center () const
{
assert (!is_empty ());
- return (elem (LEFT) + elem (RIGHT)) / T (2);
+ return (at (LEFT) + at (RIGHT)) / T (2);
}
typedef Interval_t Interval;
-typedef Interval_t Slice; // weird name
+typedef Interval_t Slice; // weird name
#endif // INTERVAL_HH