Example #1
0
    public bool SearchOctant( 
        Map                 map, 
        Compass             compass,
        int                 start,
        SearchDirection     direction,
        Tour                tour 
        )
    {
        SearchSet           oc = m_Octants[(int)compass];
        int                 incr = direction == SearchDirection.Outwards ? 1 : -1;

        for( int i=start;;i+=incr)
        {
            if( i < 0 || i > m_Radius ) return false;

            EntrySet entrySet = oc.GetEntrySet( i );

            if( entrySet == null ) continue;

            List<Entry> entries = entrySet.Entries;

            foreach( OctantEntry entry in entries )
            {
                if( tour( map, entry.X, entry.Y ) )
                    return true;
            }

            return false;
        }
    }
        public static bool CheckForCloneNums(String[,] tableToSolve, int rank, int tableWidth, int tableHeight, SearchDirection direction)
        {
            int count;

            for (int i = 0; i < tableWidth; i++)
            {
                for (int k = 1; k <= rank; k++)
                {
                    count = 0;

                    for (int j = 0; j < tableHeight; j++)
                    {
                        string value;

                        if (direction == SearchDirection.Vertical)
                            value = (string)tableToSolve.GetValue(i, j);
                        else
                            value = (string)tableToSolve.GetValue(j, i);

                        if (value == k.ToString()) count++;

                        if (count > 1) return true;
                    }
                }
            }

            return false;
        }
Example #3
0
 public static void Traverse(Node v, SearchDirection direction)
 {
     m_NodeStates.Clear();
     Queue<Node> queue = new Queue<Node>();
     queue.Enqueue(v);
     m_NodeStates[v] = NodeState.Grey;
     while (queue.Count != 0)
     {
         Node n = queue.Dequeue();
         foreach (Edge edge in (direction != SearchDirection.Forward) ? n.inputEdges : n.outputEdges)
         {
             if (OnDiscoverEdge != null)
             {
                 OnDiscoverEdge(new SearchEvent(n, edge));
             }
             Node key = (direction != SearchDirection.Forward) ? edge.fromSlot.node : edge.toSlot.node;
             if (!m_NodeStates.ContainsKey(key))
             {
                 if (OnDiscoverNode != null)
                 {
                     OnDiscoverNode(new SearchEvent(key, edge));
                 }
                 queue.Enqueue(key);
                 m_NodeStates[key] = NodeState.Grey;
             }
         }
         m_NodeStates[n] = NodeState.Black;
     }
 }
Example #4
0
//--------------------------------------------------------------------------------------------------
//  SearchContentricCircles -- search around the radii, moving in or out
//--------------------------------------------------------------------------------------------------
    public bool SearchConcentricCircles( 
        Map                 map, 
        int                 start, 
        SearchDirection     searchDirection,
        Tour                tour 
        )
    {
        return SearchConcentricCircles( map, start, ClockDirection.CounterClockwise, searchDirection, tour );
    }
Example #5
0
//------------------------------------------------------------------------------
//  SearchConcentric -- search all cells in a circle, around the center
//------------------------------------------------------------------------------
    public static bool ConcentricCircles( 
        Map                 map, 
        int                 start, 
        SearchDirection     searchDirection,
        Tour                tour 
        )
    {
        return m_CircleSearch.SearchConcentricCircles( map, start, searchDirection, tour );
    }
Example #6
0
//------------------------------------------------------------------------------
//  SearchOctant -- search all cells in an octant, from start range, going Inwards
//                 or going Outwards. Search will terminate if the Search delegate
//                 returns false any time during the tour
//------------------------------------------------------------------------------
    public static bool Octant( 
        Map                 map, 
        Direction           direction,
        int                 start,
        SearchDirection     searchDirection,
        Tour                tour 
        )
    {
        Compass compass = m_CompassLookup[(int)direction];

        return m_OctantSearch.SearchOctant( map, compass, start, searchDirection, tour );
    }
Example #7
0
//--------------------------------------------------------------------------------------------------
//  Spiral search
//--------------------------------------------------------------------------------------------------
    public bool SearchSpiral( 
        Map                 map, 
        int                 start,
        SearchDirection     direction,
        bool                randomStart,
        Tour                tour 
        )
    {
        int                 incr = ( direction == SearchDirection.Outwards ? 1 : -1 );
        bool                firstpass = true;

        for( int i=start;;i+=incr)
        {
            if( i < 0 || i > MAXRANGE ) break;

            SearchSet           ss      = m_SearchSets[i];
            List<SpiralEntry>   entries = ss.Entries;

            int startpos;
            
            if( randomStart && firstpass ) 
            { 
                startpos = Utility.RandomMinMax( 0, entries.Count ); 
            }
            else
            { 
                startpos = ( direction == SearchDirection.Outwards ? 0 : entries.Count - 1 );
            }

            for( int pos = startpos;;pos+=incr )
            {
                if( pos < 0 || pos > entries.Count-1 ) break;

                SpiralEntry entry = entries[pos];

                if( tour( map, entry.X, entry.Y ) ) return true;
            }

            firstpass = false;
        }

        return false;
    }
		public void Search(Regex pattern, SearchDirection dir)
		{
			var node = _curSearchBlock;

			// No search in progress; set current node to the bottom visible block
			if (node == null)
			{
				node = _bottomBlock != null ? _bottomBlock : _blocks.Last;
			}
			else
			{
				// Move back to the previous node. If we're at the top or bottom, do nothing.
				node = dir == SearchDirection.Previous ? _curSearchBlock.Previous : _curSearchBlock.Next;
				if (node == null)
				{
					return;
				}
			}

			while (node != null)
			{
				var matches = (from Match m in pattern.Matches(node.Value.Source.Text)
									 select new Tuple<int,int>(m.Index, m.Index + m.Length)).ToList();
				if(matches.Count > 0)
				{
					_curSearchBlock = node;
					_curSearchMatches = matches;
					break;
				}
				node = dir == SearchDirection.Previous ? node.Previous : node.Next;
			}

			if (_curSearchBlock != null)
			{
				this.ScrollIntoView(_curSearchBlock);
				this.InvalidateVisual();
			}
		}
Example #9
0
        private IConversation SearchAllNonCurrentConversations(IConversation startingConversation, SearchDirection searchDirection)
        {
            IConversation currentConversation = GetNextConversationToSearch(startingConversation, searchDirection);

            string wordToFind;

            if (!CaseSensitive)
            {
                wordToFind = Query.ToLower();
            }
            else
            {
                wordToFind = Query;
            }

            while (currentConversation != startingConversation)
            {
                if (_searchWorker.CancellationPending)
                {
                    throw new OperationCanceledException();
                }

                if (WordAppearsInConversation(wordToFind, currentConversation, searchDirection))
                {
                    return currentConversation;
                }

                currentConversation = GetNextConversationToSearch(currentConversation, searchDirection);
            }

            return null;
        }
Example #10
0
 private IConversation GetNextConversationToSearch(IConversation currentConversation, SearchDirection searchDirection)
 {
     if (searchDirection == SearchDirection.Down)
     {
         return _searchTarget.NextConversation(currentConversation);
     }
     else
     {
         return _searchTarget.PreviousConversation(currentConversation);
     }
 }
Example #11
0
 /// <summary>
 /// Nájde nasledujúci elem vyhovujúci všetkým podmienkam.
 /// Ukazuje na tento elem.
 /// </summary>
 /// <param name="dir"></param>
 /// <param name="tree"></param>
 /// <param name="vis"></param>
 /// <returns></returns>
 public IElement Find(SearchDirection dir, SearchVisibility vis)
 {
     return(Find(dir, vis, null));
 }
        private bool IsImmediate(float distance, double angle, SearchDirection immediateDirection)
        {
            // -90 degrees to 90 degrees. This is the default search angle
            double l = -1.5707963267948966;
            double r = 1.5707963267948966;

            if (distance < Settings.Instance.ImmediateRange1)
            {
                // Prevent searching on the non-neighboring side
                if ((immediateDirection & SearchDirection.Left) == SearchDirection.None)    l = 0;
                if ((immediateDirection & SearchDirection.Right) == SearchDirection.None)   r = 0;
            }
            else if (distance < Settings.Instance.ImmediateRange2 && (immediateDirection & SearchDirection.Ahead) != SearchDirection.None)
            {
                // Restrict the search on the non-neighboring side to 60 degrees to give enough space for merging
                if ((immediateDirection & SearchDirection.Left) == SearchDirection.None)    l = -1.0471975512;
                if ((immediateDirection & SearchDirection.Right) == SearchDirection.None)   r = 1.0471975512;
            }
            else
                return false;

            return angle >= l && angle <= r;
        }
Example #13
0
        public static IEnumerable<DirectoryInfo> EnumerateDirectories(string rootDirectory, SearchDirection direction)
        {
            if (rootDirectory == null) throw new ArgumentNullException("rootDirectory");

            var directory = new DirectoryInfo(rootDirectory);
            if (Directory.Exists(rootDirectory))
            {
                if (direction == SearchDirection.Down)
                {
                    yield return directory;
                    foreach (var subDirectory in directory.EnumerateDirectories("*", SearchOption.AllDirectories))
                    {
                        yield return subDirectory;
                    }
                }
                else
                {
                    do
                    {
                        yield return directory;
                        directory = directory.Parent;
                    }
                    while (directory != null);
                }
            }
        }
Example #14
0
        public ushort AssignTarget(ushort vehicleID)
        {
            Vehicle vehicle = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID];
            ushort  target  = 0;

            if (vehicle.m_sourceBuilding != _buildingID)
            {
                return(target);
            }

            if (Singleton <PathManager> .instance.m_pathUnits.m_buffer[vehicle.m_path].m_nextPathUnit == 0)
            {
                byte b = vehicle.m_pathPositionIndex;
                if (b == 255)
                {
                    b = 0;
                }
                if ((b & 1) == 0)
                {
                    b += 1;
                }
                if ((b >> 1) + 1 >= Singleton <PathManager> .instance.m_pathUnits.m_buffer[vehicle.m_path].m_positionCount)
                {
                    return(target);
                }
            }

            ushort current = vehicle.m_targetBuilding;

            if (!Helper.IsBuildingWithDead(current))
            {
                _oldtargets.Remove(vehicleID);
                _master.Remove(current);
                _primary.Remove(current);
                _secondary.Remove(current);

                current = 0;
            }
            else if (_master.ContainsKey(current))
            {
                if (_master[current].IsValid && _master[current].Vehicle != vehicleID)
                {
                    current = 0;
                }
            }

            int vehicleStatus = Dispatcher.GetHearseStatus(ref vehicle);

            if (current != 0 && vehicleStatus == Dispatcher.VEHICLE_STATUS_HEARSE_COLLECT && _lastchangetimes.ContainsKey(vehicleID) && (SimulationManager.instance.m_currentGameTime - _lastchangetimes[vehicleID]).TotalDays < 0.5)
            {
                return(target);
            }

            bool            immediateOnly      = (_primary.Contains(current) || _secondary.Contains(current));
            SearchDirection immediateDirection = GetImmediateSearchDirection(vehicleID);

            if (immediateOnly && immediateDirection == SearchDirection.None)
            {
                target = current;
            }
            else
            {
                target = GetClosestTarget(vehicleID, ref _primary, immediateOnly, immediateDirection);

                if (target == 0)
                {
                    target = GetClosestTarget(vehicleID, ref _secondary, immediateOnly, immediateDirection);
                }
            }

            if (target == 0)
            {
                _oldtargets.Remove(vehicleID);

                if ((vehicle.m_targetBuilding != 0 && WithinPrimaryRange(vehicle.m_targetBuilding)) || _checkups.Count == 0)
                {
                    target = vehicle.m_targetBuilding;
                }
                else
                {
                    target = _checkups[0];
                    _checkups.RemoveAt(0);
                }
            }

            return(target);
        }
Example #15
0
        private bool WordAppearsInConversation(string wordToFind, IConversation conversation, SearchDirection searchDirection)
        {
            foreach (IConversationMessage message in conversation)
            {
                if (string.IsNullOrEmpty(message.MessageContents))
                {
                    continue;
                }
                if (FindWordInString(wordToFind, message.MessageContents, searchDirection) >= 0)
                {
                    return true;
                }
            }

            return false;
        }
Example #16
0
 public static extern IntPtr imaqStraightEdge(IntPtr image, ref ROI roi, SearchDirection searchDirection, ref EdgeOptions2 edgeOptions, ref StraightEdgeOptions straightEdgeOptions);
Example #17
0
		public void Search(Regex pattern, SearchDirection dir)
		{
			_presenter.Search(pattern, dir);
		}
Example #18
0
        public List <DateTime> GetCoversationDateList(
            Contact contract,
            DateTime searchDate,
            SearchDirection direction = SearchDirection.None)
        {
            List <DateTime> list = new List <DateTime>();

            bool insertAt0 = true;

            lock (locker)
            {
                using (var repository = StorageEngine.FromFile(DATABASE_NAME))
                {
                    var table = repository.Scheme.CreateOrOpenXTable <long, DateTime>(
                        new Locator(string.Format("{0}_MsgDate", contract.Id)));
                    repository.Scheme.Commit();

                    var v = table.Where(w => w.Record == searchDate).FirstOrDefault();

                    var first = table.FirstOrDefault();
                    var last  = table.LastOrDefault();

                    //avoid the first/last' forward/backward
                    if (v == null &&
                        (direction == SearchDirection.Forward ||
                         direction == SearchDirection.Backward))
                    {
                        logger.Warn(string.Format("Cannot found record of {0}", searchDate));

                        return(list);
                    }

                    IEnumerable <Row <long, DateTime> > enumerator = null;

                    if (direction == SearchDirection.None ||
                        direction == SearchDirection.Last)
                    {
                        enumerator = table.Backward();
                        insertAt0  = true;
                    }
                    else if (direction == SearchDirection.First)
                    {
                        enumerator = table.Forward();
                        insertAt0  = false;
                    }
                    else if (direction == SearchDirection.Forward)
                    {
                        if (v.Key != last.Key)
                        {
                            enumerator = table.Forward(v.Key);
                            insertAt0  = false;
                        }
                    }
                    else if (direction == SearchDirection.Backward)
                    {
                        if (v.Key != first.Key)
                        {
                            enumerator = table.Backward(v.Key);
                            insertAt0  = true;
                        }
                    }

                    if (enumerator != null)
                    {
                        foreach (var row in enumerator.Take(PageSize))
                        {
                            if (insertAt0)
                            {
                                list.Insert(0, row.Record);
                            }
                            else
                            {
                                list.Add(row.Record);
                            }
                        }
                    }
                }
            }

            return(list);
        }
Example #19
0
        protected static IEnumerable <FloorSelection> Prefilter(IEnumerable <FloorSelection> floors, int?startIndex, SearchDirection direction = SearchDirection.Down)
        {
            Contract.Requires(floors != null);
            Contract.Ensures(Contract.Result <IEnumerable <FloorSelection> >() != null);

            switch (direction)
            {
            case SearchDirection.Up:
                return(floors.Where(a => !startIndex.HasValue || a.Index >= startIndex.Value).OrderBy(a => a.Index));

            case SearchDirection.Down:
                return(floors.Where(a => !startIndex.HasValue || a.Index <= startIndex.Value).OrderByDescending(a => a.Index));

            default:
                throw new ArgumentException("Unknown search direction");
            }
        }
Example #20
0
        public int StrFind(string haystack, string needle, SearchDirection direction = SearchDirection.FromBegin, int startPos = 0, int occurance = 0)
        {
            int len = haystack.Length;

            if (len == 0 || needle.Length == 0)
            {
                return(0);
            }

            bool fromBegin = direction == SearchDirection.FromBegin;

            if (startPos == 0)
            {
                startPos = fromBegin ? 1 : len;
            }

            if (startPos < 1 || startPos > len)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            if (occurance == 0)
            {
                occurance = 1;
            }

            int startIndex = startPos - 1;
            int foundTimes = 0;
            int index      = len + 1;

            if (fromBegin)
            {
                while (foundTimes < occurance && index >= 0)
                {
                    index = haystack.IndexOf(needle, startIndex, StringComparison.Ordinal);
                    if (index >= 0)
                    {
                        startIndex = index + 1;
                        foundTimes++;
                    }
                    if (startIndex >= len)
                    {
                        break;
                    }
                }
            }
            else
            {
                while (foundTimes < occurance && index >= 0)
                {
                    index = haystack.LastIndexOf(needle, startIndex, StringComparison.Ordinal);
                    if (index >= 0)
                    {
                        startIndex = index - 1;
                        foundTimes++;
                    }
                    if (startIndex < 0)
                    {
                        break;
                    }
                }
            }

            if (foundTimes == occurance)
            {
                return(index + 1);
            }
            else
            {
                return(0);
            }
        }
Example #21
0
 /// <summary>
 /// Vráti element, ktorý nasleduje ďalej v strome/sekvencii, prípadne vráti null.
 /// </summary>
 /// <param name="dir"></param>
 /// <param name="tree"></param>
 /// <returns></returns>
 public IElement Move(SearchDirection dir, bool goIntoCurrent)
 {
     return(dir == SearchDirection.LeftToRight ? MoveNext(goIntoCurrent) : MovePrev());
 }
Example #22
0
 public IElement FindNextBlack(SearchDirection dir)
 {
     Move(dir);
     return(Find(dir, SearchVisibility.Visible));
 }
Example #23
0
        private TextRange SearchCurrentConversation(SearchDirection searchDirection, bool wrapSearch)
        {
            if (string.IsNullOrEmpty(Query))
            {
                return null;
            }

            TextPointer searchStartPointer;

            RichTextBox targetTextBox = (RichTextBox)_searchTarget.SearchTargetControl;

            if (_queryChangedSinceLastSearch)
            {
                ClearRichTextBoxSelection(targetTextBox);
            }

            if (searchDirection == SearchDirection.Down)
            {
                searchStartPointer = targetTextBox.Selection.End;
            }
            else
            {
                TextRange startToCaret = new TextRange(targetTextBox.Document.ContentStart, targetTextBox.CaretPosition);
                if (startToCaret.Text.Length == 0)
                {
                    searchStartPointer = targetTextBox.Document.ContentEnd;
                }
                else
                {
                    searchStartPointer = targetTextBox.Selection.Start;
                }
            }

            TextRange foundRange = FindWordFromPosition(searchStartPointer, Query, searchDirection);
            if (foundRange == null && wrapSearch)
            {
                if ((searchDirection == SearchDirection.Down) && (searchStartPointer != targetTextBox.Document.ContentStart))
                {
                    foundRange = FindWordFromPosition(targetTextBox.Document.ContentStart, Query, searchDirection);
                }
                else if ((searchDirection == SearchDirection.Up) && (searchStartPointer != targetTextBox.Document.ContentEnd))
                {
                    foundRange = FindWordFromPosition(targetTextBox.Document.ContentEnd, Query, searchDirection);
                }
            }

            if (foundRange != null)
            {
                targetTextBox.Focus();
                targetTextBox.Selection.Select(foundRange.Start, foundRange.End);

                return foundRange;
            }

            return null;
        }
Example #24
0
 private LogicalDirection SearchDirectionToLogicalDirection(SearchDirection searchDirection)
 {
     if (searchDirection == SearchDirection.Down)
     {
         return LogicalDirection.Forward;
     }
     else
     {
         return LogicalDirection.Backward;
     }
 }
Example #25
0
        private ushort GetClosestTarget(ushort vehicleID, ref HashSet <ushort> targets, bool immediateOnly, SearchDirection immediateDirection)
        {
            Vehicle vehicle = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID];

            Building[] buildings = Singleton <BuildingManager> .instance.m_buildings.m_buffer;

            List <ushort> removals = new List <ushort>();

            ushort target = vehicle.m_targetBuilding;

            if (_master.ContainsKey(target) && _master[target].IsValid && _master[target].Vehicle != vehicleID)
            {
                target = 0;
            }
            int   targetProblematicLevel = 0;
            float targetdistance         = float.PositiveInfinity;
            float distance = float.PositiveInfinity;

            Vector3 velocity = vehicle.GetLastFrameVelocity();
            Vector3 position = vehicle.GetLastFramePosition();

            double bearing = double.PositiveInfinity;
            double facing  = Math.Atan2(velocity.z, velocity.x);

            if (targets.Contains(target))
            {
                if (!Helper.IsBuildingWithDead(target))
                {
                    removals.Add(target);
                    target = 0;
                }
                else
                {
                    if ((buildings[target].m_problems & Notification.Problem.Death) != Notification.Problem.None)
                    {
                        if (Identity.ModConf.PrioritizeTargetWithRedSigns && (buildings[target].m_problems & Notification.Problem.MajorProblem) != Notification.Problem.None)
                        {
                            targetProblematicLevel = 2;
                        }
                        else
                        {
                            targetProblematicLevel = 1;
                        }
                    }

                    Vector3 a = buildings[target].m_position;

                    targetdistance = distance = (a - position).sqrMagnitude;

                    bearing = Math.Atan2(a.z - position.z, a.x - position.x);
                }
            }
            else if (!immediateOnly)
            {
                target = 0;
            }

            foreach (ushort id in targets)
            {
                if (target == id)
                {
                    continue;
                }

                if (!Helper.IsBuildingWithDead(id))
                {
                    removals.Add(id);
                    continue;
                }

                if (_master.ContainsKey(id) && _master[id].IsValid && !_master[id].IsChallengable)
                {
                    continue;
                }

                if (_master.ContainsKey(id) && _master[id].IsValid && _master[id].Vehicle != vehicleID)
                {
                    Vehicle vehicle2 = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[_master[id].Vehicle];
                    if (vehicle2.m_flags.IsFlagSet(Vehicle.Flags.Spawned) && vehicle2.m_path != 0 &&
                        Singleton <PathManager> .instance.m_pathUnits.m_buffer[vehicle2.m_path].m_nextPathUnit == 0)
                    {
                        byte b = vehicle2.m_pathPositionIndex;
                        if (b == 255)
                        {
                            b = 0;
                        }
                        if ((b & 1) == 0)
                        {
                            b += 1;
                        }
                        if ((b >> 1) + 1 >= Singleton <PathManager> .instance.m_pathUnits.m_buffer[vehicle2.m_path].m_positionCount)
                        {
                            continue;
                        }
                    }
                }

                Vector3 p = buildings[id].m_position;
                float   d = (p - position).sqrMagnitude;

                int candidateProblematicLevel = 0;
                if ((buildings[id].m_problems & Notification.Problem.Death) != Notification.Problem.None)
                {
                    if (Identity.ModConf.PrioritizeTargetWithRedSigns && (buildings[id].m_problems & Notification.Problem.MajorProblem) != Notification.Problem.None)
                    {
                        candidateProblematicLevel = 2;
                    }
                    else
                    {
                        candidateProblematicLevel = 1;
                    }
                }

                if (_oldtargets.ContainsKey(vehicleID) && _oldtargets[vehicleID].Count > 5 && targetProblematicLevel >= candidateProblematicLevel)
                {
                    continue;
                }

                if (_master.ContainsKey(id) && _master[id].IsValid && _master[id].IsChallengable)
                {
                    if (targetProblematicLevel > candidateProblematicLevel)
                    {
                        continue;
                    }

                    if (d > targetdistance * 0.9)
                    {
                        continue;
                    }

                    if (d > distance)
                    {
                        continue;
                    }

                    if (d > _master[id].Distance * 0.9)
                    {
                        continue;
                    }

                    double angle = Helper.GetAngleDifference(facing, Math.Atan2(p.z - position.z, p.x - position.x));

                    int immediateLevel = GetImmediateLevel(d, angle, immediateDirection);

                    if (immediateLevel == 0)
                    {
                        continue;
                    }

                    if (_oldtargets.ContainsKey(vehicleID) && _oldtargets[vehicleID].Contains(id))
                    {
                        continue;
                    }
                }
                else
                {
                    double angle          = Helper.GetAngleDifference(facing, Math.Atan2(p.z - position.z, p.x - position.x));
                    int    immediateLevel = GetImmediateLevel(d, angle, immediateDirection);

                    if (immediateOnly && immediateLevel == 0)
                    {
                        continue;
                    }

                    if (_oldtargets.ContainsKey(vehicleID) && _oldtargets[vehicleID].Contains(id))
                    {
                        continue;
                    }

                    if (targetProblematicLevel > candidateProblematicLevel)
                    {
                        continue;
                    }

                    if (targetProblematicLevel < candidateProblematicLevel)
                    {
                        // No additonal conditions at the moment. Problematic buildings always have priority over nonproblematic buildings
                    }
                    else
                    {
                        if (d > targetdistance * 0.9)
                        {
                            continue;
                        }

                        if (d > distance)
                        {
                            continue;
                        }

                        if (immediateLevel > 0)
                        {
                            // If it's that close, no need to further qualify its priority
                        }
                        else if (IsAlongTheWay(d, angle))
                        {
                            // If it's in the general direction the vehicle is facing, it's good enough
                        }
                        else if (!double.IsPositiveInfinity(bearing))
                        {
                            if (IsAlongTheWay(d, Helper.GetAngleDifference(bearing, Math.Atan2(p.z - position.z, p.x - position.x))))
                            {
                                // If it's in the general direction along the vehicle's target path, we will have to settle for it at this point
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            // If it's not closeby and not in the direction the vehicle is facing, but our vehicle also has no bearing, we will take whatever is out there
                        }
                    }
                }

                target = id;
                targetProblematicLevel = candidateProblematicLevel;
                distance = d;
            }

            foreach (ushort id in removals)
            {
                _master.Remove(id);
                targets.Remove(id);
            }

            return(target);
        }
        private int FindWordInStringHelper(string toFind, string target, SearchDirection direction, bool isCaseSensitive)
        {
            MockConversationSearchTarget searchTarget = new MockConversationSearchTarget();
            searchTarget.SearchTargetControl = CreateRichTextBoxWithContent(target);

            FindDialogModel_Accessor model = new FindDialogModel_Accessor(searchTarget);

            model.CaseSensitive = isCaseSensitive;

            return model.FindWordInString(toFind, target, direction);
        }
		private void DoSearch(SearchDirection dir)
		{
			Regex pattern = null;

			try
			{
				pattern = new Regex(
						chkUseRegEx.IsChecked.Value ? txtSearchTerm.Text : Regex.Escape(txtSearchTerm.Text),
						chkMatchCase.IsChecked.Value ? RegexOptions.None : RegexOptions.IgnoreCase);
			}
			catch (ArgumentException ex)
			{
				MessageBox.Show("The regular expression was not valid: " + Environment.NewLine + ex.Message,
					"Invalid pattern", MessageBoxButton.OK, MessageBoxImage.Error);
			}

			boxOutput.Search(pattern, dir);
		}
Example #28
0
 public FindNumberedInstanceOfByteLocationInFileAndUpdateOnProgress(long startingByte, byte byteToFind, SearchDirection searchDirection, string filePath, long instanceNumberToFind, bool overrideUI, IActorRef updateUIActor, Action <double> updateAction)
 {
     StartingByteNumber   = startingByte;
     ByteToFind           = byteToFind;
     SearchDirection      = searchDirection;
     FilePath             = filePath;
     InstanceNumberToFind = instanceNumberToFind;
     OverrideUI           = overrideUI;
     UpdateUIActor        = updateUIActor;
     UpdateAction         = updateAction;
 }
Example #29
0
        private SearchDirection GetImmediateSearchDirection(ushort vehicleID)
        {
            Vehicle vehicle = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID];

            PathManager pm = Singleton <PathManager> .instance;

            PathUnit pu = pm.m_pathUnits.m_buffer[vehicle.m_path];

            byte pi = vehicle.m_pathPositionIndex;

            if (pi == 255)
            {
                pi = 0;
            }

            PathUnit.Position position = pu.GetPosition(pi >> 1);

            NetManager nm = Singleton <NetManager> .instance;

            NetSegment segment = nm.m_segments.m_buffer[position.m_segment];

            int laneCount = 0;

            int   leftLane     = -1;
            float leftPosition = float.PositiveInfinity;

            int   rightLane     = -1;
            float rightPosition = float.NegativeInfinity;

            for (int i = 0; i < segment.Info.m_lanes.Length; i++)
            {
                NetInfo.Lane l = segment.Info.m_lanes[i];

                if (l.m_laneType != NetInfo.LaneType.Vehicle || l.m_vehicleType != VehicleInfo.VehicleType.Car)
                {
                    continue;
                }

                laneCount++;

                if (l.m_position < leftPosition)
                {
                    leftLane     = i;
                    leftPosition = l.m_position;
                }

                if (l.m_position > rightPosition)
                {
                    rightLane     = i;
                    rightPosition = l.m_position;
                }
            }

            SearchDirection dir = SearchDirection.None;

            if (laneCount == 0)
            {
            }
            else if (position.m_lane != leftLane && position.m_lane != rightLane)
            {
                dir = SearchDirection.Ahead;
            }
            else if (leftLane == rightLane)
            {
                dir = SearchDirection.Left | SearchDirection.Right | SearchDirection.Ahead;
            }
            else if (laneCount == 2 && segment.Info.m_lanes[leftLane].m_direction != segment.Info.m_lanes[rightLane].m_direction)
            {
                dir = SearchDirection.Left | SearchDirection.Right | SearchDirection.Ahead;
            }
            else
            {
                if (position.m_lane == leftLane)
                {
                    dir = SearchDirection.Left | SearchDirection.Ahead;
                }
                else
                {
                    dir = SearchDirection.Right | SearchDirection.Ahead;
                }
            }

            return(dir);
        }
        private ushort GetClosestTarget(ushort hearseID, ref HashSet<ushort> targets, bool immediateOnly, SearchDirection immediateDirection)
        {
            Vehicle hearse = Singleton<VehicleManager>.instance.m_vehicles.m_buffer[hearseID];

            Building[] buildings = Singleton<BuildingManager>.instance.m_buildings.m_buffer;

            List<ushort> removals = new List<ushort>();

            ushort target = hearse.m_targetBuilding;
            if (_master.ContainsKey(target) && _master[target].IsValid && _master[target].Hearse != hearseID)
                target = 0;

            bool targetProblematic = false;
            float distance = float.PositiveInfinity;

            Vector3 velocity = hearse.GetLastFrameVelocity();
            Vector3 position = hearse.GetLastFramePosition();

            double bearing = double.PositiveInfinity;
            double facing = Math.Atan2(velocity.z, velocity.x);

            if (targets.Contains(target))
            {
                if (!SkylinesOverwatch.Data.Instance.IsBuildingWithDead(target))
                {
                    removals.Add(target);
                    target = 0;
                }
                else
                {
                    targetProblematic = (buildings[target].m_problems & Notification.Problem.Death) != Notification.Problem.None;

                    Vector3 a = buildings[target].m_position;

                    distance = (a - position).sqrMagnitude;

                    bearing = Math.Atan2(a.z - position.z, a.x - position.x);
                }
            }
            else if (!immediateOnly)
                target = 0;

            foreach (ushort id in targets)
            {
                if (target == id)
                    continue;

                if (!SkylinesOverwatch.Data.Instance.IsBuildingWithDead(id))
                {
                    removals.Add(id);
                    continue;
                }

                if (_master.ContainsKey(id) && _master[id].IsValid && !_master[id].IsChallengable)
                    continue;

                Vector3 p = buildings[id].m_position;
                float d = (p - position).sqrMagnitude;

                bool candidateProblematic = (buildings[id].m_problems & Notification.Problem.Death) != Notification.Problem.None;

                double angle = Helper.GetAngleDifference(facing, Math.Atan2(p.z - position.z, p.x - position.x));

                bool isImmediate = IsImmediate(d, angle, immediateDirection);

                #region debug

                string bname = Singleton<BuildingManager>.instance.GetBuildingName(id, new InstanceID { Building = id });
                string vname = Singleton<VehicleManager>.instance.GetVehicleName(hearseID);

                if (bname.Contains("##") && vname.Contains("##"))
                {
                    Helper.Instance.NotifyPlayer(String.Format("{0} :: {1} :: {2} :: {3}", d, angle, immediateDirection, isImmediate));
                }

                #endregion

                if (_master.ContainsKey(id) && _master[id].IsValid && _master[id].IsChallengable)
                {
                    if (d > distance)
                        continue;

                    if (d > _master[id].Distance)
                        continue;

                    if (!isImmediate)
                        continue;
                }
                else
                {
                    if (immediateOnly && !isImmediate)
                        continue;

                    if (targetProblematic && !candidateProblematic)
                        continue;

                    if (!targetProblematic && candidateProblematic)
                    {
                        // No additonal conditions at the moment. Problematic buildings always have priority over nonproblematic buildings
                    }
                    else
                    {
                        if (d > distance)
                            continue;

                        if (isImmediate)
                        {
                            // If it's that close, no need to further qualify its priority
                        }
                        else if (IsAlongTheWay(d, angle))
                        {
                            // If it's in the general direction the vehicle is facing, it's good enough
                        }
                        else if (!double.IsPositiveInfinity(bearing))
                        {
                            angle = Helper.GetAngleDifference(bearing, Math.Atan2(p.z - position.z, p.x - position.x));

                            if (IsAlongTheWay(d, angle))
                            {
                                // If it's in the general direction along the vehicle's target path, we will have to settle for it at this point
                            }
                            else
                                continue;
                        }
                        else
                        {
                            // If it's not closeby and not in the direction the vehicle is facing, but our vehicle also has no bearing, we will take whatever is out there
                        }
                    }
                }

                target = id;
                targetProblematic = candidateProblematic;
                distance = d;
            }

            foreach (ushort id in removals)
            {
                _master.Remove(id);
                targets.Remove(id);
            }

            return target;
        }
Example #31
0
 public FindNumberedInstanceOfByteLocationInFile(long startingByte, byte byteToFind, SearchDirection searchDirection, string filePath, long instanceNumberToFind, bool overrideUI)
 {
     StartingByteNumber   = startingByte;
     ByteToFind           = byteToFind;
     SearchDirection      = searchDirection;
     FilePath             = filePath;
     InstanceNumberToFind = instanceNumberToFind;
     OverrideUI           = overrideUI;
 }
Example #32
0
 public static extern IntPtr imaqStraightEdge2(IntPtr image, ref ROI roi, SearchDirection searchDirection, ref EdgeOptions2 edgeOptions, ref StraightEdgeOptions straightEdgeOptions, uint optimizedMode);
Example #33
0
 /// <summary>
 /// Vráti element, ktorý nasleduje ďalej v strome/sekvencii, prípadne vráti null.
 /// </summary>
 /// <param name="dir"></param>
 /// <param name="tree"></param>
 /// <returns></returns>
 public IElement Move(SearchDirection dir)
 {
     return(Move(dir, true));
 }
Example #34
0
//--------------------------------------------------------------------------------------------------
    public bool SearchConcentricCircles( 
        Map                 map, 
        int                 start, 
        ClockDirection      clockDirection,
        SearchDirection     searchDirection,
        Tour                tour 
        )
    {
        int                 incr = ( searchDirection == SearchDirection.Outwards ? 1 : -1 );

        for( int i=start;;i+=incr)
        {
            if( i < 0 || i > m_Radius ) return false;

            SearchSet           ss = m_SearchSets[i];

            SortedList<double,CircleEntry> entries = ss.Entries;

            if( entries == null ) continue;

            IList<CircleEntry> values;

            if( clockDirection == ClockDirection.Clockwise )
            {
                List<CircleEntry> list = new List<CircleEntry>( entries.Values );
                list.Reverse();
                values = list;
            }
            else 
                values = entries.Values;

            foreach( CircleEntry entry in values )
            {
                if( tour( map, entry.X, entry.Y ) )
                    return true;
            }

            return false;
        }
    }
Example #35
0
        private void FindInCurrentDisplay(SearchDirection searchDirection)
        {
            if (FindModel == null)
            {
                return;
            }

            ViewToModel();

            if (string.IsNullOrEmpty(FindModel.Query))
            {
                return;
            }

            FindModel.SearchDisplayedConversation(searchDirection);

            findQueryTextBox.Focus();

            if (!FindModel.LastQuerySuccessful)
            {
                ShowFailedQueryNotice();
            }
            else
            {
                ClearFailedQueryNotice();
            }
        }
Example #36
0
        /// <summary>
        /// Get list of records bounded by the specified message number, specific count of messages, and search direction.
        /// </summary>
        /// <param name="MessageNumber">Specified starting Message Number</param>
        /// <param name="Count">Count of records to return</param>
        /// <param name="Direction">The direction to search, forwards or backwards</param>
        /// <returns>List of Log Records</returns>
        public List<LogRecord> GetRecordsByMessageNumberAndCount(ulong MessageNumber, int Count, SearchDirection Direction = SearchDirection.Forward)
        {
            log.DebugFormat("MessageNumber - {0}", MessageNumber);
            log.DebugFormat("Count - {0}", Count);
            log.DebugFormat("Direction - {0}", Direction.ToString());

            List<LogRecord> returnValue = new List<LogRecord>();

                // Get the first recordin the list
                LogRecord localRecord = this.GetRecordByMessageNumber(MessageNumber);

                if (localRecord.ReturnCode.Status)
                {
                    returnValue.Add(localRecord);
                }

                // Now start looping through until we have exceeded our target count or the last record we read returned a non true status, indicating a bad read or more typically no more records to read.
                while ((returnValue.Count < Count) && localRecord.ReturnCode.Status)
                {
                    if (Direction == SearchDirection.Back)
                    {
                        localRecord = GetPrevRecord();
                    }
                    else
                    {
                        localRecord = GetNextRecord();
                    }

                    if(localRecord.ReturnCode.Status)
                    {
                        returnValue.Add(localRecord);
                    }
                    else
                    {
                        break;
                    }
                }

                return returnValue;
        }
Example #37
0
        public void SearchDisplayedConversation(SearchDirection searchDirection)
        {
            LastQuerySuccessful = (SearchCurrentConversation(searchDirection, true) != null);

            _queryChangedSinceLastSearch = false;
        }
Example #38
0
        private TextRange FindWordFromPosition(TextPointer position, string word, SearchDirection searchDirection)
        {
            string wordToFind;

            if (!CaseSensitive)
            {
                wordToFind = word.ToLower();
            }
            else
            {
                wordToFind = word;
            }

            LogicalDirection logicalDirection = SearchDirectionToLogicalDirection(searchDirection);

            while (position != null)
            {
                if (position.Parent is ConversationContentRun)
                {
                    string textRun = position.GetTextInRun(logicalDirection);

                    int indexInRun = FindWordInString(wordToFind, textRun, searchDirection);

                    if (indexInRun >= 0)
                    {
                        int startOffset;

                        if (searchDirection == SearchDirection.Down)
                        {
                            startOffset = indexInRun;
                        }
                        else
                        {
                            startOffset = -1 * (textRun.Length - indexInRun);
                        }

                        TextPointer start = position.GetPositionAtOffset(startOffset, logicalDirection);
                        TextPointer end = start.GetPositionAtOffset(wordToFind.Length, logicalDirection);
                        return new TextRange(start, end);
                    }
                }

                position = position.GetNextContextPosition(logicalDirection);
            }

            return null;
        }
Example #39
0
        private int FindWordInString(string wordToFind, string toSearch, SearchDirection searchDirection)
        {
            if (!CaseSensitive)
            {
                toSearch = toSearch.ToLower();
            }

            int wordIndex;

            if (searchDirection == SearchDirection.Down)
            {
                wordIndex = toSearch.IndexOf(wordToFind);
            }
            else
            {
                wordIndex = toSearch.LastIndexOf(wordToFind);
            }

            return wordIndex;
        }
Example #40
0
//------------------------------------------------------------------------------
//  SearchSpiral    --  search a square mosaic spiral, going in or out (allows
//                     a random placement within the first search ring)
//------------------------------------------------------------------------------
    public static bool Spiral( 
        Map                 map, 
        int                 start,
        SearchDirection     direction,
        bool                randomStart,
        Tour                tour 
        )
    {
        return m_SpiralSearch.SearchSpiral( map, start, direction, randomStart, tour );
    }
Example #41
0
 public abstract List <DateTime> GetConversationDateList(
     Contact contract,
     DateTime?searchDate,
     SearchDirection direction);