Skip to content
Snippets Groups Projects
Commit f1671402 authored by Andika Naufal Hilmy's avatar Andika Naufal Hilmy
Browse files

implement add node mechanism in radar

parent 207e96c0
Branches
No related merge requests found
package radar
import kotlin.properties.Delegates
/**
* Note: Assume that node values starting from 12 o'clock clockwise
*/
class Radar (maxScale: Int, numNodes: Int) {
/** Stands for values from each node in Double */
private var maxScale = maxScale
private var numNodes = numNodes
set(value) {
field = value
nodesValues.subList(numNodes + 1, nodesValues.size - 1).clear()
}
private var nodesValues: MutableList<Double?> = MutableList(numNodes) {null}
private var overwrittenNode by Delegates.notNull<Double>()
private var overwrittenNodeIndex by Delegates.notNull<Int>()
fun addNode(index: Int, value: Double) {
if (index < numNodes) {
// check if the destination node is null or not
// if the destination node is not null, copy to overwritten node then replace with new node
nodesValues[index]?.let {
overwrittenNode = nodesValues[index]!!
overwrittenNodeIndex = index
nodesValues[index] = value
}
// else, just add
?: run {
nodesValues[index] = value
}
}
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment