1717package com .androidplot .xy ;
1818
1919import android .graphics .Canvas ;
20+ import android .graphics .Paint ;
2021import android .graphics .PointF ;
2122import android .graphics .RectF ;
23+ import android .support .annotation .NonNull ;
2224
2325import com .androidplot .exception .PlotRenderException ;
2426import com .androidplot .ui .RenderStack ;
3638 */
3739public class FastLineAndPointRenderer extends XYSeriesRenderer <XYSeries , FastLineAndPointRenderer .Formatter > {
3840
41+ /**
42+ * A line drawn by {@link Canvas#drawLines(float[], int, int, Paint)} must be defined by at
43+ * least four points {@code x0, y0, x1, y1}
44+ */
45+ private static final int MINIMUM_NUMBER_OF_POINTS_TO_DEFINE_A_LINE = 4 ;
3946 private float [] points ;
4047 List <Integer > segmentOffsets = new ArrayList <>();
4148 List <Integer > segmentLengths = new ArrayList <>();
@@ -94,10 +101,14 @@ protected void onRender(Canvas canvas, RectF plotArea, XYSeries series, Formatte
94101 }
95102 }
96103
97- protected void drawSegment (Canvas canvas , float [] points , int offset , int len , Formatter formatter ) {
104+ protected void drawSegment (@ NonNull Canvas canvas ,
105+ @ NonNull float [] points ,
106+ int offset ,
107+ int len ,
108+ Formatter formatter ) {
98109 if (formatter .linePaint != null ) {
99110 // draw lines:
100- if (len >= 4 ) {
111+ if (len >= MINIMUM_NUMBER_OF_POINTS_TO_DEFINE_A_LINE ) {
101112 // optimization to avoid using 2x storage space to represent the full path:
102113 if ((len & 2 ) != 0 ) {
103114 canvas .drawLines (points , offset , len - 2 , formatter .linePaint );
@@ -116,7 +127,9 @@ protected void drawSegment(Canvas canvas, float[] points, int offset, int len, F
116127 }
117128
118129 @ Override
119- protected void doDrawLegendIcon (Canvas canvas , RectF rect , Formatter formatter ) {
130+ protected void doDrawLegendIcon (@ NonNull Canvas canvas ,
131+ @ NonNull RectF rect ,
132+ @ NonNull Formatter formatter ) {
120133 if (formatter .hasLinePaint ()) {
121134 canvas .drawLine (rect .left , rect .bottom , rect .right , rect .top , formatter .getLinePaint ());
122135 }
0 commit comments