Skip to content

Commit

Permalink
Bugfix: ranges on double and long values correctly mapped to int
Browse files Browse the repository at this point in the history
When you work with a NumberRangeModel that is initialized with double
values, setting the value range with the method setValueRange() yields
an unexpected result (a tiny range close to the minimum is selected).
The bug is in updateRange(), where the double range is transformed to an
int range from 0 to 10,000. The problem is that the multiplication with
10,000 happens *after* the intermediate result is converted to int. So,
v and e are either 0 or 10,000.
The same bug and patch should apply to NumberRangeModel that are
initialized with long values. (I did not test it.)
NumberRangeModel that are initialized with int values are not affected
by this issue, because they do not need such an transformation.
  • Loading branch information
alex-rind committed Jan 4, 2012
1 parent 87280e4 commit 952965e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/prefuse/data/query/NumberRangeModel.java
Expand Up @@ -96,8 +96,8 @@ else if ( m_type == long.class )
long lo = m_lo.longValue() - m_min.longValue();
long hi = m_hi.longValue() - m_min.longValue();

int v = 10000 * (int)( lo / range );
int e = 10000 * (int)( hi / range ) - v;
int v = (int)(10000 * lo / range );
int e = (int)(10000 * hi / range ) - v;
setRange(v, e, 0, 10000);
}
}
Expand All @@ -110,8 +110,8 @@ else if ( m_type == long.class )
double lo = m_lo.doubleValue() - m_min.doubleValue();
double hi = m_hi.doubleValue() - m_min.doubleValue();

int v = 10000 * (int)( lo / range );
int e = 10000 * (int)( hi / range ) - v;
int v = (int)(10000.0 * lo / range );
int e = (int)(10000.0 * hi / range ) - v;
setRange(v, e, 0, 10000);
}
}
Expand Down

0 comments on commit 952965e

Please sign in to comment.