<commit_before>/* Copyright 2015 Samsung Electronics Co., LTD
 *
 * 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.eje_c.meganekko;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.View;

/**
 * This is one of the key Meganekko classes: It holds GL meshes.
 * <p>
 * A GL mesh is a net of triangles that define an object's surface geometry.
 */
public class Mesh extends HybridObject {

    public Mesh() {
    }

    Mesh(long ptr) {
        super(ptr);
    }

    private static native void build(long renderData, float[] positions, float[] colors, float[] uvs, int[] triangles);

    private static native void buildQuad(long renderData, float width, float heigh);

    private static native void buildTesselatedQuad(long renderData, int horizontal, int vertical, boolean twoSided);

    private static native void buildFadedScreenMask(long renderData, float xFraction, float yFraction);

    private static native void buildVignette(long renderData, float xFraction, float yFraction);

    private static native void buildTesselatedCylinder(long renderData, float radius, float height, int horizontal, int vertical, float uScale, float vScale);

    private static native void buildDome(long renderData, float latRads, float uScale, float vScale);

    private static native void buildGlobe(long renderData, float uScale, float vScale);

    private static native void buildSpherePatch(long renderData, float fov);

    private static native void buildCalibrationLines(long renderData, int extraLines, boolean fullGrid);

    private static native void buildUnitCubeLines(long renderData);

    public void build(float[] positions, float[] colors, float[] uvs, int[] triangles) {

        if (positions.length % 3 != 0) {
            throw new IllegalArgumentException("positions element count must be multiple of 3.");
        } else if (colors.length % 4 != 0) {
            throw new IllegalArgumentException("positions element count must be multiple of 4.");
        } else if (uvs.length % 2 != 0) {
            throw new IllegalArgumentException("positions element count must be multiple of 2.");
        } else if (triangles.length % 3 != 0) {
            throw new IllegalArgumentException("triangles element count must be multiple of 3.");
        }

        int positionSize = positions.length / 3;
        int colorSize = colors.length / 4;
        int uvSize = uvs.length / 2;

        if (positionSize != colorSize) {
            throw new IllegalArgumentException("position elements are " + positionSize + " but color elements are " + colorSize + ".");
        } else if (colorSize != uvSize) {
            throw new IllegalArgumentException("color elements are " + colorSize + " but uv elements are " + uvSize + ".");
        }

        build(getNative(), positions, colors, uvs, triangles);
    }

    /**
     * Build quad mesh
     *
     * @param width
     * @param height
     */
    public void buildQuad(float width, float height) {

        /*
         * 0    2
         * *----*
         * |  / |
         * | /  |
         * *----*
         * 1    3
         */

        float[] positions = {
                width * -0.5f, height * 0.5f, 0.0f,  // Left Top
                width * -0.5f, height * -0.5f, 0.0f, // Left Bottom
                width * 0.5f, height * 0.5f, 0.0f,   // Right Top
                width * 0.5f, height * -0.5f, 0.0f   // Right Bottom
        };

        float[] colors = {
                1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f
        };

        float[] uvs = {
                0.0f, 0.0f,
                0.0f, 1.0f,
                1.0f, 0.0f,
                1.0f, 1.0f
        };

        int[] triangles = {
                0, 1, 2,
                1, 3, 2
        };

        build(positions, colors, uvs, triangles);
    }

    public void buildTesselatedQuad(int horizontal, int vertical, boolean twoSided) {
        buildTesselatedQuad(getNative(), horizontal, vertical, twoSided);
    }

    public void buildFadedScreenMask(float xFraction, float yFraction) {
        buildFadedScreenMask(getNative(), xFraction, yFraction);
    }

    public void buildVignette(float xFraction, float yFraction) {
        buildVignette(getNative(), xFraction, yFraction);
    }

    public void buildTesselatedCylinder(float radius, float height, int horizontal, int vertical, float uScale, float vScale) {
        buildTesselatedCylinder(getNative(), radius, height, horizontal, vertical, uScale, vScale);
    }<commit_msg>Add Mesh.mapLocalXYToUV<commit_after>/* Copyright 2015 Samsung Electronics Co., LTD
 *
 * 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.eje_c.meganekko;

import android.graphics.Bitmap;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.view.View;

/**
 * This is one of the key Meganekko classes: It holds GL meshes.
 * <p>
 * A GL mesh is a net of triangles that define an object's surface geometry.
 */
public class Mesh extends HybridObject {

    private RectF mQuad;

    public Mesh() {
    }

    Mesh(long ptr) {
        super(ptr);
    }

    private static native void build(long renderData, float[] positions, float[] colors, float[] uvs, int[] triangles);

    private static native void buildQuad(long renderData, float width, float heigh);

    private static native void buildTesselatedQuad(long renderData, int horizontal, int vertical, boolean twoSided);

    private static native void buildFadedScreenMask(long renderData, float xFraction, float yFraction);

    private static native void buildVignette(long renderData, float xFraction, float yFraction);

    private static native void buildTesselatedCylinder(long renderData, float radius, float height, int horizontal, int vertical, float uScale, float vScale);

    private static native void buildDome(long renderData, float latRads, float uScale, float vScale);

    private static native void buildGlobe(long renderData, float uScale, float vScale);

    private static native void buildSpherePatch(long renderData, float fov);

    private static native void buildCalibrationLines(long renderData, int extraLines, boolean fullGrid);

    private static native void buildUnitCubeLines(long renderData);

    public void build(float[] positions, float[] colors, float[] uvs, int[] triangles) {

        if (positions.length % 3 != 0) {
            throw new IllegalArgumentException("positions element count must be multiple of 3.");
        } else if (colors.length % 4 != 0) {
            throw new IllegalArgumentException("positions element count must be multiple of 4.");
        } else if (uvs.length % 2 != 0) {
            throw new IllegalArgumentException("positions element count must be multiple of 2.");
        } else if (triangles.length % 3 != 0) {
            throw new IllegalArgumentException("triangles element count must be multiple of 3.");
        }

        int positionSize = positions.length / 3;
        int colorSize = colors.length / 4;
        int uvSize = uvs.length / 2;

        if (positionSize != colorSize) {
            throw new IllegalArgumentException("position elements are " + positionSize + " but color elements are " + colorSize + ".");
        } else if (colorSize != uvSize) {
            throw new IllegalArgumentException("color elements are " + colorSize + " but uv elements are " + uvSize + ".");
        }

        build(getNative(), positions, colors, uvs, triangles);
    }

    /**
     * Build quad mesh
     *
     * @param width
     * @param height
     */
    public void buildQuad(float width, float height) {

        /*
         * 0    2
         * *----*
         * |  / |
         * | /  |
         * *----*
         * 1    3
         */

        float[] positions = {
                width * -0.5f, height * 0.5f, 0.0f,  // Left Top
                width * -0.5f, height * -0.5f, 0.0f, // Left Bottom
                width * 0.5f, height * 0.5f, 0.0f,   // Right Top
                width * 0.5f, height * -0.5f, 0.0f   // Right Bottom
        };

        float[] colors = {
                1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f
        };

        float[] uvs = {
                0.0f, 0.0f,
                0.0f, 1.0f,
                1.0f, 0.0f,
                1.0f, 1.0f
        };

        int[] triangles = {
                0, 1, 2,
                1, 3, 2
        };

        build(positions, colors, uvs, triangles);

        // RectF's Y coordinate is inverted from OpenGL
        // top is -Y, bottom is +Y
        mQuad = new RectF(-width * 0.5f, -height * 0.5f, width * 0.5f, height * 0.5f);
    }

    /**
     * Convert local coordinates XY to texture UV.
     * This only works with mesh created from {@link #createQuad(float, float)}.
     *
     * @param x  X on local coordinates
     * @param y  Y on local coordinates
     * @param uv Results will be set. {@code uv.length} must be 2 or greater.
     */
    public void mapLocalXYToUV(float x, float y, @NonNull float[] uv) {
        if (mQuad == null)
            throw new IllegalStateException("Mesh is not created with quad geometry");

        uv[0] = (x - mQuad.left) / mQuad.width();
        uv[1] = (-y - mQuad.top) / mQuad.height();
    }

    public void buildTesselatedQuad(int horizontal, int vertical, boolean twoSided) {
        buildTesselatedQuad(getNative(), horizontal, vertical, twoSided);
    }

    public void buildFadedScreenMask(float xFraction, float yFraction) {
        buildFadedScreenMask(getNative(), xFraction, yFraction);
    }

    public void buildVignette(float xFraction, float yFraction) {
        buildVignette(getNative(), xFraction, yFraction);
    }

    public void buildTesselatedCylinder(float radius, float height, int horizontal, int vertical, float uScale, float vScale) {
        buildTesselatedCylinder(getNative(), radius, height, horizontal, vertical, uScale, vScale);
    }
{'fraction_non_alphanumeric': 0.10054469149031163, 'fraction_numerical': 0.019733904812929727, 'mean_word_length': 2.3949681721733858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4734547', 'n_tokens_mistral': 3381, 'n_tokens_neox': 3140, 'n_words': 1108}