Skip to content

Commit

Permalink
ttools: fix plan bug in LabelPlotter
Browse files Browse the repository at this point in the history
A plan was being construed as matching even when the value type of the
associated cache map did not match (String instead of DepthString).
Actually, I'm not sure how this could happen, because I thought that
2D plots would always use String and 3D plots would always use DepthString,
but the fix, which involves storing Class<T> in the relevant places and
testing for equality, is harmless in any case.
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent 7bb88cc commit 025a878
Showing 1 changed file with 17 additions and 8 deletions.
Expand Up @@ -113,6 +113,7 @@ private static abstract class LabelDrawing<T> implements Drawing {
final DataSpec dataSpec_;
final LabelStyle style_;
final Surface surface_;
final Class<T> clazz_;
final DataGeom geom_;
final int icLabel_;

Expand All @@ -123,13 +124,15 @@ private static abstract class LabelDrawing<T> implements Drawing {
* @param dataSpec full data specification
* @param style style
* @param surface plot surface
* @param clazz parameterising class
*/
LabelDrawing( DataGeom geom, DataSpec dataSpec, LabelStyle style,
Surface surface ) {
Surface surface, Class<T> clazz ) {
geom_ = geom;
dataSpec_ = dataSpec;
style_ = style;
surface_ = surface;
clazz_ = clazz;
icLabel_ = geom.getPosCoords().length;
}

Expand All @@ -155,12 +158,12 @@ public Object calculatePlan( Object[] knownPlans,
Object plan = knownPlans[ i ];
if ( plan instanceof LabelPlan &&
((LabelPlan) plan).matches( geom_, dataSpec_,
surface_ ) ) {
surface_, clazz_ ) ) {
return plan;
}
}
Map<Point,T> map = createMap( dataStore );
return new LabelPlan<T>( geom_, dataSpec_, surface_, map );
return new LabelPlan<T>( geom_, dataSpec_, surface_, map, clazz_ );
}

public void paintData( Object plan, Paper paper, DataStore dataStore ) {
Expand Down Expand Up @@ -188,7 +191,7 @@ private static class LabelDrawing2D extends LabelDrawing<String> {
*/
LabelDrawing2D( DataGeom geom, DataSpec dataSpec, LabelStyle style,
Surface surface, PaperType2D paperType ) {
super( geom, dataSpec, style, surface );
super( geom, dataSpec, style, surface, String.class );
paperType_ = paperType;
}

Expand Down Expand Up @@ -245,7 +248,7 @@ private static class LabelDrawing3D extends LabelDrawing<DepthString> {
*/
LabelDrawing3D( DataGeom geom, DataSpec dataSpec, LabelStyle style,
Surface surface, PaperType3D paperType ) {
super( geom, dataSpec, style, surface );
super( geom, dataSpec, style, surface, DepthString.class );
paperType_ = paperType;
}

Expand Down Expand Up @@ -316,6 +319,7 @@ private static class LabelPlan<T> {
final DataSpec dataSpec_;
final Surface surface_;
final Map<Point,T> map_;
final Class<T> clazz_;

/**
* Constructor.
Expand All @@ -325,13 +329,15 @@ private static class LabelPlan<T> {
* @param surface plot surface
* @param map plan payload - a map from screen position to
* placeable label
* @param clazz class parameterising map values
*/
LabelPlan( DataGeom geom, DataSpec dataSpec, Surface surface,
Map<Point,T> map ) {
Map<Point,T> map, Class<T> clazz ) {
geom_ = geom;
dataSpec_ = dataSpec;
surface_ = surface;
map_ = map;
clazz_ = clazz;
}

/**
Expand All @@ -341,11 +347,14 @@ private static class LabelPlan<T> {
* @param geom data geom
* @param dataSpec data specfication
* @param surface plot surface
* @param parameterising class
*/
boolean matches( DataGeom geom, DataSpec dataSpec, Surface surface ) {
boolean matches( DataGeom geom, DataSpec dataSpec, Surface surface,
Class clazz ) {
return geom.equals( geom_ )
&& dataSpec.equals( dataSpec_ )
&& surface.equals( surface_ );
&& surface.equals( surface_ )
&& clazz.equals( clazz_ );
}
}

Expand Down

0 comments on commit 025a878

Please sign in to comment.