<commit_before>/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ========================================================================
 */

package com.theenginerd.analogredstone.client.model.builder

import org.lwjgl.opengl.GL11
import com.theenginerd.analogredstone.client.model.{Part, Model}

class ModelBuilder
{
    private var mutableParts: Map[String, Part] = Map()

    def addPart(name: String, xOrigin: Int = 0, yOrigin: Int = 0, zOrigin: Int = 0)(partBuilder: (PartBuilder) => Unit): ModelBuilder =
    {
        val builder = new PartBuilder(name, xOrigin, yOrigin, zOrigin)
        partBuilder(builder)
        mutableParts += (name -> builder.toPart)
        this
    }

    def toModel: Model =
        new Model
        {
            val parts = mutableParts

            def drawAllParts(partHandler: (Part) => Unit) =
                drawParts(parts.values, partHandler)

            def drawParts(partNames: String*)(partHandler: (Part) => Unit) =
                drawParts(for(key <- partNames; part <- parts.get(key)) yield part, partHandler)

            private def drawParts(partsToDraw: Iterable[Part], partHandler: (Part) => Unit)
            {
                GL11.glPushMatrix()
                GL11.glTranslatef(0.5f, 0, 0.5f)

                partsToDraw.foreach
                {
                    part =>
                        GL11.glPushMatrix()
                        val (x, y, z) = part.origin
                        GL11.glTranslatef(x, y, z)
                        partHandler(part)
                        GL11.glPopMatrix()
                }

                GL11.glPopMatrix()
            }
        }

}<commit_msg>Clean up the ModelBuilder slightly.<commit_after>/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ========================================================================
 */

package com.theenginerd.analogredstone.client.model.builder

import org.lwjgl.opengl.GL11
import com.theenginerd.analogredstone.client.model.{Part, Model}

class ModelBuilder
{
    private var mutableParts: Map[String, Part] = Map()

    def addPart(name: String, xOrigin: Int = 0, yOrigin: Int = 0, zOrigin: Int = 0)(partBuilder: (PartBuilder) => Unit): ModelBuilder =
    {
        val builder = new PartBuilder(name, xOrigin, yOrigin, zOrigin)
        partBuilder(builder)
        mutableParts += (name -> builder.toPart)
        this
    }

    def toModel: Model =
        new Model
        {
            val parts = mutableParts

            def drawAllParts(partHandler: (Part) => Unit) =
                drawParts(parts.values, partHandler)

            def drawParts(partNames: String*)(partHandler: (Part) => Unit) =
                drawParts(for(key <- partNames; part <- parts.get(key)) yield part, partHandler)

            private def drawParts(partsToDraw: Iterable[Part], partHandler: (Part) => Unit)
            {
                GL11.glPushMatrix()
                GL11.glTranslatef(0.5f, 0, 0.5f)

                for(part <- partsToDraw)
                {
                    val (x, y, z) = part.origin

                    GL11.glPushMatrix()
                    GL11.glTranslatef(x, y, z)

                    partHandler(part)

                    GL11.glPopMatrix()
                }

                GL11.glPopMatrix()
            }
        }

}
{'fraction_non_alphanumeric': 0.12522768670309653, 'fraction_numerical': 0.01366120218579235, 'mean_word_length': 2.167267483777938, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4048868', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1161, 'n_words': 354}