Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        Points = new List <Vector2>(PointCount);
        //Seed = (uint)Mathf.Max(1, System.DateTime.Now.Millisecond);
        var random = new Unity.Mathematics.Random(Seed);

        for (int i = 0; i < PointCount; i++)
        {
            Points.Add(random.NextFloat2());
        }
        //for (int i = 0; i < PointCount; i++)
        //{
        //    Points.Add(new Vector2(i / 100.0f, Mathf.Sin(i / 10.0f)));
        //}

        {
            var s = new BMCurves.CurveBuilder(DistanceBetweenPoints, CurveSplitError);
            for (int i = 0; i < Points.Count; i++)
            {
                s.AddPoint(Points[i]);
            }

            var curves = s.Curves;
            BurningMimeCurves.positionCount = curves.Count * 4;
            for (int i = 0; i < curves.Count; i++)
            {
                BurningMimeCurves.SetPosition(i * 4 + 0, curves[i].p0 * 25.0f);
                BurningMimeCurves.SetPosition(i * 4 + 1, curves[i].p1 * 25.0f);
                BurningMimeCurves.SetPosition(i * 4 + 2, curves[i].p2 * 25.0f);
                BurningMimeCurves.SetPosition(i * 4 + 3, curves[i].p3 * 25.0f);
            }
        }

        {
            var s = new OPCurves.CurveBuilder(DistanceBetweenPoints, CurveSplitError);
            for (int i = 0; i < Points.Count; i++)
            {
                s.AddPoint(Points[i]);
            }

            var curves = s.Curves;
            OptimizedCurves.positionCount = curves.Count * 4;
            for (int i = 0; i < curves.Count; i++)
            {
                OptimizedCurves.SetPosition(i * 4 + 0, curves[i].p0 * 25.0f);
                OptimizedCurves.SetPosition(i * 4 + 1, curves[i].p1 * 25.0f);
                OptimizedCurves.SetPosition(i * 4 + 2, curves[i].p2 * 25.0f);
                OptimizedCurves.SetPosition(i * 4 + 3, curves[i].p3 * 25.0f);
            }
        }
    }
Ejemplo n.º 2
0
                [Explicit("Test for specific fail case which I don't want to deal with atm, so keeping it around here, but will have fix for it at some point?")] // TODO: Make this pass
                public void FailingAddTrianglePoints()
                {
                    //var randomSeed = (uint)Mathf.Max(1, System.DateTime.Now.Millisecond);
                    var randomSeed = (uint)886;

                    try
                    {
                        using var d = new Unity.Profiling.ProfilerMarker("AddTrianglePoints").Auto();
                        var points       = new List <Vector2>();
                        var randomPoints = new Unity.Mathematics.Random(randomSeed);
                        for (int i = 0; i < 500; i++)
                        {
                            points.Add(randomPoints.NextFloat2());
                        }

                        var desiredSpline   = new BMCurves.CurveBuilder(DistanceBetweenPoints, CurveSplitError);
                        var optimizedSpline = new OPCurves.CurveBuilder(DistanceBetweenPoints, CurveSplitError);
                        for (int i = 0; i < points.Count; i++)
                        {
                            var desiredRes   = desiredSpline.AddPoint(points[i]);
                            var optimizedRes = optimizedSpline.AddPoint(points[i]);
                            Assert.IsTrue(desiredRes.FirstChangedIndex == optimizedRes.FirstChangedIndex);
                        }

                        for (int i = 0; i < desiredSpline.Curves.Count; i++)
                        {
                            try
                            {
                                Assert.IsTrue(Equals(desiredSpline.Curves[i], optimizedSpline.Curves[i]));
                            }
                            catch (Exception e)
                            {
                                throw e;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogError($"Seed: {randomSeed}");
                        throw e;
                    }
                }
        private readonly Spline _spline;             // Underlyig spline

        public SplineBuilder(FLOAT pointDistance, FLOAT error, int samplesPerCurve)
        {
            _builder = new CurveBuilder(pointDistance, error);
            _spline  = new Spline(samplesPerCurve);
        }