Exemplo n.º 1
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();
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public DocContainer(EdiSegmentCollection segs, GroupContainer parent)
        {
            _elDelimiter = segs.ElementDelimiter;
            Segments     = segs.SegmentList;
            var els = Segments.First().GetElements(_elDelimiter);

            DocType       = els[1];
            ControlNumber = els[2].CastToInt();
            ParentGroup   = parent;
        }
Exemplo n.º 5
0
        public bool Remove(Position p)
        {
            if (Segments.Any(s => s.Position == p))
            {
                Segments.First(s => s.Position == p).RemoveElement();
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
        public bool RemoveBuilding(IBuilding building)
        {
            if (!this.Buildings.Contains(building))
            {
                return(false);
            }
            var segment = Segments.First(s => s.Position.X == building.Position.X ||
                                         s.Position.Y == building.Position.Y);

            segment.Buildings.Remove(building);
            return(true);
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
0
        public int MoveSegment2NextPosition(Segment segment)
        {
            var orderId = -1;

            foreach (var seg in Segments.OrderBy(t => t.OrderId))
            {
                orderId++;
                seg.OrderId = orderId;
            }
            var oldIndex = Segments[Segments.IndexOf(segment)].OrderId;

            if (oldIndex == Segments.Count - 1)
            {
                return(oldIndex);
            }
            Segments.First(t => t.OrderId == oldIndex + 1).OrderId = oldIndex;
            segment.OrderId = oldIndex + 1;
            return(segment.OrderId);
        }
Exemplo n.º 9
0
        public bool AddBuilding(IBuilding building)
        {
            if (building == null || Buildings.Any(b => b.Position.Equals(building.Position)))
            {
                return(false);
            }

            var segment = Segments.First(s => s.Position.X == building.Position.X ||
                                         s.Position.Y == building.Position.Y);

            if (IsVertical)
            {
                building.Direction = building.Position.X > this.Start.X ? Direction.Right : Direction.Left;
            }
            else
            {
                building.Direction = building.Position.Y > this.Start.Y ? Direction.Up : Direction.Down;
            }

            segment.Buildings.Add(building);
            return(true);
        }
Exemplo n.º 10
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;
                }
            }
        }
Exemplo n.º 11
0
        private void HandleInput()
        {
            if (Input.KeyboardHold(Keys.S))             // Select nearest vertex
            {
                var foundVertex = Vertices.IndexOf(Vertices.OrderBy(v => (v.Position - Input.MousePos.ToVector2()).LengthSquared()).First());

                if (Input.MouseClick)
                {
                    currentVertex = foundVertex;
                }

                if (Input.RightMouseClick)
                {
                    currentShiftVertex = foundVertex;
                }
            }
            else             // Toggle static or add segments
            {
                if (Input.MouseClick)
                {
                    Vertices[currentVertex].StaticPos = Input.MousePos.ToVector2();
                    Vertices[currentVertex].Static    = !Vertices[currentVertex].Static;
                }

                if (Input.RightMouseClick)
                {
                    var newVertex = new ChainVertex(Input.MousePos.ToVector2(), (float)(Rand.NextDouble() * 8f + 4f), 0.9f, 0.5f, GRAVITY);
                    Vertices.Add(newVertex);

                    Segments.Add(new ChainSegment(newVertex, Vertices[currentVertex], (float)(Rand.NextDouble() * 20f + 10f)));

                    currentVertex = Vertices.Count - 1;
                }
            }

            if (Input.KeyboardClick(Keys.L))             // Link / Unlink
            {
                if (currentShiftVertex != currentVertex)
                {
                    if (Input.Shift)
                    {
                        var foundSegment = Segments.First(s => (s.Vertex1 == Vertices[currentVertex] && s.Vertex2 == Vertices[currentShiftVertex]) || (s.Vertex2 == Vertices[currentVertex] && s.Vertex1 == Vertices[currentShiftVertex]));

                        if (foundSegment != null)
                        {
                            Segments.Remove(foundSegment);
                        }
                    }
                    else
                    {
                        Segments.Add(new ChainSegment(Vertices[currentShiftVertex], Vertices[currentVertex], (float)(Rand.NextDouble() * 20f + 10f)));
                    }
                }
            }

            if (Input.ScrollDown)             // Change selected vertices
            {
                if (Input.Shift)
                {
                    currentShiftVertex++;
                    if (currentShiftVertex >= Vertices.Count)
                    {
                        currentShiftVertex = 0;
                    }
                }
                else
                {
                    currentVertex++;
                    if (currentVertex >= Vertices.Count)
                    {
                        currentVertex = 0;
                    }
                }
            }
            if (Input.ScrollUp)
            {
                if (Input.Shift)
                {
                    currentShiftVertex--;
                    if (currentShiftVertex < 0)
                    {
                        currentShiftVertex = Vertices.Count - 1;
                    }
                }
                else
                {
                    currentVertex--;
                    if (currentVertex < 0)
                    {
                        currentVertex = Vertices.Count - 1;
                    }
                }
            }

            if (Input.KeyboardHold(Keys.H))             // Hold current vertex to mouse
            {
                Vertices[currentVertex].Position = Input.MousePos.ToVector2();
            }

            if (Input.KeyboardClick(Keys.Back) || Input.KeyboardClick(Keys.Delete))             // Delete current vertex
            {
                if (Vertices.Count > 1)
                {
                    var vertexToDelete = Vertices[currentVertex];

                    foreach (var s in Segments.Where(s => s.Vertex1 == vertexToDelete || s.Vertex2 == vertexToDelete).ToList())
                    {
                        Segments.Remove(s);
                    }

                    Vertices.Remove(vertexToDelete);

                    if (currentVertex >= Vertices.Count)
                    {
                        currentVertex = Vertices.Count - 1;
                    }
                }
            }

            if (Input.KeyboardClick(Keys.I))
            {
                ShowStats = !ShowStats;
            }
        }