private PointCurve.SegmentationResult SynchronizeRoutePointCurve() { if (RoutePointCurveUpToDate && m_routePointCurve.LastSuccessfulResult.Successful) { return(m_routePointCurve.LastSuccessfulResult); } if (m_routePointCurve == null) { m_routePointCurve = new PointCurve(); } m_routePointCurve.LastSuccessfulResult = new PointCurve.SegmentationResult() { Error = float.PositiveInfinity, Successful = false }; if (m_routePointCurve.NumPoints == Route.NumNodes) { for (int i = 0; i < Route.NumNodes; ++i) { m_routePointCurve[i] = Route[i].Position; } } else { m_routePointCurve.Clear(); foreach (var node in Route) { m_routePointCurve.Add(node.Position); } } if (m_routePointCurve.Finalize()) { var numSegments = Mathf.Max(Mathf.CeilToInt(ResolutionPerUnitLength * Route.TotalLength), 1); var result = m_routePointCurve.FindSegmentLength(numSegments, PointCurve.DefaultErrorFunc, 5.0E-3f, 1.0E-3f); if (result.Successful) { return(result); } } return(new PointCurve.SegmentationResult() { Error = float.PositiveInfinity, Successful = false }); }
public PointCurve.SegmentationResult SynchronizeRoutePointCurve() { if (RoutePointCurveUpToDate && m_routePointCurve.LastSuccessfulResult.Successful) { return(m_routePointCurve.LastSuccessfulResult); } if (m_routePointCurve == null) { m_routePointCurve = new PointCurve(); } m_routePointCurve.LastSuccessfulResult = new PointCurve.SegmentationResult() { Error = float.PositiveInfinity, Successful = false }; m_routePointsCache = new Vector3[] { }; if (m_routePointCurve.NumPoints == Route.NumNodes) { for (int i = 0; i < Route.NumNodes; ++i) { m_routePointCurve[i] = Route[i].Position; } } else { m_routePointCurve.Clear(); foreach (var node in Route) { m_routePointCurve.Add(node.Position); } } if (m_routePointCurve.Finalize()) { var numSegments = Mathf.Max(Mathf.CeilToInt(ResolutionPerUnitLength * Route.TotalLength), 1); var result = m_routePointCurve.FindSegmentLength(numSegments, PointCurve.DefaultErrorFunc, 5.0E-3f, 1.0E-3f); if (result.Successful) { m_routePointResulutionPerUnitLength = ResolutionPerUnitLength; var routePoints = new List <Vector3>(); m_routePointCurve.Traverse((curr, next, type) => { routePoints.Add(curr.Point); if (type == PointCurve.SegmentType.Last && Mathf.Abs(next.Time - 1.0f) < Mathf.Abs(curr.Time - 1)) { routePoints.Add(next.Point); } }, result.SegmentLength); m_routePointsCache = routePoints.ToArray(); return(result); } } return(new PointCurve.SegmentationResult() { Error = float.PositiveInfinity, Successful = false }); }