![JAR search and dependency download from the Maven repository](/logo.png)
commonMain.ru.casperix.math.array.float32.FloatBasedArray.kt Maven / Gradle / Ivy
package ru.casperix.math.array.float32
import ru.casperix.math.array.MutableArray1D
import ru.casperix.math.iteration.map
class FloatBasedArray(val array: FloatArray, private val codec: FloatCodec) :
MutableArray1D {
private val floatsPerRecord = codec.floatsPerRecord
override val size = array.size / floatsPerRecord
constructor(recordsAmount: Int, codec: FloatCodec) : this(
FloatArray(recordsAmount * codec.floatsPerRecord),
codec
)
init {
if (array.size % floatsPerRecord != 0) {
throw Exception("size: ${array.size}; floatsPerVertex: $floatsPerRecord. Not compatibled")
}
}
override operator fun get(index: Int): Record {
val offset = index * floatsPerRecord
val pixel = array.sliceArray(offset until offset + floatsPerRecord)
return codec.decode(pixel)
}
override operator fun set(index: Int, value: Record) {
val pixel = codec.encode(value)
val offset = index * floatsPerRecord
pixel.copyInto(array, offset)
}
override fun iterator(): Iterator {
return (0 until size).iterator().map { get(it) }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy