@@ -10,7 +10,7 @@ import kotlin.math.abs
1010 * groups of values inside the Chart (e.g. the values for a specific line in the
1111 * LineChart, or the values of a specific group of bars in the BarChart).
1212 */
13- abstract class DataSet <T : EntryFloat >(
13+ abstract class DataSet <T : BaseEntry < Float > >(
1414 protected var entriesInternal : MutableList <T >,
1515 label : String = " "
1616) : BaseDataSet<T>(label), Serializable {
@@ -219,72 +219,55 @@ abstract class DataSet<T : EntryFloat>(
219219 while (low < high) {
220220 val m = low + (high - low) / 2
221221
222- val currentEntryFloat: EntryFloat = entriesInternal[m]
222+ val current = entriesInternal[m]
223+ val next = entriesInternal[m + 1 ]
223224
224- val nextEntryFloat: EntryFloat = entriesInternal[m + 1 ]
225-
226- val d1 = currentEntryFloat.x - xValue
227- val d2 = nextEntryFloat.x - xValue
225+ val d1 = current.x - xValue
226+ val d2 = next.x - xValue
228227 val ad1 = abs(d1)
229228 val ad2 = abs(d2)
230229
231230 if (ad2 < ad1) {
232- // [m + 1] is closer to xValue
233- // Search in a higher place
234231 low = m + 1
235232 } else if (ad1 < ad2) {
236- // [m] is closer to xValue
237- // Search in a lower place
238233 high = m
239234 } else {
240- // We have multiple sequential x-value with same distance
241-
242235 if (d1 >= 0.0 ) {
243- // Search in a lower place
244236 high = m
245237 } else if (d1 < 0.0 ) {
246- // Search in a higher place
247238 low = m + 1
248239 }
249240 }
250241
251242 closest = high
252243 }
253244
254- val closestEntryFloat : EntryFloat = entriesInternal[closest]
255- val closestXValue = closestEntryFloat .x
245+ val closestEntry = entriesInternal[closest]
246+ val closestXValue = closestEntry .x
256247 if (rounding == Rounding .UP ) {
257- // If rounding up, and found x-value is lower than specified x, and we can go upper...
258248 if (closestXValue < xValue && closest < entriesInternal.size - 1 ) {
259249 ++ closest
260250 }
261251 } else if (rounding == Rounding .DOWN ) {
262- // If rounding down, and found x-value is upper than specified x, and we can go lower...
263252 if (closestXValue > xValue && closest > 0 ) {
264253 -- closest
265254 }
266255 }
267256
268- // Search by closest to y-value
269257 if (! closestToY.isNaN()) {
270258 while (closest > 0 && entriesInternal[closest - 1 ].x == closestXValue) {
271259 closest - = 1
272260 }
273261
274- var closestYValue = closestEntryFloat .y
262+ var closestYValue = closestEntry .y
275263 var closestYIndex = closest
276264
277265 while (true ) {
278266 closest + = 1
279- if (closest >= entriesInternal.size) {
280- break
281- }
267+ if (closest >= entriesInternal.size) break
282268
283269 val value: T = entriesInternal[closest]
284-
285- if (value.x != closestXValue) {
286- break
287- }
270+ if (value.x != closestXValue) break
288271
289272 if (abs(value.y - closestToY) <= abs(closestYValue - closestToY)) {
290273 closestYValue = closestToY
0 commit comments