non/spire — pull request #291 by non (2014-08-02 00:27:33+00:00)
Title: Some clean up to intervals/bounds, with a few bigger changes.

This commit is mostly to try to clean up the documentation and some
code formatting a bit. Apologies to @denisrosset -- I saw some of
my own code which I no longer like the look of and wanted to fix.

There are a few major changes, however.

One is that I did some refactoring to remove the .asInstanceOf calls.
Since this is a bit of a shift away from the previous code patterns
in Interval I wanted to explain the rationale.

Previously, the style was to always define all the logic in the parent
trait (e.g. Interval[A]). I find this style really elegant and readable.
However, there are (at least) two problems with it:

1. Broadest return type in all cases
2. Potential slowness with lots of cases

In this case #1 was causing problems. Starting from a Bounded interval,
we were losing track of the fact that lowerBound and upperBound would
return ValueBounds (since the generic implementations only guarantee
Bound[A]). I refactored Interval to require each subtype to define
those methods, allowing more precise return types.

From there, Bound[A] * Bound[A] only guarantees a Bound[A]. This was a
bit more challenging, but I added methods +~, -~, *~, and /~ which,
for two ValueBound[A] values, guarantee the result to be a ValueBound[A]
as well (they should also be a bit faster).

There's obviously a tension here -- I don't want to rewrite all the
interval code away from the current (nice) style. But in some cases
being more precise about return types (and not losing type information)
will help us have more efficient (and more direct) code.

Review by @denisrosset.