<commit_before>package cc.clv.android.ca2d.graphics

import cc.clv.android.ca2d.World

class WorldModel(world: World) {
    private val world = world
    val maxVertexCount: Int get() = world.width * world.height * 6

    fun vertexAttribSet(): VertexAttribSet {
        val cellWidth = 2.0f / world.width.toFloat()
        val cellHeight = 2.0f / world.height.toFloat()

        var positions = floatArrayOf()
        var colors = floatArrayOf()

        for (y in (0..(world.height - 1))) {
            for (x in (0..(world.width - 1))) {
                val condition = world.cells[y * world.width + x]

                if (condition == 0.toByte()) {
                    continue
                }

                val posA = floatArrayOf(-1.0f + cellWidth * x.toFloat(), -1.0f + cellHeight * y.toFloat())
                val posB = floatArrayOf(-1.0f + cellWidth * x.toFloat(), -1.0f + cellHeight * (y + 1).toFloat())
                val posC = floatArrayOf(-1.0f + cellWidth * (x + 1).toFloat(), -1.0f + cellHeight * y.toFloat())
                val posD = floatArrayOf(-1.0f + cellWidth * (x + 1).toFloat(), -1.0f + cellHeight * (y + 1).toFloat())

                positions += posA
                positions += posB
                positions += posC

                positions += posB
                positions += posC
                positions += posD

                val color = colorFromCondition(condition)
                for (i in 0..5) {
                    colors += color
                }
            }
        }

        return VertexAttribSet(world.cells.size * 6, positions, colors)
    }

    fun colorFromCondition(condition: Byte): FloatArray {
        if (world.rule.conditions <= 2) {
            return floatArrayOf(1.0f, 1.0f, 0.0f)
        }

        val cyan = 0.0f
        val magenta = 1.0f - (1.0f / (world.rule.conditions - 2).toFloat() * (condition - 1).toFloat())
        val yellow = 1.0f
        val key = 0.0f

        val red = 1.0f - arrayOf(1.0f, cyan * (1.0f - key)).min()!! + key
        val green = 1.0f - arrayOf(1.0f, magenta * (1.0f - key)).min()!! + key
        val blue = 1.0f - arrayOf(1.0f, yellow * (1.0f - key)).min()!! + key

        return floatArrayOf(red, green, blue)<commit_msg>Fix vertex count<commit_after>package cc.clv.android.ca2d.graphics

import cc.clv.android.ca2d.World

class WorldModel(world: World) {
    private val world = world
    val maxVertexCount: Int get() = world.width * world.height * 6

    fun vertexAttribSet(): VertexAttribSet {
        val cellWidth = 2.0f / world.width.toFloat()
        val cellHeight = 2.0f / world.height.toFloat()

        var positions = floatArrayOf()
        var colors = floatArrayOf()

        var vertexCount = 0
        for (y in (0..(world.height - 1))) {
            for (x in (0..(world.width - 1))) {
                val condition = world.cells[y * world.width + x]

                if (condition == 0.toByte()) {
                    continue
                }

                val posA = floatArrayOf(-1.0f + cellWidth * x.toFloat(), -1.0f + cellHeight * y.toFloat())
                val posB = floatArrayOf(-1.0f + cellWidth * x.toFloat(), -1.0f + cellHeight * (y + 1).toFloat())
                val posC = floatArrayOf(-1.0f + cellWidth * (x + 1).toFloat(), -1.0f + cellHeight * y.toFloat())
                val posD = floatArrayOf(-1.0f + cellWidth * (x + 1).toFloat(), -1.0f + cellHeight * (y + 1).toFloat())

                positions += posA
                positions += posB
                positions += posC

                positions += posB
                positions += posC
                positions += posD

                val color = colorFromCondition(condition)
                for (i in 0..5) {
                    colors += color
                }

                vertexCount += 6
            }
        }

        return VertexAttribSet(vertexCount, positions, colors)
    }

    fun colorFromCondition(condition: Byte): FloatArray {
        if (world.rule.conditions <= 2) {
            return floatArrayOf(1.0f, 1.0f, 0.0f)
        }

        val cyan = 0.0f
        val magenta = 1.0f - (1.0f / (world.rule.conditions - 2).toFloat() * (condition - 1).toFloat())
        val yellow = 1.0f
        val key = 0.0f

        val red = 1.0f - arrayOf(1.0f, cyan * (1.0f - key)).min()!! + key
        val green = 1.0f - arrayOf(1.0f, magenta * (1.0f - key)).min()!! + key
        val blue = 1.0f - arrayOf(1.0f, yellow * (1.0f - key)).min()!! + key

        return floatArrayOf(red, green, blue)
{'fraction_non_alphanumeric': 0.13636363636363635, 'fraction_numerical': 0.031994704324801414, 'mean_word_length': 1.6036760482481331, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5937395', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1403, 'n_words': 349}