<commit_before>package me.benjozork.onyx.internal;

import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.math.Polygon;
import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue;

import java.util.HashMap;

import me.benjozork.onyx.logger.Log;

/**
 * Class to load {@link Polygon} from a JSON value and to get
 * @author <NAME>
 */

public class PolygonLoader {

    private static JsonValue value;

    private static Log log;

    private static HashMap<String,Polygon> polygons;

    public static void init() {
        log = Log.create("PolygonLoader");
        polygons = new HashMap<String, Polygon>();
        JsonReader reader = new JsonReader();
        value = reader.parse(new FileHandle("data/models.json"));
    }

    /**
     * Loads a new polygon into the polygon cache
     * @param name the name of the polygon to load
     */
    public static void loadPolygon(String name) {
        int len = 0, i = 0;
        Polygon p;
        JsonValue.JsonIterator iter = value.iterator();
        JsonValue temp, required = null;

        //Get the polygon of the required name from json
        while (iter.hasNext()) {
            temp = iter.next();
            if(temp.getString("name").equals(name))
                required = temp;
        }

        if(required == null) {
            log.print("ERROR: Polygon named %s not found", name);
            return;
        }

        iter = required.get("vertices").iterator();

        for (JsonValue vertice : iter) {
            len += 2;
        }

        iter = required.get("vertices").iterator();

        float[] vertices = new float[len];
        for (JsonValue val : iter) {
            vertices[i] = (float) val.getDouble("x");
            vertices[i + 1] = (float) val.getDouble("y");
            i += 2;
        }
        p = new Polygon(vertices);
        p.setOrigin(required.get("origin").getFloat("x"),required.get("origin").getFloat("y"));
        polygons.put(name,p);
        log.print("Polygon '%s' loaded", name);
    }

    /**
     * Retrieves a polygon from the polygon cache
     * @param name the polygon to retrieve
     * @return the loaded polygon
     */
    public static Polygon getPolygon(String name) {
        return getPolygon(name, 1, 1);
    }

    /**
     * Retrieves a polygon from the polygon cache, with a specified width and height
     * @param name the polygon to retrieve
     * @param width the width of the polygon
     * @param height the height of the polygon
     * @return the loaded polygon
     */
    public static Polygon getPolygon(String name, float width, float height) {
        if(! polygons.containsKey(name))
            loadPolygon(name);
        Polygon temp = polygons.get(name);
        float[] tempVertices = temp.getVertices();
        float[] returnVertices = new float[tempVertices.length];
        for(int i = 0; i < tempVertices.length; i++)
        {
            if(i % 2 == 0)
                returnVertices[i] = tempVertices[i] * width;
            else returnVertices[i] = tempVertices[i] * height;
        }
        Polygon ret = new Polygon(returnVertices);
        ret.setOrigin(width/2, height/2);
        return ret;
        //NOTE: Origin might need to be revisited
    }

    /**
     * Empties the polygon cache
     */
    public static void dispose() {
        polygons = new HashMap<String, Polygon>();
    }

}<commit_msg>Formatting and better PL header<commit_after>package me.benjozork.onyx.internal;

import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.math.Polygon;
import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue;

import java.util.HashMap;

import me.benjozork.onyx.logger.Log;

/**
 * Loads {@link Polygon} objects form JSON files and serves them to the game.
 * @author <NAME>
 */

public class PolygonLoader {

    private static JsonValue value;

    private static Log log;

    private static HashMap<String,Polygon> polygons;

    public static void init() {
        log = Log.create("PolygonLoader");
        polygons = new HashMap<String, Polygon>();
        JsonReader reader = new JsonReader();
        value = reader.parse(new FileHandle("data/models.json"));
    }

    /**
     * Loads a new polygon into the polygon cache
     *
     * @param name the name of the polygon to load
     */
    public static void loadPolygon(String name) {
        int len = 0, i = 0;
        Polygon p;
        JsonValue.JsonIterator iter = value.iterator();
        JsonValue temp, required = null;

        //Get the polygon of the required name from json
        while (iter.hasNext()) {
            temp = iter.next();
            if(temp.getString("name").equals(name))
                required = temp;
        }

        if(required == null) {
            log.print("ERROR: Polygon named %s not found", name);
            return;
        }

        iter = required.get("vertices").iterator();

        for (JsonValue vertice : iter) {
            len += 2;
        }

        iter = required.get("vertices").iterator();

        float[] vertices = new float[len];
        for (JsonValue val : iter) {
            vertices[i] = (float) val.getDouble("x");
            vertices[i + 1] = (float) val.getDouble("y");
            i += 2;
        }
        p = new Polygon(vertices);
        p.setOrigin(required.get("origin").getFloat("x"),required.get("origin").getFloat("y"));
        polygons.put(name,p);
        log.print("Polygon '%s' loaded", name);
    }

    /**
     * Retrieves a polygon from the polygon cache
     *
     * @param name the polygon to retrieve
     *
     * @return the loaded polygon
     */
    public static Polygon getPolygon(String name) {
        return getPolygon(name, 1, 1);
    }

    /**
     * Retrieves a polygon from the polygon cache, with a specified width and height
     *
     * @param name the polygon to retrieve
     * @param width the width of the polygon
     * @param height the height of the polygon
     *
     * @return the loaded polygon
     */
    public static Polygon getPolygon(String name, float width, float height) {
        if(! polygons.containsKey(name))
            loadPolygon(name);
        Polygon temp = polygons.get(name);
        float[] tempVertices = temp.getVertices();
        float[] returnVertices = new float[tempVertices.length];
        for(int i = 0; i < tempVertices.length; i++)
        {
            if(i % 2 == 0)
                returnVertices[i] = tempVertices[i] * width;
            else returnVertices[i] = tempVertices[i] * height;
        }
        Polygon ret = new Polygon(returnVertices);
        ret.setOrigin(width/2, height/2);
        return ret;
        //NOTE: Origin might need to be revisited
    }

    /**
     * Empties the polygon cache
     */
    public static void dispose() {
        polygons = new HashMap<String, Polygon>();
    }

}
{'fraction_non_alphanumeric': 0.11580322159338267, 'fraction_numerical': 0.0034828036569438396, 'mean_word_length': 2.189264229523369, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '251694', 'n_tokens_mistral': 2072, 'n_tokens_neox': 1974, 'n_words': 577}