Esempio n. 1
0
 // ----------------------------------------------------------------------------------------------------
 // Moves position information to the beginning of the network
 // ----------------------------------------------------------------------------------------------------
 public void MoveToStart(ref PositionInformation _positionInformation)
 {
     _positionInformation.m_Position        = m_Nodes[0];
     _positionInformation.m_Segment         = 0;
     _positionInformation.m_SegmentRatio    = 0.0f;
     _positionInformation.m_TotalDistance   = 0.0f;
     _positionInformation.m_SegmentDistance = 0.0f;
 }
Esempio n. 2
0
 // ----------------------------------------------------------------------------------------------------
 // Moves the position information to the end of the network
 // ----------------------------------------------------------------------------------------------------
 public void MoveToEnd(ref PositionInformation _positionInformation)
 {
     _positionInformation.m_Position        = m_Nodes[m_NodeCount - 1];
     _positionInformation.m_Segment         = m_NodeCount - 2;
     _positionInformation.m_SegmentRatio    = 1.0f;
     _positionInformation.m_TotalDistance   = m_Length;
     _positionInformation.m_SegmentDistance = m_SegmentLength[_positionInformation.m_Segment];
 }
Esempio n. 3
0
 // ----------------------------------------------------------------------------------------------------
 // Moves to the end of the network
 // ----------------------------------------------------------------------------------------------------
 void End(ref PositionInformation _positionInformation, bool _reverseDirection)
 {
     if (_reverseDirection)
     {
         MoveToStart(ref _positionInformation);
     }
     else
     {
         MoveToEnd(ref _positionInformation);
     }
 }
Esempio n. 4
0
 private bool ValidateException(
     JsonMasherException ex,
     string expectedMessage,
     PositionInformation expectedPositionInformation)
 {
     ex.Message.Should().Be(expectedMessage);
     if (expectedPositionInformation != null)
     {
         ex.Line.Should().Be(expectedPositionInformation.Line);
         ex.Column.Should().Be(expectedPositionInformation.Column);
         ex.Highlights.CleanCR().Should().Be(expectedPositionInformation.Highlights.CleanCR());
     }
     return(true);
 }
Esempio n. 5
0
 private bool VerifyException(
     JsonMasherException ex,
     string messageExpectation,
     PositionInformation positionInformationExpectation)
 {
     ex.Message.Should().Be(messageExpectation);
     if (positionInformationExpectation != null)
     {
         ex.Line.Should().Be(positionInformationExpectation.Line);
         ex.Column.Should().Be(positionInformationExpectation.Column);
         ex.Highlights.CleanCR().Should().Be(positionInformationExpectation.Highlights.CleanCR());
     }
     return(true);
 }
Esempio n. 6
0
    // ----------------------------------------------------------------------------------------------------
    // Projects a position on the network
    // ----------------------------------------------------------------------------------------------------
    public override PositionInformation ProjectOnNetwork(Vector3 _position)
    {
        PositionInformation projection = new PositionInformation();

        float closestSquareDistance = m_MaxSquareDistanceCheck;
        int   closestIndex          = -1;
        float currentSquareDistance;

        for (int i = 0; i < m_NodeCount; i++)
        {
            currentSquareDistance = Vector3.SqrMagnitude(_position - m_Nodes[i]);
            if (currentSquareDistance < closestSquareDistance)
            {
                closestIndex          = i;
                closestSquareDistance = currentSquareDistance;
            }
        }

        if (closestIndex != -1)
        {
            Vector3 node1 = closestIndex > 0 ? m_Nodes[closestIndex - 1] : m_Nodes[closestIndex];
            Vector3 node2 = m_Nodes[closestIndex];
            Vector3 node3 = closestIndex < m_NodeCount - 1 ? m_Nodes[closestIndex + 1] : m_Nodes[closestIndex];
            Vector3 point1 = Math.ProjectPointOnSegment(node1, node2, _position), point2 = Math.ProjectPointOnSegment(node2, node3, _position);

            if (Vector3.SqrMagnitude(_position - point1) < Vector3.SqrMagnitude(_position - point2))
            {
                projection.m_Position = point1;
                projection.m_Segment  = closestIndex - 1;
            }
            else
            {
                projection.m_Position = point2;
                projection.m_Segment  = closestIndex;
            }

            projection.m_SegmentDistance = (projection.m_Position - m_Nodes[projection.m_Segment]).magnitude;
            projection.m_SegmentRatio    = projection.m_SegmentDistance / m_SegmentLength[projection.m_Segment];

            for (int i = 0; i < projection.m_Segment; i++)
            {
                projection.m_TotalDistance += m_SegmentLength[i];
            }

            projection.m_TotalDistance += projection.m_SegmentDistance;
        }

        return(projection);
    }
Esempio n. 7
0
        public void ParseTest(
            string program,
            string messageExpectation,
            PositionInformation positionInformationExpectation)
        {
            // Arrange
            var parser = new Parser();

            // Act
            Action action = () => parser.Parse(program);

            // Assert
            action
            .Should().Throw <JsonMasherException>()
            .Where(e => VerifyException(e, messageExpectation, positionInformationExpectation));
        }
Esempio n. 8
0
    // ----------------------------------------------------------------------------------------------------
    // Loops to the other side of the network
    // ----------------------------------------------------------------------------------------------------
    void Loop(ref PositionInformation _positionInformation, float _distance, ref bool _reverseDirection)
    {
        _distance -= _reverseDirection ? -_positionInformation.m_TotalDistance : _positionInformation.m_TotalDistance - m_Length;

        if (_reverseDirection)
        {
            MoveToEnd(ref _positionInformation);
        }
        else
        {
            MoveToStart(ref _positionInformation);
        }

        // Continues recursively
        Advance(ref _positionInformation, _distance, Mode.Loop, ref _reverseDirection);
    }
Esempio n. 9
0
        public void GetPosition_ReturnsCorrectInformation(int x, int y, PositionInformation expected)
        {
            var input  = @"..##.......
#...#...#..
.#....#..#.
..#.#...#.#
.#...##..#.
..#.##.....
.#.#.#....#
.#........#
#.##...#...
#...##....#
.#..#...#.#";
            var map    = new LoopingMap(input);
            var actual = map.GetPosition(x, y);

            Assert.Equal(expected, actual);
        }
Esempio n. 10
0
    // ----------------------------------------------------------------------------------------------------
    // Advances on a network using specified distance, mode and direction
    // ----------------------------------------------------------------------------------------------------
    public override void Advance(ref PositionInformation _positionInformation, float _distance, Network.Mode _mode, ref bool _reverseDirection)
    {
        _positionInformation.m_TotalDistance += _reverseDirection ? -_distance : _distance;

        // Reached the end of the network
        if (_positionInformation.m_TotalDistance < 0.0f || _positionInformation.m_TotalDistance > m_Length)
        {
            switch (_mode)
            {
            case Mode.Forward:
                End(ref _positionInformation, _reverseDirection);
                break;

            case Mode.Loop:
                Loop(ref _positionInformation, _distance, ref _reverseDirection);
                break;

            case Mode.BackAndForth:
                Reverse(ref _positionInformation, _distance, ref _reverseDirection);
                break;
            }
        }
        else
        {
            _positionInformation.m_SegmentDistance += _reverseDirection ? -_distance : _distance;

            while (_positionInformation.m_SegmentDistance < 0.0f || _positionInformation.m_SegmentDistance > m_SegmentLength[_positionInformation.m_Segment])
            {
                _positionInformation.m_SegmentDistance -= _reverseDirection ? -m_SegmentLength[_positionInformation.m_Segment - 1] : m_SegmentLength[_positionInformation.m_Segment];
                _positionInformation.m_Segment         += _reverseDirection ? -1 : 1;

                Assertion.Assert(_positionInformation.m_Segment != -1, "Bad segment number");
            }

            _positionInformation.m_SegmentRatio = _positionInformation.m_SegmentDistance / m_SegmentLength[_positionInformation.m_Segment];
            _positionInformation.m_Position     = m_Nodes[_positionInformation.m_Segment] + (m_SegmentDirection[_positionInformation.m_Segment] * _positionInformation.m_SegmentDistance);
        }
    }
Esempio n. 11
0
        public void ProgramTest(
            string program,
            string inputJson,
            string expectedMessage,
            PositionInformation expectedPositionInformation)
        {
            // Arrange
            var parser = new Parser();

            var(filter, sourceInformation) = parser.Parse(program);
            var input = inputJson.AsJson().AsEnumerable();

            // Act
            Action action = () => {
                var(result, context) = new Mashers.JsonMasher().Mash(
                    input, filter, new DebugMashStack(), sourceInformation);
                result.ToList();
            };

            // Assert
            action
            .Should().Throw <JsonMasherException>()
            .Where(ex => ValidateException(ex, expectedMessage, expectedPositionInformation));
        }
Esempio n. 12
0
 // ----------------------------------------------------------------------------------------------------
 // Advances on a network using specified distance, mode and direction
 // ----------------------------------------------------------------------------------------------------
 public abstract void Advance(ref PositionInformation _positionInformation, float _distance, Network.Mode _mode, ref bool _reverseDirection);
Esempio n. 13
0
 private record TestItem(
     string Program,
     string InputJson,
     string ExpectedMessage,
     PositionInformation ExpectedPositionInformation);
Esempio n. 14
0
        /// <summary>
        /// Получение элемента семантического дерева по его смещению
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public VhdlElement GetElementByOffset(VhdlElement parent, int offset)
        {
            if ((parent == null) || (file == null))
            {
                return(null);
            }

            if (((parent is IDeclarativeRegion) == false) && ((parent is SequentialStatement) == false))
            {
                return(parent);
            }

            if (parent is IDeclarativeRegion)
            {
                IDeclarativeRegion decl    = parent as IDeclarativeRegion;
                List <object>      objects = decl.Scope.GetLocalListOfObjects();
                if (objects.Count >= 1)
                {
                    foreach (object obj in objects)
                    {
                        if (parent == obj)
                        {
                            continue;
                        }
                        if (obj is VhdlElement)
                        {
                            PositionInformation pos = GetPositionInformation(obj as VhdlElement);
                            if ((pos != null) && (pos.Begin.Index <= offset) && (pos.End.Index >= offset))
                            {
                                (obj as VhdlElement).Parent = (parent as IDeclarativeRegion);
                                return(GetElementByOffset(obj as VhdlElement, offset));
                            }
                            if (pos == null)
                            {
                                (obj as VhdlElement).Parent = (parent as IDeclarativeRegion);
                                return(obj as VhdlElement);
                            }
                        }
                    }
                }
            }
            if (parent is SequentialStatement)
            {
                SequentialStatement stat    = parent as SequentialStatement;
                List <VhdlElement>  objects = stat.GetAllStatements();
                if (objects.Count >= 1)
                {
                    foreach (VhdlElement obj in objects)
                    {
                        if (parent == obj)
                        {
                            continue;
                        }
                        if (obj == null)
                        {
                            continue;
                        }

                        PositionInformation pos = GetPositionInformation(obj as VhdlElement);
                        if ((pos != null) && (pos.Begin.Index <= offset) && (pos.End.Index >= offset))
                        {
                            (obj as VhdlElement).Parent = ((parent as SequentialStatement).Parent);
                            return(GetElementByOffset(obj as VhdlElement, offset));
                        }
                        if (pos == null)
                        {
                            (obj as VhdlElement).Parent = (parent as IDeclarativeRegion);
                            return(obj as VhdlElement);
                        }
                    }
                }
            }
            return(parent);
        }
Esempio n. 15
0
 public record TestItem(
     string Program,
     string MessageExpectation,
     PositionInformation PositionInformationExpectation);
Esempio n. 16
0
        private void AddPositionAnnotation(VhdlElement element, ParserRuleContext context)
        {
            PositionInformation info = ContextToPosition(context);

            Annotations.putAnnotation(element, info);
        }