<commit_before>using System;
using System.Collections.Generic;
using UnityEngine;
using BriLib;
using Point = BriLib.TwoDimensionalPoint<ShatterTester.ColorWrapper>;
using PointCollection = BriLib.IObservableCollection<BriLib.TwoDimensionalPoint<ShatterTester.ColorWrapper>>;

public class ShatterTester : TextureWriteTester
{
    public enum State
    {
        None = 0,
        Points = 1,
        VoronoiCells = 2,
        CircumCircles = 3,
        IntersectionPoints = 4,
        Triangles = 5,
        Broken = 6,
    }

    public int VoronoiCount;
    public int PointSize;
    public int IntersectionPointSize;
    public Color CircleColor;
    public Color IntersectionColor;
    public MeshFilter MeshFilter;

    private Quadtree<ColorWrapper> _colorTree;
    private VoronoiDiagram _voronoi;
    private Dictionary<ColorWrapper, BriLib.Point> _pointMap;
    private Triangulation _delaunay;
    private State _currentState;

    private void OnGUI()
    {
        var startX = 20;
        var width = 100;
        var startY = Screen.height - 30;
        var height = 30;
        var currentX = startX;

        var enumValues = Enum.GetValues(typeof(State));
        var enumNames = Enum.GetNames(typeof(State));

        for (int i = 1; i < enumValues.Length; i++)
        {
            if (GUI.Button(new Rect(currentX, startY, width, height), enumNames[i]))
            {
                AdvanceToState((State)enumValues.GetValue(i));
            }

            currentX += width + startX;
        }
    }

    protected override void OnMouseClick(int x, int y)
    {
        base.OnMouseClick(x, y);

        Debug.Log("Got mouse click at x: " + x + ", y: " + y);

        if (_colorTree == null) return;

        var _rand = new System.Random();
        var r = _rand.Next(256) / 256f;
        var g = _rand.Next(256) / 256f;
        var b = _rand.Next(256) / 256f;
        var color = new Color(r, g, b);
        var wrapper = new ColorWrapper { Color = color };

        _colorTree.Insert(x, y, wrapper);
    }

    protected override void OnMouseClickWorld(Vector3 point)
    {
        base.OnMouseClickWorld(point);
        var localPoint = transform.InverseTransformPoint(point);
        _delaunay.delaunayPlace(new Pnt(localPoint.x, localPoint.z));
    }

    protected override void Initialize()
    {
        base.Initialize();
        _colorTree = new Quadtree<ColorWrapper>(Width / 2, Height / 2, Width / 2, 5);
        _voronoi = new VoronoiDiagram();
        _pointMap = new Dictionary<ColorWrapper, BriLib.Point>();
        var tri = new Triangle(
                new Pnt(-10000, -10000),
                new Pnt(10000, -10000),
                new Pnt(Width / 2, 10000)
            );
        _delaunay = new Triangulation(tri);

        //_delaunay = new Triangulation();
        //var verts = MeshFilter.mesh.vertices;
        //var tris = MeshFilter.mesh.triangles;

        //var triList = new List<Triangle>();

        //for (int i = 0; i < tris.Length; i += 3)
        //{
        //    var s = "[Point=X:" + verts[tris[i]].x + ",Y:" + verts[tris[i]].y + ",Z:" + verts[tris[i]].z + "]";
        //    s += ",[Point=X:" + verts[tris[i + 1]].x + ",Y:" + verts[tris[i + 1]].y + ",Z:" + verts[tris[i + 1]].z + "]";
        //    s += ",[Point=X:" + verts[tris[i + 2]].x + ",Y:" + verts[tris[i + 2]].y + ",Z:" + verts[tris[i + 2]].z + "]";
        //    Debug.Log("Got tri with points: " + s);
        //    var pnt = new Pnt(verts[tris[i]].x, verts[tris[i]].z);
        //    var pnt2 = new Pnt(verts[tris[i + 1]].x, verts[tris[i + 1]].z);
        //    var pnt3 = new Pnt(verts[tris[i + 2]].x, verts[tris[i + 2]].z);
        //    var tri = new Triangle(pnt, pnt2, pnt3);
        //    triList.Add(tri);
        //}

        //_delaunay.AddExistingTriangles(triList);

        UpdateTexture();
    }

    private void AdvanceToState(State v)
    {
        if ((int)v <= (int)_currentState)
        {
            _currentState = State.None;<commit_msg>Reference voronoi implementation from <NAME>. Chew work<commit_after>using System;
using System.Collections.Generic;
using UnityEngine;
using BriLib;
using Point = BriLib.TwoDimensionalPoint<ShatterTester.ColorWrapper>;
using PointCollection = BriLib.IObservableCollection<BriLib.TwoDimensionalPoint<ShatterTester.ColorWrapper>>;

public class ShatterTester : TextureWriteTester
{
    public enum State
    {
        None = 0,
        Points = 1,
        VoronoiCells = 2,
        CircumCircles = 3,
        IntersectionPoints = 4,
        Triangles = 5,
        Broken = 6,
    }

    public int VoronoiCount;
    public int PointSize;
    public int IntersectionPointSize;
    public Color CircleColor;
    public Color IntersectionColor;
    public MeshFilter MeshFilter;

    private Quadtree<ColorWrapper> _colorTree;
    private VoronoiDiagram _voronoi;
    private Dictionary<ColorWrapper, BriLib.Point> _pointMap;
    private Triangulation _delaunay;
    private State _currentState;

    private void OnGUI()
    {
        var startX = 20;
        var width = 100;
        var startY = Screen.height - 30;
        var height = 30;
        var currentX = startX;

        var enumValues = Enum.GetValues(typeof(State));
        var enumNames = Enum.GetNames(typeof(State));

        for (int i = 1; i < enumValues.Length; i++)
        {
            if (GUI.Button(new Rect(currentX, startY, width, height), enumNames[i]))
            {
                AdvanceToState((State)enumValues.GetValue(i));
            }

            currentX += width + startX;
        }
    }

    protected override void OnMouseClick(int x, int y)
    {
        base.OnMouseClick(x, y);

        Debug.Log("Got mouse click at x: " + x + ", y: " + y);

        if (_colorTree == null) return;

        var _rand = new System.Random();
        var r = _rand.Next(256) / 256f;
        var g = _rand.Next(256) / 256f;
        var b = _rand.Next(256) / 256f;
        var color = new Color(r, g, b);
        var wrapper = new ColorWrapper { Color = color };

        _colorTree.Insert(x, y, wrapper);
    }

    protected override void OnMouseClickWorld(Vector3 point)
    {
        base.OnMouseClickWorld(point);
        var localPoint = transform.InverseTransformPoint(point);
        _delaunay.delaunayPlace(new Pnt(localPoint.x, localPoint.z));
    }

    protected override void Initialize()
    {
        base.Initialize();
        _colorTree = new Quadtree<ColorWrapper>(Width / 2, Height / 2, Width / 2, 5);
        _voronoi = new VoronoiDiagram();
        _pointMap = new Dictionary<ColorWrapper, BriLib.Point>();
        var tri = new Triangle(
                new Pnt(-10000, -10000),
                new Pnt(10000, -10000),
                new Pnt(Width / 2, 10000)
            );
        _delaunay = new Triangulation(tri);

        //_delaunay = new Triangulation();
        //var verts = MeshFilter.mesh.vertices;
        //var tris = MeshFilter.mesh.triangles;

        //var triList = new List<Triangle>();

        //for (int i = 0; i < tris.Length; i += 3)
        //{
        //    var s = "[Point=X:" + verts[tris[i]].x + ",Y:" + verts[tris[i]].y + ",Z:" + verts[tris[i]].z + "]";
        //    s += ",[Point=X:" + verts[tris[i + 1]].x + ",Y:" + verts[tris[i + 1]].y + ",Z:" + verts[tris[i + 1]].z + "]";
        //    s += ",[Point=X:" + verts[tris[i + 2]].x + ",Y:" + verts[tris[i + 2]].y + ",Z:" + verts[tris[i + 2]].z + "]";
        //    Debug.Log("Got tri with points: " + s);
        //    var pnt = new Pnt(verts[tris[i]].x, verts[tris[i]].z);
        //    var pnt2 = new Pnt(verts[tris[i + 1]].x, verts[tris[i + 1]].z);
        //    var pnt3 = new Pnt(verts[tris[i + 2]].x, verts[tris[i + 2]].z);
        //    var tri = new Triangle(pnt, pnt2, pnt3);
        //    triList.Add(tri);
        //}

        //_delaunay.AddExistingTriangles(triList);

        UpdateTexture();
    }

    public void drawAllVoronoi(boolean withFill, boolean withSites)
    {
        // Keep track of sites done; no drawing for initial triangles sites
        HashSet<Pnt> done = new HashSet<Pnt>(initialTriangle);
        for (Triangle triangle : dt)
            for (Pnt site: triangle)
            {
                if (done.contains(site)) continue;
                done.add(site);
                List<Triangle> list = dt.surroundingTriangles(site, triangle);
                Pnt[] vertices = new Pnt[list.size()];
                int i = 0;
                for (Triangle tri: list)
                    vertices[i++] = tri.getCircumcenter();
                draw(vertices, withFill ? getColor(site) : null);
                if (withSites) draw(site);
            }
    }

    private void AdvanceToState(State v)
    {
        if ((int)v <= (int)_currentState)
        {
            _currentState = State.None;
{'fraction_non_alphanumeric': 0.13473564525298465, 'fraction_numerical': 0.018760659465605456, 'mean_word_length': 2.0841514726507713, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, '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': '2482849', 'n_tokens_mistral': 3069, 'n_tokens_neox': 2855, 'n_words': 672}