예제 #1
0
        protected override void ClearUnUsedSegments(int startIndex)
        {
            // Clearing the scattersegments.
            var scatterSegments = new List <ChartSegment>();

            foreach (var segment in Segments.Where(item => item is ScatterSegment))
            {
                scatterSegments.Add(segment);
            }

            foreach (var segment in scatterSegments)
            {
                Segments.Remove(segment);
            }

            if (this.Segments.Count > startIndex)
            {
                int count = this.Segments.Count;

                for (int i = startIndex; i < count; i++)
                {
                    this.Segments.RemoveAt(startIndex);
                }
            }
        }
예제 #2
0
        private void DeleteSegment()
        {
            SelectedSegment.DeleteCommand.Execute(null);

            // Remove from the Segments collection
            Segments.Remove(SelectedSegment);
        }
예제 #3
0
        public void Remove_CorrectRemoveOfSegments_ReturnsNothing()
        {
            var segments = new Segments();

            var segmentTest1 = new VolarisSegment
            {
                ID = "120",
                DepartureStation = "MEX",
                ArrivalStation   = "CUN",
                DepartureTime    = DateTime.Now,
                ArrivalTime      = DateTime.Now.AddHours(3),
                Type             = SegmentType.Connection
            };

            var segmentTest2 = new VolarisSegment
            {
                ID = "123",
                DepartureStation = "MEX",
                ArrivalStation   = "MTY",
                DepartureTime    = DateTime.Now,
                ArrivalTime      = DateTime.Now.AddHours(2),
                Type             = SegmentType.Connection
            };

            segments.Add(segmentTest1);
            segments.Add(segmentTest2);

            segments.Remove(segmentTest1);
            Assert.IsTrue(segments.GetAll().Count == 1, "No se removieron correctamente los segmentos");
        }
예제 #4
0
        /// <summary>
        /// Removes the unused segments
        /// </summary>
        private void ClearUnUsedStepLineSegment(int startIndex)
        {
            var emptySegments = new List <ChartSegment>();

            foreach (var segment in Segments.Where(item => item is EmptyPointSegment))
            {
                emptySegments.Add(segment);
            }

            foreach (var segment in emptySegments)
            {
                Segments.Remove(segment);
            }

            if (this.Segments.Count >= startIndex && this.Segments.Count != 0)
            {
                int count = this.Segments.Count;

                for (int i = startIndex; i <= count; i++)
                {
                    if (i == count)
                    {
                        this.Segments.RemoveAt(startIndex - 1);
                    }
                    else
                    {
                        this.Segments.RemoveAt(startIndex);
                    }
                }
            }
        }
예제 #5
0
 public override void UpdateOffsets(BuildingContext context)
 {
     if (NetResourceDirectoryBuilder.Segments.Count == 0)
     {
         Segments.Remove(NetResourceDirectoryBuilder);
     }
     base.UpdateOffsets(context);
 }
예제 #6
0
        /// <summary>
        /// Instructs the manager to dispose no longer needed areas.
        /// </summary>
        protected override void CleanAreas()
        {
            List <Tuple <int, int> > columns = GetEntityColumns(_Player);

            // flag nonlisted areas for removal
            List <ClientArea> areas = new List <ClientArea>(Areas.Values);

            foreach (ClientArea area in areas)
            {
                if (!area.IsInitialized ||
                    columns.Contains(new Tuple <int, int>(area.X, area.Z)))
                {
                    // this area has not been initialize yet or is an active area
                    continue;
                }

                if (area.Key < 0)
                {
                    // now this is a problem...
                    DiagnosticsManager.WriteMessage("WARNING: attempt to remove an area without a key!");
                    continue;
                }

                area.IsFlaggedForRemoval = true;
                lock (CollectionsLock)
                {
                    // lock the collections to prevent conflicts
                    int segmentCount = area.GetSegmentCount();
                    int boxesCount   = 0;

                    // save changed
                    if (area.IsChanged)
                    {
                        SaveArea(area);
                    }

                    for (int i = 0; i < segmentCount; i++)
                    {
                        ClientSegment segment = area.GetSegment <ClientSegment>(ref i);
                        boxesCount += segment.GetBoxCount();
                        foreach (ClientBox box in segment.GetBoxesSynchronized())
                        {
                            _PooledBoxes.Enqueue(box);
                        }
                        segment.Unload();
                        Segments.Remove(segment.Key);

                        _PooledSegments.Enqueue(segment);
                    }
                    area.Unload();
                    Areas.Remove(area.Key);

                    DiagnosticsManager.BoxesLoaded    -= boxesCount;
                    DiagnosticsManager.SegmentsLoaded -= segmentCount;
                    DiagnosticsManager.AreasLoaded--;
                }
            }
        }
예제 #7
0
 private void Replace(IEnumerable <DocumentSegment> affectedSegments, ref int offset, ref int replacementLength,
                      ref string text)
 {
     foreach (DocumentSegment segment in affectedSegments)
     {
         segment.OnReplace(ref offset, ref replacementLength, ref text);
         if (segment.Length == 0)
         {
             Segments.Remove(segment);
         }
     }
     offset            = Math.Min(textDocument.TextLength, offset);
     replacementLength = Math.Min(textDocument.TextLength - offset, replacementLength);
     textDocument.Replace(offset, replacementLength, text);
 }
예제 #8
0
        /// <summary>
        ///     Merges duplicate segments of a surface
        /// </summary>
        private void MergeDuplicates()
        {
            int i = 0;

            while (i < Segments.Count - 1)
            {
                if (Segments[i].Graph.Equals(Segments[i + 1].Graph))
                {
                    Segments[i].End = Segments[i + 1].End;
                    Segments.Remove(Segments[i + 1]);
                }
                else
                {
                    i++;
                }
            }
        }
예제 #9
0
        private void ApplyChanges(DocumentChangeEventArgs lastChange, ReadOnlyCollection <DocumentSegment> changedSegments)
        {
            if (textDocument.TextLength == 0)
            {
                Segments.Clear();
                return;
            }
            if (lastChange == null)
            {
                return;
            }
            if (textDocument.IsInUpdate)
            {
                return;
            }
            List <DocumentSegment> affectedSegments = changedSegments.Where(v => v is PlaceholderSegment).ToList();

            foreach (var segment in affectedSegments.Where(v => v.Length == 0).ToList())
            {
                Segments.Remove(segment);
                affectedSegments.Remove(segment);
            }

            if (!affectedSegments.Any())
            {
                return;
            }
            if (!textDocument.UndoStack.CanUndo)
            {
                return;
            }
            try
            {
                textDocument.UndoStack.Undo();
            }
            catch (Exception)
            {
                return;
            }

            int    offset = lastChange.Offset;
            int    legnth = lastChange.RemovalLength;
            string text   = lastChange.InsertedText.Text;

            Replace(affectedSegments, ref offset, ref legnth, ref text);
        }
예제 #10
0
        /// <summary>
        /// Completes the polygon by connecting the last point to the first point.
        /// </summary>
        private void ClosePolygon()
        {
            // Remember that we closed the polygon
            PolygonClosed = true;

            // If the start side is being colored a special color then...
            if (ColorStartSide)
            {
                // Remove all the segments except the last one
                while (Segments.Count > 1)
                {
                    Segments.Remove(Segments[Segments.Count - 1]);
                }

                // Wipe fill type is only valid for polygons with four or three sides
                if (PointCollection.Count == 4 ||
                    PointCollection.Count == 3)
                {
                    // Color the start side green
                    Segments[0].Color = Colors.Lime;
                }
                // Otherwise if the fill type is set to wipe then...
                else if (Polygon.FillType == PolygonFillType.Wipe)
                {
                    // Set the fill type to solid since the polygon does meet the requirements of a wipe
                    Polygon.FillType = PolygonFillType.Solid;

                    // Hide the green line
                    SegmentsVisible = false;
                }
            }
            // Otherwise hide all segments
            else
            {
                SegmentsVisible = false;
            }

            // Fire the property changed event so the converters run
            NotifyPointCollectionChanged();

            // Make the WPF polygon visible
            Visibility = true;
        }
예제 #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;
            }
        }
예제 #12
0
      /// <summary>
      /// Instructs the manager to dispose no longer needed areas.
      /// </summary>
      protected override void CleanAreas()
      {
         if (Configuration.World.LoadWholeMap)
         {
            // don't clean when whole map is loaded
            return;
         }

         List<int> areas = new List<int>();
         lock (CollectionsLock)
         {
            areas.AddRange(Areas.Keys);
         }

         List<int> clientAreas = new List<int>();
         lock (_ClientLock)
         {
            clientAreas.AddRange(_ClientAreas.SelectMany(ca => ca.Value));
         }

         foreach (int key in clientAreas)
         {
            if (areas.Contains(key))
            {
               areas.Remove(key);
            }
         }

         // only no longer areas are left now
         foreach (int toRemove in areas)
         {
            ServerArea area = Areas[toRemove];
            if (!area.IsInitialized || area.Key < 0)
            {
               // skip not loaded area
               continue;
            }

            // save changed
            if (area.IsChanged)
            {
               SaveArea(area);
            }

            // pool and unload
            lock (CollectionsLock)
            {
               int segmentCount = area.GetSegmentCount();
               for (int i = 0; i < segmentCount; i++)
               {
                  ServerSegment segment = area.GetSegment<ServerSegment>(ref i);
                  foreach (ServerBox box in segment.GetBoxesSynchronized())
                  {
                     _PooledBoxes.Enqueue(box);
                  }
                  segment.Unload();
                  Segments.Remove(segment.Key);

                  _PooledSegments.Enqueue(segment);
               }
               area.Unload();
               Areas.Remove(area.Key);
            }
         }
      }
예제 #13
0
        private void SplitSegmentsThatOverlap()
        {
            // O(N^2)
            Queue <Segment> open = new Queue <Segment>(Segments);

            Segments.Clear();
            while (open.Any())
            {
                if (Segments.Count > 300)
                {
                    Debug.Log("Too many segment splits!");
                    return;
                }
                Segment segment   = open.Dequeue();
                bool    splitFree = true;
                foreach (Segment testing in Segments)
                {
                    Segment.IntersectionResult intersection = Segment.IsInFrontOf(segment, testing, Center);

                    if (intersection == Segment.IntersectionResult.Intersects)
                    {
                        // Do they *really* overlap, there seems to be some issues with the IsInFrontOf method.
                        if (ShadowMathUtils.Approximately(testing.Start.Point, segment.Start.Point) ||
                            ShadowMathUtils.Approximately(testing.End.Point, segment.End.Point) ||
                            ShadowMathUtils.Approximately(testing.End.Point, segment.Start.Point) ||
                            ShadowMathUtils.Approximately(testing.Start.Point, segment.End.Point))
                        {
                            //intersection = Segment.IsInFrontOf(segment, testing, Center);
                            //Debug.Log("They're the same point!"+intersection);
                            continue;
                        }

                        // segment && testing overlap, we must split one of them but both must go back on the queue
                        Segments.Remove(testing);
                        open.Enqueue(testing);

                        Vector2 position =
                            ShadowMathUtils.LineIntersection(
                                segment.Start.Point,
                                segment.End.Point,
                                testing.Start.Point,
                                testing.End.Point);

                        if (_drawGizmos)
                        {
                            Gizmos.color = Color.red;
                            Gizmos.DrawSphere(position, 0.2f);
                        }

                        // Split segments and add both parts back to the queue
                        Split(segment, position, open);
                        splitFree = false;
                        break;
                    }
                }
                if (splitFree)
                {
                    Segments.Add(segment);
                }
            }
        }