using System.Collections.Generic;
using UnityEngine;

public class GrassMeshGeneration {
    static public BladeData[] GenerateBladesRandom(int size, int num) {
        var blades = new BladeData[num];

        for (int i = 0; i < num; i++) {
            blades[i].rootPosition = new Vector3(
                Random.Range(0f, size), Random.Range(-0.25f, 0f), Random.Range(0f, size)
            );
            blades[i].tipOffset = new Vector3(Random.Range(-.8f, .8f), Random.Range(0.7f, 1f), Random.Range(-.8f, .8f));
        }

        return blades;
    }

    // r = 0.5 means that the generated blades will have 50% of the blades of the input blades
    static public BladeData[] GenerateBladesReduced(BladeData[] from, float r) {
        List<BladeData> blades = new();
        
        for (int i = 0; i < from.Length; i++) {
            if (Random.Range(0f, 1f) > r) continue;
            
            BladeData blade = from[i];
            blades.Add(blade);
        }
        
        return blades.ToArray();
    }

    static public BladeData[] GenerateBladesEven(int size) {
        var blades = new BladeData[size * size * 100];

        for (int x = 0; x < size * 10; x++)
        for (int y = 0; y < size * 10; y++) {
            var i = x + y * size * 10;
            blades[i].rootPosition = new Vector3(x/10.0f, 0.0f, y/10.0f);
            blades[i].tipOffset = new Vector3(0.01f, 1.0f, 0.01f);
        }

        return blades;
    }
}