<commit_before>/*
 * This file is part of Caustic API.
 *
 * Copyright (c) 2013 Spout LLC <http://www.spout.org/>
 * Caustic API is licensed under the Spout License Version 1.
 *
 * Caustic API is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * In addition, 180 days after any changes are published, you can use the
 * software, incorporating those changes, under the terms of the MIT license,
 * as described in the Spout License Version 1.
 *
 * Caustic API is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License,
 * the MIT license and the Spout License Version 1 along with this program.
 * If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
 * License and see <http://spout.in/licensev1> for the full license, including
 * the MIT license.
 */
package org.spout.renderer.api.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.flowpowered.math.vector.Vector2f;
import com.flowpowered.math.vector.Vector3f;

import gnu.trove.list.TFloatList;
import gnu.trove.list.TIntList;
import gnu.trove.list.array.TFloatArrayList;
import gnu.trove.map.TObjectIntMap;
import gnu.trove.map.hash.TObjectIntHashMap;

import org.spout.renderer.api.data.VertexAttribute;
import org.spout.renderer.api.data.VertexAttribute.DataType;
import org.spout.renderer.api.data.VertexData;

/**
 * Generates various shape meshes of the desired size and stores them to the models.
 */
public class MeshGenerator {
    private MeshGenerator() {
    }

    /*
     * ^
     * | y
     * |
     * |     x
     * ------->
     * \
     *  \
     *   \ z
     *    V
     * The axis system
     */

    /**
     * Generates a crosshairs shaped wireframe in 3D. The center is at the intersection point of the three lines.
     *
     * @param destination Where to save the mesh (can be null)
     * @param length The length for the three lines
     * @return The vertex data
     */
    public static VertexData generateCrosshairs(VertexData destination, float length) {
        /*
         *   \ |
         *    \|
         * ----O-----
         *     |\
         *     | \
         */
        // Model data buffers
        if (destination == null) {
            destination = new VertexData();
        }
        final VertexAttribute positionsAttribute = new VertexAttribute("positions", DataType.FLOAT, 3);
        destination.addAttribute(0, positionsAttribute);
        final TFloatList positions = new TFloatArrayList();
        final TIntList indices = destination.getIndices();
        length /= 2;
        // Add the x axis line
        addAll(positions, -length, 0, 0, length, 0, 0);
        addAll(indices, 0, 1);
        // Add the y axis line
        addAll(positions, 0, -length, 0, 0, length, 0);
        addAll(indices, 2, 3);
        // Add the z axis line
        addAll(positions, 0, 0, -length, 0, 0, length);
        addAll(indices, 4, 5);
        // Put the mesh in the vertex data
        positionsAttribute.setData(positions);
        return destination;
    }

    /**
     * Generates a cuboid shaped wireframe (the outline of the cuboid). The center is at the middle of the cuboid.
     *
     * @param destination Where to save the mesh (can be null)
     * @param size The size of the cuboid to generate, on x, y and z
     * @return The vertex data
     */
    public static VertexData generateWireCuboid(VertexData destination, Vector3f size) {
        /*
         * 4------5
         * |\     |\
         * | 7------6
         * | |    | |
         * 0-|----1 |
         *  \|     \|
         *   3------2
         */
        // Corner positions
        final Vector3f p = size.div(2);
        final Vector3f p6 = new Vector3f(p.getX(), p.getY(), p.getZ());
        final Vector3f p0 = p6.negate();
        final Vector3f p7 = new Vector3f(-p.getX(), p.getY(), p.getZ());
        final Vector3f p1 = p7.negate();
        final Vector3f p4 = new Vector3f(-p.getX(), p.getY(), -p.getZ());
        final Vector3f p2 = p4.negate();
        final Vector3f p5 = new Vector3f(p.getX(), p.getY(), -p.getZ());
        final Vector3f p3 = p5.negate();
        // Model data buffers
        if (destination == null) {
            destination = new VertexData();
        }
        final VertexAttribute positionsAttribute = new VertexAttribute("positions", DataType.FLOAT, 3);
        destination.addAttribute(0, positionsAttribute);
        final TFloatList positions = new TFloatArrayList();
        final VertexAttribute normalsAttribute = new VertexAttribute("normals", DataType.FLOAT, 3);
        destination.addAttribute(1, normalsAttribute);
        final TFloatList normals = new TFloatArrayList();
        final TIntList indices = destination.getIndices();
        // Add all of the corners
        addVector(positions, p0);
        addVector(normals, p0.normalize());
        addVector(positions, p1);
        addVector(normals, p1.normalize());
        addVector(positions, p2);
        addVector(normals, p2.normalize());
        addVector(positions, p3);
        addVector(normals, p3.normalize());
        addVector(positions, p4);
        addVector(normals, p4.normalize());
        addVector(positions, p5);
        addVector(normals, p5.normalize());
        addVector(positions, p6);
        addVector(normals, p6.normalize());
        addVector(positions, p7);
        addVector(normals, p7.normalize());
        // Top face
        addAll(indices, 4, 5, 5, 6, 6, 7, 7, 4);
        // Bottom face
        addAll(indices, 0, 1, 1, 2, 2, 3, 3, 0);
        // Sides
        addAll(indices, 6, 2, 7, 3, 4, 0, 5, 1);
        // Put the mesh in the vertex data
        positionsAttribute.setData(positions);
        normalsAttribute.setData(normals);
        return destination;<commit_msg>Remove normals from wireframe cuboid<commit_after>/*
 * This file is part of Caustic API.
 *
 * Copyright (c) 2013 Spout LLC <http://www.spout.org/>
 * Caustic API is licensed under the Spout License Version 1.
 *
 * Caustic API is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * In addition, 180 days after any changes are published, you can use the
 * software, incorporating those changes, under the terms of the MIT license,
 * as described in the Spout License Version 1.
 *
 * Caustic API is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License,
 * the MIT license and the Spout License Version 1 along with this program.
 * If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
 * License and see <http://spout.in/licensev1> for the full license, including
 * the MIT license.
 */
package org.spout.renderer.api.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.flowpowered.math.vector.Vector2f;
import com.flowpowered.math.vector.Vector3f;

import gnu.trove.list.TFloatList;
import gnu.trove.list.TIntList;
import gnu.trove.list.array.TFloatArrayList;
import gnu.trove.map.TObjectIntMap;
import gnu.trove.map.hash.TObjectIntHashMap;

import org.spout.renderer.api.data.VertexAttribute;
import org.spout.renderer.api.data.VertexAttribute.DataType;
import org.spout.renderer.api.data.VertexData;

/**
 * Generates various shape meshes of the desired size and stores them to the models.
 */
public class MeshGenerator {
    private MeshGenerator() {
    }

    /*
     * ^
     * | y
     * |
     * |     x
     * ------->
     * \
     *  \
     *   \ z
     *    V
     * The axis system
     */

    /**
     * Generates a crosshairs shaped wireframe in 3D. The center is at the intersection point of the three lines.
     *
     * @param destination Where to save the mesh (can be null)
     * @param length The length for the three lines
     * @return The vertex data
     */
    public static VertexData generateCrosshairs(VertexData destination, float length) {
        /*
         *   \ |
         *    \|
         * ----O-----
         *     |\
         *     | \
         */
        // Model data buffers
        if (destination == null) {
            destination = new VertexData();
        }
        final VertexAttribute positionsAttribute = new VertexAttribute("positions", DataType.FLOAT, 3);
        destination.addAttribute(0, positionsAttribute);
        final TFloatList positions = new TFloatArrayList();
        final TIntList indices = destination.getIndices();
        length /= 2;
        // Add the x axis line
        addAll(positions, -length, 0, 0, length, 0, 0);
        addAll(indices, 0, 1);
        // Add the y axis line
        addAll(positions, 0, -length, 0, 0, length, 0);
        addAll(indices, 2, 3);
        // Add the z axis line
        addAll(positions, 0, 0, -length, 0, 0, length);
        addAll(indices, 4, 5);
        // Put the mesh in the vertex data
        positionsAttribute.setData(positions);
        return destination;
    }

    /**
     * Generates a cuboid shaped wireframe (the outline of the cuboid). The center is at the middle of the cuboid.
     *
     * @param destination Where to save the mesh (can be null)
     * @param size The size of the cuboid to generate, on x, y and z
     * @return The vertex data
     */
    public static VertexData generateWireCuboid(VertexData destination, Vector3f size) {
        /*
         * 4------5
         * |\     |\
         * | 7------6
         * | |    | |
         * 0-|----1 |
         *  \|     \|
         *   3------2
         */
        // Corner positions
        final Vector3f p = size.div(2);
        final Vector3f p6 = new Vector3f(p.getX(), p.getY(), p.getZ());
        final Vector3f p0 = p6.negate();
        final Vector3f p7 = new Vector3f(-p.getX(), p.getY(), p.getZ());
        final Vector3f p1 = p7.negate();
        final Vector3f p4 = new Vector3f(-p.getX(), p.getY(), -p.getZ());
        final Vector3f p2 = p4.negate();
        final Vector3f p5 = new Vector3f(p.getX(), p.getY(), -p.getZ());
        final Vector3f p3 = p5.negate();
        // Model data buffers
        if (destination == null) {
            destination = new VertexData();
        }
        final VertexAttribute positionsAttribute = new VertexAttribute("positions", DataType.FLOAT, 3);
        destination.addAttribute(0, positionsAttribute);
        final TFloatList positions = new TFloatArrayList();
        final TIntList indices = destination.getIndices();
        // Add all of the corners
        addVector(positions, p0);
        addVector(positions, p1);
        addVector(positions, p2);
        addVector(positions, p3);
        addVector(positions, p4);
        addVector(positions, p5);
        addVector(positions, p6);
        addVector(positions, p7);
        // Top face
        addAll(indices, 4, 5, 5, 6, 6, 7, 7, 4);
        // Bottom face
        addAll(indices, 0, 1, 1, 2, 2, 3, 3, 0);
        // Sides
        addAll(indices, 6, 2, 7, 3, 4, 0, 5, 1);
        // Put the mesh in the vertex data
        positionsAttribute.setData(positions);
        return destination;
{'fraction_non_alphanumeric': 0.10967687505272927, 'fraction_numerical': 0.018560701932000337, 'mean_word_length': 2.286387579706127, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2403648', 'n_tokens_mistral': 3607, 'n_tokens_neox': 3440, 'n_words': 1172}