protected override IStyleData Calculate(MarkupRegularLine line, ITrajectory trajectory, MarkupLOD lod)
        {
            if (!IsValid)
            {
                return(new MarkupStyleParts());
            }

            if (Invert)
            {
                trajectory = trajectory.Invert();
            }

            if (Shift != 0)
            {
                var startNormal = trajectory.StartDirection.Turn90(!Invert);
                var endNormal   = trajectory.EndDirection.Turn90(Invert);

                trajectory = new BezierTrajectory(trajectory.StartPosition + startNormal * Shift, trajectory.StartDirection, trajectory.EndPosition + endNormal * Shift, trajectory.EndDirection);
            }

            var length = trajectory.Length;

            if (OffsetBefore + OffsetAfter >= length)
            {
                return(new MarkupStyleParts());
            }

            var startT = OffsetBefore == 0f ? 0f : trajectory.Travel(OffsetBefore);
            var endT   = OffsetAfter == 0f ? 1f : 1f - trajectory.Invert().Travel(OffsetAfter);

            trajectory = trajectory.Cut(startT, endT);

            var count        = Mathf.CeilToInt(trajectory.Length / RepeatDistance);
            var trajectories = new ITrajectory[count];

            if (count == 1)
            {
                trajectories[0] = trajectory;
            }
            else
            {
                for (int i = 0; i < count; i += 1)
                {
                    trajectories[i] = trajectory.Cut(1f / count * i, 1f / count * (i + 1));
                }
            }

            return(new MarkupStyleNetwork(Prefab, trajectories, Prefab.Value.m_halfWidth * 2f, Prefab.Value.m_segmentLength, Scale, Elevation));
        }
Beispiel #2
0
        protected bool Cut(MarkupCrosswalk crosswalk, ITrajectory trajectory, float width, out ITrajectory cutTrajectory)
        {
            var delta = width / Mathf.Tan(crosswalk.CornerAndNormalAngle) / 2;

            if (2 * delta >= trajectory.Magnitude)
            {
                cutTrajectory = default;
                return(false);
            }
            else
            {
                var startCut = trajectory.Travel(0, delta);
                var endCut   = trajectory.Invert().Travel(0, delta);
                cutTrajectory = trajectory.Cut(startCut, 1 - endCut);
                return(true);
            }
        }