Esempio n. 1
0
        private void ExtendToBorders()
        {
            var firstSegment = Segments.First(fs => !fs.IsVirtual);
            var firstBound   = (IStringBoundary)Layout.GetStringBoundaryLine(firstSegment.String, FingerboardSide.Treble);//first segment is toward treble side so edge is at right (Treble)

            var lastSegment = Segments.Last(fs => !fs.IsVirtual);
            var lastBound   = (IStringBoundary)Layout.GetStringBoundaryLine(lastSegment.String, FingerboardSide.Bass);//last segment is toward bass side so edge is at left (Bass)

            if (Points.Count == 1)
            {
                Points.Insert(0, firstBound.GetRelativePoint(firstSegment.String.LayoutLine, firstSegment.PointOnString));
                Points.Add(lastBound.GetRelativePoint(firstSegment.String.LayoutLine, firstSegment.PointOnString));
                Spline = null;
                return;
            }

            if (Points.Count == 2)
            {
                Points.Insert(0, GetIntersection((LayoutLine)firstBound));
                Points.Add(GetIntersection((LayoutLine)lastBound));
                Spline = null;
                return;
            }

            TrimBetween((LayoutLine)firstBound, (LayoutLine)lastBound, true);
        }
Esempio n. 2
0
 /// <summary>
 /// Extends a memory chunk references list by adding a new reference. If the new reference is contiguous to the last existing reference,
 /// then the list size remains constant.
 /// </summary>
 /// <param name="memoryChunkReferences"></param>
 /// <param name="newSegment"></param>
 public void ExtendSegments(MemoryBlockIDAndSlice blockAndSlice, bool extendEarlierReferencesForSameChunk)
 {
     if (Segments.Any())
     {
         if (extendEarlierReferencesForSameChunk)
         {
             for (int i = 0; i < Segments.Count; i++)
             {
                 var segment = Segments[i];
                 if (segment.MemoryBlockID == blockAndSlice.MemoryBlockID)
                 {
                     MemoryChunk existingChunk = GetMemoryChunkByMemoryBlockID(segment.MemoryBlockID);
                     if (existingChunk != null)
                     {
                         existingChunk.LoadingInfo.PreTruncationLength = blockAndSlice.Length;
                     }
                 }
             }
         }
         var last = Segments.Last();
         if (last.MemoryBlockID == blockAndSlice.MemoryBlockID && blockAndSlice.Offset == last.Offset + last.Length)
         {
             last = new MemoryBlockIDAndSlice(last.MemoryBlockID, last.Offset, last.Length + blockAndSlice.Length);
             Segments[Segments.Count - 1] = last;
             PatchesTotalLength          += blockAndSlice.Length;
             return;
         }
     }
     Segments.Add(new MemoryBlockIDAndSlice(blockAndSlice.MemoryBlockID, blockAndSlice.Offset, blockAndSlice.Length));
     PatchesTotalLength += blockAndSlice.Length;
 }
Esempio n. 3
0
        public GlobalPath ChangeExtension(string newExtension)
        {
            if (Segments.Count == 0)
            {
                throw new KOSInvalidPathException("This path points to the root directory, you can't change its extension", this.ToString());
            }

            string        nameSegment = Segments.Last();
            List <string> newSegments = new List <string>(Segments);

            newSegments.RemoveAt(newSegments.Count - 1);
            var nameParts = new List <string>(nameSegment.Split('.'));

            if (nameParts.Count() > 1)
            {
                nameParts.RemoveAt(nameParts.Count() - 1);
            }

            nameParts = new List <string>(nameParts);
            nameParts.Add(newExtension);

            var newName = String.Join(".", nameParts.ToArray());

            newSegments.Add(newName);

            return(new GlobalPath(VolumeId, newSegments));
        }
Esempio n. 4
0
        public void Update()
        {
            var secondsSinceStart = AntManagerState.Instance.WorkoutElapsedTime;

            var currentSegment = CurrentSegment;
            var nextSegment    = NextSegment;

            if (currentSegment == null)
            {
                AntManagerState.Instance.TargetPower = 0;
            }
            else
            {
                Console.WriteLine("Target power : {0}", currentSegment.TargetRelativePowerIntensity);
                AntManagerState.Instance.TargetPower           = currentSegment.TargetRelativePowerIntensity * AntManagerState.Instance.CriticalPower;
                AntManagerState.Instance.RemainingIntervalTime = currentSegment.EndTimeSeconds - secondsSinceStart;
                AntManagerState.Instance.RemainingTotalTime    = Segments.Last().EndTimeSeconds - secondsSinceStart;
                AntManagerState.Instance.WorkoutMessage        = CurrentMessage;
                if (nextSegment != null)
                {
                    AntManagerState.Instance.NextTargetPower = nextSegment.TargetRelativePowerIntensity * AntManagerState.Instance.CriticalPower;
                }
                else
                {
                    AntManagerState.Instance.NextTargetPower = 0;
                }
            }
        }
Esempio n. 5
0
        public BracketedExpressionSegment(IEnumerable <IExpressionSegment> segments)
        {
            if (segments == null)
            {
                throw new ArgumentNullException("segments");
            }

            Segments = segments.ToList().AsReadOnly();
            if (Segments.Any(e => e == null))
            {
                throw new ArgumentException("Null reference encountered in segments set");
            }
            if (!Segments.Any())
            {
                throw new ArgumentException("Empty segments set specified - invalid");
            }

            // 2015-03-23 DWR: For deeply-nested bracketed segments, it can be very expensive to enumerate over their AllTokens sets repeatedly so it's worth preparing the data once and
            // avoiding doing it over and over again. This is often seen with an expression with many string concatenations - currently they are broken down into pairs of operations,
            // which results in many bracketed operations (I want to change this for concatenations going forward, since it's so common to have sets of concatenations and it would
            // be better if the CONCAT took a variable number of arguments rather than just two, but this hasn't been done yet).
            _allTokens =
                new IToken[] { new OpenBrace(Segments.First().AllTokens.First().LineIndex) }
            .Concat(Segments.SelectMany(s => s.AllTokens))
            .Concat(new[] { new CloseBrace(Segments.Last().AllTokens.Last().LineIndex) })
            .ToList()
            .AsReadOnly();
        }
Esempio n. 6
0
            public override string ToString()
            {
                var sb = new StringBuilder();

                Segments.ForEach(x => sb.AppendFormat("{0}->", x.Location1));
                sb.Append(Segments.Last().Location2);
                return(sb.ToString());
            }
Esempio n. 7
0
        private ODataPathKind CalcPathType()
        {
            if (Segments.Count == 1 && Segments.First().Kind == ODataSegmentKind.Metadata)
            {
                return(ODataPathKind.Metadata);
            }
            else if (Segments.Last().Kind == ODataSegmentKind.DollarCount)
            {
                return(ODataPathKind.DollarCount);
            }
            else if (Segments.Last().Kind == ODataSegmentKind.TypeCast)
            {
                return(ODataPathKind.TypeCast);
            }
            else if (Segments.Last().Kind == ODataSegmentKind.ComplexProperty)
            {
                return(ODataPathKind.ComplexProperty);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.StreamProperty || c.Kind == ODataSegmentKind.StreamContent))
            {
                return(ODataPathKind.MediaEntity);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Ref))
            {
                return(ODataPathKind.Ref);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.OperationImport))
            {
                return(ODataPathKind.OperationImport);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Operation))
            {
                return(ODataPathKind.Operation);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.NavigationProperty))
            {
                return(ODataPathKind.NavigationProperty);
            }
            else if (Segments.Count == 1 && Segments[0] is ODataNavigationSourceSegment segment)
            {
                if (segment.NavigationSource is IEdmSingleton)
                {
                    return(ODataPathKind.Singleton);
                }
                else
                {
                    return(ODataPathKind.EntitySet);
                }
            }
            else if (Segments.Count == 2 && Segments.Last().Kind == ODataSegmentKind.Key)
            {
                return(ODataPathKind.Entity);
            }

            return(ODataPathKind.Unknown);
        }
Esempio n. 8
0
        public double ValueAt(double time)
        {
            foreach (var segment in Segments)
            {
                var points = segment.Points;
                if (time <= points.Last().Time)
                {
                    return((points[0].Time <= time) ? segment.ValueAt(time) : points[0].Value);
                }
            }

            return(Segments.Last().Points.Last().Value);
        }
Esempio n. 9
0
        public Tuple <LayoutLine, LayoutLine> GetFretBoundaries(bool trebleToBass = true)
        {
            var firstSegment = Segments.First(fs => !fs.IsVirtual);
            var firstBound   = Layout.GetStringBoundaryLine(firstSegment.String, FingerboardSide.Treble);//first segment is toward treble side so edge is at right (Treble)

            var lastSegment = Segments.Last(fs => !fs.IsVirtual);
            var lastBound   = Layout.GetStringBoundaryLine(lastSegment.String, FingerboardSide.Bass);//last segment is toward bass side so edge is at left (Bass)

            if (!trebleToBass)
            {
                return(new Tuple <LayoutLine, LayoutLine>(lastBound, firstBound));
            }
            return(new Tuple <LayoutLine, LayoutLine>(firstBound, lastBound));
        }
Esempio n. 10
0
        private void setupArgumentsAndSpread()
        {
            _arguments = new Lazy <RouteArgument[]>(() => Segments.OfType <RouteArgument>().ToArray());
            _spread    = Segments.OfType <Spread>().SingleOrDefault();

            if (!HasSpread)
            {
                return;
            }

            if (!Equals(_spread, Segments.Last()))
            {
                throw new ArgumentOutOfRangeException(nameof(Pattern),
                                                      "The spread parameter can only be the last segment in a route");
            }
        }
Esempio n. 11
0
        //---------------------------------------------------------------------------

        public CorridorSegment AddSegment(Point start, Point end, int thickness)
        {
            if (Segments.Count > 0)
            {
                CorridorSegment segment = Segments.Last();
                if (GetDirection(segment.Start, segment.End) == GetDirection(start, end))
                {
                    segment.End = end;
                    return(segment);
                }
            }
            CorridorSegment newSegment = new CorridorSegment(start, end, thickness);

            Segments.Add(newSegment);
            return(newSegment);
        }
Esempio n. 12
0
        private ODataPathKind CalcPathType()
        {
            if (Segments.Any(c => c.Kind == ODataSegmentKind.StreamProperty || c.Kind == ODataSegmentKind.StreamContent))
            {
                return(ODataPathKind.MediaEntity);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Ref))
            {
                return(ODataPathKind.Ref);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.OperationImport))
            {
                return(ODataPathKind.OperationImport);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Operation))
            {
                return(ODataPathKind.Operation);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.NavigationProperty))
            {
                return(ODataPathKind.NavigationProperty);
            }

            if (Segments.Count == 1)
            {
                ODataNavigationSourceSegment segment = Segments[0] as ODataNavigationSourceSegment;
                if (segment != null)
                {
                    if (segment.NavigationSource is IEdmSingleton)
                    {
                        return(ODataPathKind.Singleton);
                    }
                    else
                    {
                        return(ODataPathKind.EntitySet);
                    }
                }
            }
            else if (Segments.Count == 2 && Segments.Last().Kind == ODataSegmentKind.Key)
            {
                return(ODataPathKind.Entity);
            }

            return(ODataPathKind.Unknown);
        }
Esempio n. 13
0
 /// <summary>
 /// Gets the name of the directory.
 /// </summary>
 /// <returns>The directory name.</returns>
 /// <remarks>
 ///    If this is passed a file path, it will return the file name.
 ///    This is by-and-large equivalent to how DirectoryInfo handles this scenario.
 ///    If we wanted to return the *actual* directory name, we'd need to pull in IFileSystem,
 ///    and do various checks to make sure things exists.
 /// </remarks>
 public string GetDirectoryName()
 {
     return(Segments.Last());
 }
Esempio n. 14
0
 public void AddSegment()
 {
     Segments.Add(new SnakeSegment(Segments.Last().Position));
 }
Esempio n. 15
0
        public void ComputeFretShape()
        {
            VerifyIsStraight();
            //if (!IsStraight && !Layout.CompensateFretPositions && Layout.FretsTemperament == Physics.Temperament.Equal && CheckForHardBreak())
            //    return;

            var layout = Segments[0].String.Layout;

            if (Segments.Any(s => s.IsNut && !s.IsVirtual) && !Segments.All(s => s.IsNut || s.IsVirtual))
            {
                SeparateNutFromFrets();
                return;
            }

            if (IsStraight && Segments.Count > 1)
            {
                var leftBound  = layout.GetStringBoundaryLine(Segments.Last(fs => !fs.IsVirtual).String, FingerboardSide.Bass);
                var rightBound = layout.GetStringBoundaryLine(Segments.First(fs => !fs.IsVirtual).String, FingerboardSide.Treble);

                var line = Line.FromPoints(Segments.First().PointOnString.ToVector(), Segments.Last().PointOnString.ToVector());
                Points.Add(PointM.FromVector(line.GetIntersection(leftBound.Equation), UnitOfMeasure.Centimeters));
                Points.Add(PointM.FromVector(line.GetIntersection(rightBound.Equation), UnitOfMeasure.Centimeters));
            }
            else
            {
                if (Layout.FretInterpolation == FretInterpolationMethod.Spline && StringCount >= 2)
                {
                    foreach (var seg in Segments.Where(s => !s.IsVirtual || s.String.HasFret(s.FretIndex)))
                    {
                        Points.Add(seg.PointOnString);
                    }

                    InterpolateSplineV2(1d / (Segments.Count * 2.2));

                    ExtendToBorders();
                }
                else if (Layout.FretInterpolation == FretInterpolationMethod.NotchedSpline && StringCount >= 2)
                {
                    foreach (var seg in Segments.Where(s => !s.IsVirtual || s.String.HasFret(s.FretIndex)))
                    {
                        //Points.Add(seg.PointOnString + (seg.Direction * Measure.Mm(1.5)));
                        Points.Add(PointM.Average(seg.P2, seg.PointOnString));
                        //Points.Add(seg.PointOnString);
                        Points.Add(PointM.Average(seg.P1, seg.PointOnString));
                        //Points.Add(seg.PointOnString + (seg.Direction * -1 * Measure.Mm(1.5)));
                    }

                    InterpolateSpline(0.33, 0.4);

                    ExtendToBorders();
                }
                else
                {
                    foreach (var seg in Segments.Where(s => !s.IsVirtual))
                    {
                        Points.Add(seg.PointOnString);
                    }
                    ExtendToBorders();
                }

                (Points as ObservableCollectionEx <PointM>).Reverse();

                if (Points.Count == 2)
                {
                    _IsStraight = true;
                }
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Gets the name of the directory.
 /// </summary>
 /// <returns>The directory name.</returns>
 /// <remarks>
 /// If this is passed a file path, it will return the file name.
 /// This is by-and-large equivalent to how DirectoryInfo handles this scenario.
 /// If we wanted to return the *actual* directory name, we'd need to pull in IFileSystem,
 /// and do various checks to make sure things exists.
 /// </remarks>
 public string GetDirectoryName() => Segments.Last();
Esempio n. 17
0
    /// <summary>
    /// Used for ChaseCamera to stop it flying upwards
    /// </summary>

    /// <summary>
    /// Calculate the fence vertices after the control point
    /// </summary>
    public void CalcVisibleFenceVerts()
    {
        //This uses the XSecs to fill the two lists LFenceVerts and RFenceVerts
        //These are used to create the two gameobjects, LFence and RFence
        //The verts are always 3m apart.
        RaycastHit _hit;

        if (Segments.Count > 1)
        {
            Road Rd = Road.Instance;
            LFenceVerts.Clear();
            RFenceVerts.Clear();


            List <Vector3> LKerbs = (from x in Rd.XSecs
                                     where x.Idx >= Segments[0].Idx && x.Idx <= Segments.Last().Idx + 1
                                     select x.KerbL).ToList <Vector3>();
            if (RoadMaterial == "Air")
            {
                LKerbs = LKerbs.Select(k => Gnd(k)).ToList();
            }
            //See I added the first xsec of the next section
            //if (Rd.Sectns[Idx + 1].Segments.Count==0) return;                              //So we don't try to calculate for the last section
            Vector3 CurrPos = LKerbs[0];
            LFenceVerts.Add(CurrPos);
            int   NxtKerbIdx = 1;
            float SegLength;
            float TotDist;
            float Bckdist;
            float DistRem = Vector3.Distance(CurrPos, LKerbs.Last());
            while (DistRem > 3.0f)
            {
                //Find the next kerb point 3 meters along
                SegLength = 0;
                TotDist   = Vector3.Distance(CurrPos, LKerbs[NxtKerbIdx]);
                if (TotDist > 3)
                {
                    SegLength = Vector3.Distance(CurrPos, LKerbs[NxtKerbIdx]);
                }
                while (TotDist < 3)
                {
                    CurrPos = LKerbs[NxtKerbIdx];
                    //Yeah but the air road fences should be on the ground

                    NxtKerbIdx++;
                    SegLength = Vector3.Distance(CurrPos, LKerbs[NxtKerbIdx]);
                    TotDist  += SegLength;
                } //Now we've got to the KerbPoint after the 3m mark.
                //We have to go backward to the 3m mark
                Bckdist = TotDist - 3;
                CurrPos = Vector3.Lerp(LKerbs[NxtKerbIdx], CurrPos, Bckdist / SegLength);
                LFenceVerts.Add(CurrPos);
                DistRem = Vector3.Distance(CurrPos, LKerbs.Last());
            }
            //Add the first kerb point of the next section
            XSec LastXSec = Rd.XSecs[Segments.Last().Idx];
            LFenceVerts.Add(RoadMaterial == "Air"? Gnd(Rd.XSecPlusOne(LastXSec).KerbL): Rd.XSecPlusOne(LastXSec).KerbL);

//Right Kerbs
            List <Vector3> RKerbs = (from x in Rd.XSecs
                                     where x.Idx >= Segments[0].Idx && x.Idx <= Segments.Last().Idx + 1 //See I added the first xsec of the next section
                                     select x.KerbR).ToList <Vector3>();
            if (RoadMaterial == "Air")
            {
                RKerbs = RKerbs.Select(k => Gnd(k)).ToList();
            }

            CurrPos = RKerbs[0];
            RFenceVerts.Add(CurrPos);
            NxtKerbIdx = 1;
            DistRem    = Vector3.Distance(CurrPos, RKerbs.Last());
            while (DistRem > 3.0f)
            {
                //Find the next kerb point 3 meters along
                SegLength = 0;
                TotDist   = Vector3.Distance(CurrPos, RKerbs[NxtKerbIdx]);
                if (TotDist > 3)
                {
                    SegLength = Vector3.Distance(CurrPos, RKerbs[NxtKerbIdx]);
                }
                while (TotDist < 3)
                {
                    CurrPos = RKerbs[NxtKerbIdx];
                    NxtKerbIdx++;
                    SegLength = Vector3.Distance(CurrPos, RKerbs[NxtKerbIdx]);
                    TotDist  += SegLength;
                } //Now we've got to the KerbPoint after the 3m mark.
                //We have to go backward to the 3m mark
                Bckdist = TotDist - 3;
                CurrPos = Vector3.Lerp(RKerbs[NxtKerbIdx], CurrPos, Bckdist / SegLength);
                RFenceVerts.Add(CurrPos);
                DistRem = Vector3.Distance(CurrPos, RKerbs.Last());
            }
            RFenceVerts.Add(RoadMaterial == "Air" ? Gnd(Rd.XSecPlusOne(LastXSec).KerbR): Rd.XSecPlusOne(LastXSec).KerbR);
        }
    }
Esempio n. 18
0
        /// <summary>
        /// Method <c>Move</c> "moves" the snake
        /// </summary>
        public void Move()
        {
            Console.SetCursorPosition((head.Key + 4) * 2, head.Value + 2);
            CircularQueue <KeyValuePair <int, int> > segments2 = new CircularQueue <KeyValuePair <int, int> >(Length);
            KeyValuePair <int, int> tempSeg = head;

            if (Segments.Size >= Length)
            {
                KeyValuePair <int, int> del = Segments.Dequeue();

                DeleteLeftovers(del.Key + 1, del.Value);
                DeleteLeftovers(del.Key - 1, del.Value);
                DeleteLeftovers(del.Key, del.Value + 1);
                DeleteLeftovers(del.Key, del.Value - 1);
            }
            else
            {
                Segments.Size++;
            }

            for (int i = 0; i < Segments.Count;)
            {
                segments2.Enqueue(Segments.Dequeue());
            }


            switch (Compass)
            {
            case Direction.UP:
                if (HitEgg())
                {
                    EatEgg();
                    Grid.Tiles[tempSeg.Key, tempSeg.Value - 1] = 1;
                }
                else if (HitObstacle() || HitSelf())
                {
                    Speed  = 0;
                    IsDead = true;
                }
                segments2.Enqueue(new KeyValuePair <int, int>(tempSeg.Key, tempSeg.Value - 1));
                break;

            case Direction.LEFT:
                if (HitEgg())
                {
                    EatEgg();
                    Grid.Tiles[tempSeg.Key - 1, tempSeg.Value] = 1;
                }
                else if (HitObstacle() || HitSelf())
                {
                    Speed  = 0;
                    IsDead = true;
                }
                segments2.Enqueue(new KeyValuePair <int, int>(tempSeg.Key - 1, tempSeg.Value));
                break;

            case Direction.RIGHT:
                if (HitEgg())
                {
                    EatEgg();
                    Grid.Tiles[tempSeg.Key + 1, tempSeg.Value] = 1;
                }
                else if (HitObstacle() || HitSelf())
                {
                    Speed  = 0;
                    IsDead = true;
                }
                segments2.Enqueue(new KeyValuePair <int, int>(tempSeg.Key + 1, tempSeg.Value));
                break;

            case Direction.DOWN:
                if (HitEgg())
                {
                    EatEgg();
                    Grid.Tiles[tempSeg.Key, tempSeg.Value + 1] = 1;
                }
                else if (HitObstacle() || HitSelf())
                {
                    Speed  = 0;
                    IsDead = true;
                }
                segments2.Enqueue(new KeyValuePair <int, int>(tempSeg.Key, tempSeg.Value + 1));
                break;
            }

            if (Length > 0)
            {
                Segments = segments2;
            }
            head = Segments.Last();
        }