Skip to content

Commit 790288e

Browse files
committed
Use Math.nextUp
1 parent 6e1c909 commit 790288e

File tree

5 files changed

+32
-38
lines changed

5 files changed

+32
-38
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import kotlin.math.abs
1212
import kotlin.math.ceil
1313
import kotlin.math.floor
1414
import kotlin.math.log10
15+
import kotlin.math.nextUp
1516
import kotlin.math.pow
1617

1718
/**
@@ -180,7 +181,10 @@ abstract class AxisRenderer(
180181
first -= interval
181182
}
182183

183-
val last = if (interval == 0.0) 0.0 else Utils.nextUp(floor(max / interval) * interval)
184+
val last = if (interval == 0.0)
185+
0.0
186+
else
187+
(floor(max / interval) * interval).nextUp()
184188

185189
var f: Double
186190

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ open class XAxisRenderer(
8080
xAxis.labelRotationAngle
8181
)
8282

83-
8483
xAxis.mLabelWidth = labelRotatedSize.width.roundToInt()
8584
xAxis.mLabelHeight = labelRotatedSize.height.roundToInt()
8685

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererRadarChart.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import kotlin.math.abs
1111
import kotlin.math.ceil
1212
import kotlin.math.floor
1313
import kotlin.math.log10
14+
import kotlin.math.nextUp
1415
import kotlin.math.pow
1516

1617
class YAxisRendererRadarChart(viewPortHandler: ViewPortHandler, yAxis: YAxis, private val chart: RadarChart) : YAxisRenderer(viewPortHandler, yAxis, null) {
@@ -77,7 +78,7 @@ class YAxisRendererRadarChart(viewPortHandler: ViewPortHandler, yAxis: YAxis, pr
7778
first -= interval
7879
}
7980

80-
val last = if (interval == 0.0) 0.0 else Utils.nextUp(floor(max / interval) * interval)
81+
val last = if (interval == 0.0) 0.0 else (floor(max / interval) * interval).nextUp()
8182

8283
var f: Double
8384

@@ -137,9 +138,9 @@ class YAxisRendererRadarChart(viewPortHandler: ViewPortHandler, yAxis: YAxis, pr
137138
override fun renderAxisLabels(canvas: Canvas) {
138139
if (!yAxis.isEnabled || !yAxis.isDrawLabelsEnabled) return
139140

140-
paintAxisLabels!!.setTypeface(yAxis.typeface)
141-
paintAxisLabels!!.textSize = yAxis.textSize
142-
paintAxisLabels!!.color = yAxis.textColor
141+
paintAxisLabels.typeface = yAxis.typeface
142+
paintAxisLabels.textSize = yAxis.textSize
143+
paintAxisLabels.color = yAxis.textColor
143144

144145
val center = chart.centerOffsets
145146
val pOut = MPPointF.getInstance(0f, 0f)
@@ -160,7 +161,7 @@ class YAxisRendererRadarChart(viewPortHandler: ViewPortHandler, yAxis: YAxis, pr
160161

161162
val label = yAxis.getFormattedLabel(j)
162163

163-
canvas.drawText(label, pOut.x + xOffset, pOut.y, paintAxisLabels!!)
164+
canvas.drawText(label, pOut.x + xOffset, pOut.y, paintAxisLabels)
164165
}
165166
MPPointF.recycleInstance(center)
166167
MPPointF.recycleInstance(pOut)
@@ -182,9 +183,9 @@ class YAxisRendererRadarChart(viewPortHandler: ViewPortHandler, yAxis: YAxis, pr
182183

183184
if (!l.isEnabled) continue
184185

185-
limitLinePaint!!.color = l.lineColor
186-
limitLinePaint!!.setPathEffect(l.dashPathEffect)
187-
limitLinePaint!!.strokeWidth = l.lineWidth
186+
limitLinePaint.color = l.lineColor
187+
limitLinePaint.pathEffect = l.dashPathEffect
188+
limitLinePaint.strokeWidth = l.lineWidth
188189

189190
val r = (l.limit - chart.yChartMin) * factor
190191

@@ -200,7 +201,7 @@ class YAxisRendererRadarChart(viewPortHandler: ViewPortHandler, yAxis: YAxis, pr
200201
}
201202
limitPath.close()
202203

203-
canvas.drawPath(limitPath, limitLinePaint!!)
204+
canvas.drawPath(limitPath, limitLinePaint)
204205
}
205206
MPPointF.recycleInstance(center)
206207
MPPointF.recycleInstance(pOut)

MPChartLib/src/main/java/com/github/mikephil/charting/utils/Utils.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ public static float roundToNextSignificant(double number) {
208208
* @return
209209
*/
210210
public static int getDecimals(float number) {
211-
212211
float i = roundToNextSignificant(number);
213212

214213
if (Float.isInfinite(i)) {
@@ -218,22 +217,6 @@ public static int getDecimals(float number) {
218217
return (int) Math.ceil(-Math.log10(i)) + 2;
219218
}
220219

221-
/**
222-
* Replacement for the Math.nextUp(...) method that is only available in
223-
* HONEYCOMB and higher.
224-
*
225-
* @param d
226-
* @return
227-
*/
228-
public static double nextUp(double d) {
229-
if (d == Double.POSITIVE_INFINITY) {
230-
return d;
231-
} else {
232-
d += 0.0d;
233-
return Double.longBitsToDouble(Double.doubleToRawLongBits(d) + ((d >= 0.0d) ? +1L : -1L));
234-
}
235-
}
236-
237220
/**
238221
* Returns a recyclable MPPointF instance.
239222
* Calculates the position around a center point, depending on the distance
@@ -245,7 +228,6 @@ public static double nextUp(double d) {
245228
* @return
246229
*/
247230
public static MPPointF getPosition(MPPointF center, float dist, float angle) {
248-
249231
MPPointF p = MPPointF.getInstance(0, 0);
250232
getPosition(center, dist, angle, p);
251233
return p;
@@ -256,8 +238,7 @@ public static void getPosition(MPPointF center, float dist, float angle, MPPoint
256238
outputPoint.y = (float) (center.y + dist * Math.sin(Math.toRadians(angle)));
257239
}
258240

259-
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev,
260-
VelocityTracker tracker) {
241+
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev, VelocityTracker tracker) {
261242

262243
// Check the dot product of current velocities.
263244
// If the pointer that left was opposing another velocity vector, clear.
@@ -335,7 +316,7 @@ public static void drawImage(Canvas canvas,
335316
private static final Rect mDrawTextRectBuffer = new Rect();
336317
private static final Paint.FontMetrics mFontMetricsBuffer = new Paint.FontMetrics();
337318

338-
public static void drawXAxisValue(Canvas c, String text, float x, float y,
319+
public static void drawXAxisValue(Canvas canvas, String text, float x, float y,
339320
Paint paint,
340321
MPPointF anchor, float angleDegrees) {
341322

@@ -378,13 +359,13 @@ public static void drawXAxisValue(Canvas c, String text, float x, float y,
378359
FSize.recycleInstance(rotatedSize);
379360
}
380361

381-
c.save();
382-
c.translate(translateX, translateY);
383-
c.rotate(angleDegrees);
362+
canvas.save();
363+
canvas.translate(translateX, translateY);
364+
canvas.rotate(angleDegrees);
384365

385-
c.drawText(text, drawOffsetX, drawOffsetY, paint);
366+
canvas.drawText(text, drawOffsetX, drawOffsetY, paint);
386367

387-
c.restore();
368+
canvas.restore();
388369
} else {
389370
if (anchor.x != 0.f || anchor.y != 0.f) {
390371

@@ -395,7 +376,7 @@ public static void drawXAxisValue(Canvas c, String text, float x, float y,
395376
drawOffsetX += x;
396377
drawOffsetY += y;
397378

398-
c.drawText(text, drawOffsetX, drawOffsetY, paint);
379+
canvas.drawText(text, drawOffsetX, drawOffsetY, paint);
399380
}
400381

401382
paint.setTextAlign(originalTextAlign);

MPChartLib/src/main/java/com/github/mikephil/charting/utils/UtilsKt.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ package com.github.mikephil.charting.utils
22

33
import android.content.Context
44
import android.os.Build
5+
import android.util.Log.d
6+
import java.lang.Double
7+
import kotlin.Boolean
8+
import kotlin.Char
9+
import kotlin.CharArray
10+
import kotlin.Float
11+
import kotlin.Int
12+
import kotlin.String
13+
import kotlin.code
514

615
fun getSDKInt() = Build.VERSION.SDK_INT
716

0 commit comments

Comments
 (0)