diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieChart.kt index 80ed6e0b5..9635d3129 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieChart.kt @@ -14,8 +14,8 @@ import info.appdev.charting.renderer.PieChartRenderer import info.appdev.charting.utils.PointF import info.appdev.charting.utils.PointF.Companion.getInstance import info.appdev.charting.utils.PointF.Companion.recycleInstance -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.getNormalizedAngle import java.util.Locale import java.util.Objects import kotlin.math.abs @@ -346,7 +346,7 @@ class PieChart : PieRadarChartBase { override fun getIndexForAngle(angle: Float): Int { // take the current angle of the chart into consideration - val a = Utils.getNormalizedAngle(angle - rotationAngle) + val a = (angle - rotationAngle).getNormalizedAngle() for (i in absoluteAngles.indices) { if (this.absoluteAngles[i] > a) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt index a08d5fa2e..c859bcb47 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt @@ -16,8 +16,8 @@ import info.appdev.charting.listener.PieRadarChartTouchListener import info.appdev.charting.utils.PointF import info.appdev.charting.utils.PointF.Companion.getInstance import info.appdev.charting.utils.PointF.Companion.recycleInstance -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.getNormalizedAngle import timber.log.Timber import kotlin.math.acos import kotlin.math.cos @@ -378,7 +378,7 @@ abstract class PieRadarChartBase>> */ set(angle) { this.rawRotationAngle = angle - mRotationAngle = Utils.getNormalizedAngle(this.rawRotationAngle) + mRotationAngle = this.rawRotationAngle.getNormalizedAngle() } val diameter: Float diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/RadarChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/RadarChart.kt index 25d42d8bf..8570678a2 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/RadarChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/RadarChart.kt @@ -11,8 +11,8 @@ import info.appdev.charting.highlight.RadarHighlighter import info.appdev.charting.renderer.RadarChartRenderer import info.appdev.charting.renderer.XAxisRendererRadarChart import info.appdev.charting.renderer.YAxisRendererRadarChart -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.getNormalizedAngle import kotlin.math.max import kotlin.math.min @@ -203,16 +203,16 @@ class RadarChart : PieRadarChartBase { override fun getIndexForAngle(angle: Float): Int { // take the current angle of the chart into consideration - val a = Utils.getNormalizedAngle(angle - rotationAngle) + val a = (angle - rotationAngle).getNormalizedAngle() - val sliceangle = this.sliceAngle + val sliceAngle = this.sliceAngle val max = mData?.maxEntryCountSet!!.entryCount var index = 0 for (i in 0.. a) { index = i diff --git a/chartLib/src/main/kotlin/info/appdev/charting/utils/NumberUtils.kt b/chartLib/src/main/kotlin/info/appdev/charting/utils/NumberUtils.kt new file mode 100644 index 000000000..fb7570838 --- /dev/null +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/NumberUtils.kt @@ -0,0 +1,13 @@ +package info.appdev.charting.utils + +/** + * returns an angle between 0.f < 360.f (not less than zero, less than 360) + */ +fun Float.getNormalizedAngle(): Float { + var angle = this + while (angle < 0f) { + angle += 360f + } + + return angle % 360f +} diff --git a/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt b/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt index fe7f04800..3606c3b87 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt @@ -86,18 +86,6 @@ object Utils { } } - /** - * returns an angle between 0.f < 360.f (not less than zero, less than 360) - */ - fun getNormalizedAngle(angle: Float): Float { - var angle = angle - while (angle < 0f) { - angle += 360f - } - - return angle % 360f - } - private val mDrawableBoundsCache = Rect() fun drawImage(canvas: Canvas, drawable: Drawable, x: Int, y: Int) {