Example #1
0
        private void Process(int i, bool suppressWarning = false)
        {
            var   point = objects[i].transform.position;
            float distanceUsingMath;
            var   posUsingMath = math.CalcPositionByClosestPoint(point, out distanceUsingMath);

            Debug.DrawLine(point, posUsingMath, Color.yellow);

            if (!CheckResults)
            {
                return;
            }

            float distanceUsingCheckMethod;
            var   posUsingCheckMethod = CalcPositionByClosestPoint(math, point, out distanceUsingCheckMethod);

            Debug.DrawLine(point, posUsingCheckMethod, Color.blue);

            var distanceCheck = Math.Abs(distanceUsingMath - distanceUsingCheckMethod) > .01f;
            var pointCheck    = Vector3.Magnitude(posUsingMath - posUsingCheckMethod) > 0.001f;

            if ((distanceCheck || pointCheck) && Mathf.Abs((point - posUsingMath).magnitude - (point - posUsingCheckMethod).magnitude) > BGCurve.Epsilon)
            {
                ErrorPointIndex = i;
                if (!suppressWarning)
                {
                    Debug.Log("Error detected. Simulation stopped, but erroneous iteration's still running. Use debugger to debug the issue.");
                    Debug.Log("!!! Discrepancy detected while calculating pos by closest point: 1) [Using math] pos=" + posUsingMath + ", distance=" + distanceUsingMath
                              + "  2) [Using check method] pos=" + posUsingCheckMethod + ", distance=" + distanceUsingCheckMethod);


                    if (pointCheck)
                    {
                        Debug.Log("Reason: Result points varies more than " + BGCurve.Epsilon + ". Difference=" + Vector3.Magnitude(posUsingMath - posUsingCheckMethod));
                    }
                    if (distanceCheck)
                    {
                        Debug.Log("Reason: Distances varies more than 1cm. Difference=" + Math.Abs(distanceUsingMath - distanceUsingCheckMethod));
                    }

                    var mathPos        = math.CalcByDistance(BGCurveBaseMath.Field.Position, distanceUsingMath);
                    var checkMethodPos = math.CalcByDistance(BGCurveBaseMath.Field.Position, distanceUsingCheckMethod);
                    Debug.Log("Distance check: 1) [Using math] check=" + (Vector3.SqrMagnitude(mathPos - posUsingMath) < BGCurve.Epsilon ? "passed" : "failed")
                              + "  2) [Using check method] check=" + (Vector3.SqrMagnitude(checkMethodPos - posUsingCheckMethod) < BGCurve.Epsilon ? "passed" : "failed"));


                    var actualDistUsingMath            = Vector3.Distance(point, posUsingMath);
                    var actualDistanceUsingCheckMethod = Vector3.Distance(point, posUsingCheckMethod);
                    Debug.Log("Actual distance: 1) [Using math] Dist=" + actualDistUsingMath
                              + "  2) [Using check method] Dist=" + actualDistanceUsingCheckMethod
                              +
                              (Math.Abs(actualDistUsingMath - actualDistanceUsingCheckMethod) > BGCurve.Epsilon
                                  ? (". And the winner is " + (actualDistUsingMath < actualDistanceUsingCheckMethod ? "math" : "check method"))
                                  : ""));
                }
            }
        }
Example #2
0
        private float FillIntoLine(Vector3 position, float distance, float newDistance)
        {
            float temp = distance;

            while (temp < newDistance)
            {
                positions.Add(math.CalcByDistance(BGCurveBaseMath.Field.Position, temp));
                temp += 0.01f;
            }
            positions.Add(position);
            Vector3[] positionsArray = positions.ToArray();
            fillrenderer.positionCount = positionsArray.Length;
            fillrenderer.SetPositions(positionsArray);
            return(newDistance);
        }