Skip to content

Commit 83edd74

Browse files
authored
Merge pull request #598 from AppDevNext/MoveGetNormalizedAngle
Move getNormalizedAngle
2 parents e11d4a1 + cf4bca1 commit 83edd74

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

chartLib/src/main/kotlin/info/appdev/charting/charts/PieChart.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import info.appdev.charting.renderer.PieChartRenderer
1414
import info.appdev.charting.utils.PointF
1515
import info.appdev.charting.utils.PointF.Companion.getInstance
1616
import info.appdev.charting.utils.PointF.Companion.recycleInstance
17-
import info.appdev.charting.utils.Utils
1817
import info.appdev.charting.utils.convertDpToPixel
18+
import info.appdev.charting.utils.getNormalizedAngle
1919
import java.util.Locale
2020
import java.util.Objects
2121
import kotlin.math.abs
@@ -346,7 +346,7 @@ class PieChart : PieRadarChartBase<PieData> {
346346
override fun getIndexForAngle(angle: Float): Int {
347347
// take the current angle of the chart into consideration
348348

349-
val a = Utils.getNormalizedAngle(angle - rotationAngle)
349+
val a = (angle - rotationAngle).getNormalizedAngle()
350350

351351
for (i in absoluteAngles.indices) {
352352
if (this.absoluteAngles[i] > a)

chartLib/src/main/kotlin/info/appdev/charting/charts/PieRadarChartBase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import info.appdev.charting.listener.PieRadarChartTouchListener
1616
import info.appdev.charting.utils.PointF
1717
import info.appdev.charting.utils.PointF.Companion.getInstance
1818
import info.appdev.charting.utils.PointF.Companion.recycleInstance
19-
import info.appdev.charting.utils.Utils
2019
import info.appdev.charting.utils.convertDpToPixel
20+
import info.appdev.charting.utils.getNormalizedAngle
2121
import timber.log.Timber
2222
import kotlin.math.acos
2323
import kotlin.math.cos
@@ -378,7 +378,7 @@ abstract class PieRadarChartBase<T : ChartData<out IDataSet<out Entry>>>
378378
*/
379379
set(angle) {
380380
this.rawRotationAngle = angle
381-
mRotationAngle = Utils.getNormalizedAngle(this.rawRotationAngle)
381+
mRotationAngle = this.rawRotationAngle.getNormalizedAngle()
382382
}
383383

384384
val diameter: Float

chartLib/src/main/kotlin/info/appdev/charting/charts/RadarChart.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import info.appdev.charting.highlight.RadarHighlighter
1111
import info.appdev.charting.renderer.RadarChartRenderer
1212
import info.appdev.charting.renderer.XAxisRendererRadarChart
1313
import info.appdev.charting.renderer.YAxisRendererRadarChart
14-
import info.appdev.charting.utils.Utils
1514
import info.appdev.charting.utils.convertDpToPixel
15+
import info.appdev.charting.utils.getNormalizedAngle
1616
import kotlin.math.max
1717
import kotlin.math.min
1818

@@ -203,16 +203,16 @@ class RadarChart : PieRadarChartBase<RadarData> {
203203
override fun getIndexForAngle(angle: Float): Int {
204204
// take the current angle of the chart into consideration
205205

206-
val a = Utils.getNormalizedAngle(angle - rotationAngle)
206+
val a = (angle - rotationAngle).getNormalizedAngle()
207207

208-
val sliceangle = this.sliceAngle
208+
val sliceAngle = this.sliceAngle
209209

210210
val max = mData?.maxEntryCountSet!!.entryCount
211211

212212
var index = 0
213213

214214
for (i in 0..<max) {
215-
val referenceAngle = sliceangle * (i + 1) - sliceangle / 2f
215+
val referenceAngle = sliceAngle * (i + 1) - sliceAngle / 2f
216216

217217
if (referenceAngle > a) {
218218
index = i
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package info.appdev.charting.utils
2+
3+
/**
4+
* returns an angle between 0.f < 360.f (not less than zero, less than 360)
5+
*/
6+
fun Float.getNormalizedAngle(): Float {
7+
var angle = this
8+
while (angle < 0f) {
9+
angle += 360f
10+
}
11+
12+
return angle % 360f
13+
}

chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,6 @@ object Utils {
8686
}
8787
}
8888

89-
/**
90-
* returns an angle between 0.f < 360.f (not less than zero, less than 360)
91-
*/
92-
fun getNormalizedAngle(angle: Float): Float {
93-
var angle = angle
94-
while (angle < 0f) {
95-
angle += 360f
96-
}
97-
98-
return angle % 360f
99-
}
100-
10189
private val mDrawableBoundsCache = Rect()
10290

10391
fun drawImage(canvas: Canvas, drawable: Drawable, x: Int, y: Int) {

0 commit comments

Comments
 (0)