private GraphPoint IsMousePosWithinSegment(Point mousePos, GraphPoint p1, GraphPoint p2) { GraphPoint result = null; if (mousePos.X >= p1._coordinates.X && mousePos.X <= p2._coordinates.X) { double aCoefCoords = (p1._coordinates.Y - p2._coordinates.Y) / (p1._coordinates.X - p2._coordinates.X); double bCoefCoords = p2._coordinates.Y - (aCoefCoords * p2._coordinates.X); double expectedY = aCoefCoords * mousePos.X + bCoefCoords; double fError = Math.Abs(expectedY - mousePos.Y); const double cCurveSelectionTolerance = 10.0f; if (fError <= cCurveSelectionTolerance) { double aCoefValue = (p2._value - p1._value) / (p2._coordinates.X - p1._coordinates.X); double value = aCoefValue * (mousePos.X - p1._coordinates.X) + p1._value; result = new GraphPoint(new Point(mousePos.X, expectedY), (float)value); //Console.WriteLine("Selected Curve ({0} - Error({1:00} pixels), time range: {2}s - {3}s, value: {4}{5}", _description, fError,p1._coordinates.X / FASTBuildMonitorControl.pix_per_second, p2._coordinates.X / FASTBuildMonitorControl.pix_per_second, value, _unitTag); } } return(result); }
GraphPoint[] CreatePoints() { const int nPoints = 10; Console.WriteLine("Points on Graph\n***************"); var points = new GraphPoint[nPoints - 1]; for (var i = 0; i < nPoints / 2; i++) { var point = new GraphPoint(i, 2.3 * i + 20.0); points[i] = point; Console.WriteLine(point.ToString()); } for (var i = 0; i < nPoints / 2 - 1; i++) { var point = new GraphPoint(i, 3.0 * i + 1.0); points[nPoints / 2 + i] = point; Console.WriteLine(point.ToString()); } Console.WriteLine("****************\n"); return(points); }
// Graph Internal Utility #region void AddPoint(Vector3 pos) { GraphPoint newPoint = new GraphPoint(); newPoint.position = pos; graphPoints.Add(newPoint); }
public GraphPointInfo(GraphPoint point) { Point = point; IsUnvisited = true; EdgesWeightSum = int.MaxValue; PreviousPoint = null; }
List <GraphPoint> ReconstructPath(SquareGrid grid, AStarSearch astar) { //in reverse way -> end = start GraphPoint end = astar.cameFrom.Where(x => x.Key.wType == GraphPoint.WType.start).First().Key; var tr = astar.cameFrom.Where(x => x.Key.wType == GraphPoint.WType.end); if (tr.Any()) { GraphPoint cur = tr.First().Key; List <GraphPoint> path = new List <GraphPoint>(); while (!cur.Equals(end)) { GraphPoint ptr = cur; if (!astar.cameFrom.TryGetValue(cur, out ptr)) { ptr = cur; } path.Add(cur); cur = ptr; } return(path); } else { DialogResult result = System.Windows.Forms.MessageBox.Show(Application.OpenForms[0], "Лабіринт не має розв'язку", "Помилка", MessageBoxButtons.YesNo); } return(null); }
IEnumerator AddCurrentValue() { while (true) { System.Random random = new System.Random(); string currentReading = readingValueGameObject.GetComponent <TextMeshPro>().text; if (!currentReading.Equals("NO DATA")) { GraphPoint graphpoint = new GraphPoint(); float YValue = plotValue = (float)System.Convert.ToDouble(currentReading); //Random.Range(minYscaleValue, maxYscaleValue); graphpoint.GraphValue = YValue; graphpoint.ValueRecordedTime = getCurrentTime(); if (GraphVerticalLinePrefab != null) { graphpoint.MeshLineObject = Instantiate(GraphVerticalLinePrefab, gameObject.transform) as GameObject; graphpoint.MeshLineObject.transform.position = transform.position; graphpoint.MeshLineObject.transform.localScale = Vector3.one; } graphPoints.Add(graphpoint); graphPoints.Sort(new sortGraphPointByTime()); } yield return(new WaitForSeconds(0.3f)); } }
public bool PointInConvex(Vector2 p) { if (points.Length < 3) { return(false); } float sign = 0; bool first = true; for (int i = 0; i < points.Length; i++) { GraphPoint <NaviPoint> cur = points[i]; GraphPoint <NaviPoint> next = points[(i + 1) % points.Length]; float cross = MathTools.Vector2Cross(p - cur.value.Pos, next.value.Pos - p); if (first) { sign = cross; first = false; } else { if (Math.Sign(sign) != Math.Sign(cross)) { return(false); } } } return(true); }
Line FindBestLine(GraphPoint[] points) { Line bestLine = null; var bestCount = 0; var linesBySlope = new Dictionary<Double, List<Line>>(); for (var i = 0; i < points.Length; i++) { for (var j = i + 1; j < points.Length; j++) { var line = new Line(points[i], points[j]); InsertLine(linesBySlope, line); /* count lines that are equivalent to current line */ var count = CountEquivalentLines(linesBySlope, line); /* if better than current line, replace it */ if (count > bestCount) { bestLine = line; bestCount = count; } } } return bestLine; }
private void GenerateIndex(int activeFolderIndex) { if (activeFolderIndex > 0) { updateIndexSummary(activeFolderIndex); } if (activeFolderIndex == NLevels) { return; } string path = $"{m_rootFolder}{Path.DirectorySeparatorChar}{string.Join(Path.DirectorySeparatorChar, m_activeFolder.Take(activeFolderIndex + 1))}"; if (m_activeSummary[activeFolderIndex].N > 0) { Directory.CreateDirectory(path); //write to file using (BinaryWriter writer = new BinaryWriter(File.OpenWrite($"{path}{Path.DirectorySeparatorChar}summary.node"))) { writer.Write(m_activeSummary[activeFolderIndex].ToByte()); writer.Flush(); writer.Close(); } } // reset lower level m_activeSummary[activeFolderIndex] = new GraphPoint(); }
public AstarSolver(int[][] cells, IEnumerable <IEnumerable <int> > currentMazeMap) { /// solving plot grid var grid = new SquareGrid(cells.First().Count(), cells.Count()); // converting to flat list currentMazeMapFlat = currentMazeMap.Select(l => l.ToList()).ToList(); // toArray for indexing var currentMazeMapArray = currentMazeMap.Select(x => x.ToArray()).ToArray(); GraphPoint start = new GraphPoint(0, 0), end = new GraphPoint(0, 0); // default values // adding map to grid for (int i = 0; i < cells.First().Count(); i++) { for (int j = 0; j < cells.Count(); j++) { if ((CellControl.WallType)currentMazeMapFlat[j][i] == CellControl.WallType.Solid) { grid.walls.Add(new GraphPoint(i, j)); } if (currentMazeMapArray[j][i] == (int)CellControl.WallType.Start) { start = new GraphPoint(i, j); } if (currentMazeMapArray[j][i] == (int)CellControl.WallType.End) { end = new GraphPoint(i, j); } } } // initializing search var astar = new AStarSearch(grid, start, end); // reconstructing path from "memory array" var path = ReconstructPath(grid, astar); if (path == null) { return; //no solution } //Performing cells visual updating for (int i = 0; i < cells.First().Count(); i++) { for (int j = 0; j < cells.Count(); j++) { if (currentMazeMapFlat[j][i] == (int)(CellControl.WallType.CorrectPath)) { currentMazeMapFlat[j][i] = (int)(CellControl.WallType.None); } var a = path.Where(x => x.x == i && x.y == j); if (a.Any() && currentMazeMapFlat[j][i] != (int)(CellControl.WallType.End))// end overdraving fix { currentMazeMapFlat[j][i] = (int)(CellControl.WallType.CorrectPath); } } } }
// Graph Internal Utility #region void AddPoint(Vector2 pos, Vector2Int boardPos) { GraphPoint newPoint = new GraphPoint(); newPoint.position = pos; newPoint.boardPos = boardPos; graphPoints.Add(newPoint); }
public T CenterNode <T>(T node) where T : INode { var center = new GraphPoint(ViewCenter.X - (node.Width / 2), ViewCenter.Y - (node.Height / 2)); node.Location = center; return(node); }
public NodeAStar(GraphPoint <NaviPoint> point, NodeAStar father) { this.point = point; this.father = father; this.G = 0; this.H = 0; this.F = 0; }
private string GetCostDescription(GraphPoint itemBegin, GraphPoint itemEnd, int cost) { string content = ""; content += itemBegin.Name + " - "; content += itemEnd.Name + " arasi maliyet : "; content += cost; return(content); }
public Node(GraphPoint point, float g, float h) { this.point = point; this.g = g; this.h = h; this.d = g + h; path = new List <GraphPoint>(); path.Add(point); }
public override void Refresh() { SharpNoise.Modules.Module[] inputModules = NullToConstInputModules(); outputModule.Source0 = inputModules[0]; outputModule.ControlPoints = GraphPoint.ToVector2List(controlPoints); base.Refresh(); }
public void GraphPointsToIntPoints() { Interpolator = new CSharpIDW.IdwInterpolator(2); for (int i = 0; i < GPoints.Count; i++) { GraphPoint gp = GPoints[i]; CSharpIDW.Point NewPoint = new CSharpIDW.Point(gp.Diff, gp.XCoord, gp.ZCoord); Interpolator.AddPoint(NewPoint); } }
private void Connect(GraphPoint pointA, GraphPoint pointB) { var edge = new Edge(pointA, pointB); sizeMatrix[pointA.Id, pointB.Id] = edge.Size; sizeMatrix[pointB.Id, pointA.Id] = edge.Size; edges.Add(edge); Update(); }
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { //_mouseDownPosition = e.GetPosition(this.gcontrol); SelectionBox.MouseDownPosition = e.GetPosition(this); if (e.OriginalSource is FrameworkElement memberElement && memberElement.DataContext is IGraphMember member) { _mouseDownMember = member; _isLeftMouseDownOnElement = true; _startPosition = _mouseDownPosition; SetLastPositions(); }
public Line(GraphPoint p, GraphPoint q) { _infiniteSlope = false; if (Math.Abs(p.X - q.X) > Epsilon) { // if X’s are different Slope = (p.Y - q.Y) / (p.X - q.X); // compute slope _intercept = p.Y - Slope * p.X; // Y intercept from Y=mx+b } else { _infiniteSlope = true; _intercept = p.X; // X-intercept, since slope is infinite } }
public void AddGraphConnection(GraphPoint pointA, GraphPoint pointB, float diff) { Connection NewConnection = Connection.Instantiate(ConnectionPrefab); NewConnection.DiffScore = diff; NewConnection._Source = pointA; NewConnection._Target = pointB; MapGraph.AddEdge(NewConnection); GConnections.Add(NewConnection); NewInterpGraph = true; }
private void FindAndDeleteEdge(GraphPoint point) { foreach (var edge in edges) { if (edge.points.Contains(point.Id)) { edges.Remove(edge); FindAndDeleteEdge(point); break; } } }
GraphPointInfo GetPointData(GraphPoint point) // Получение информации о вершине графа { foreach (var i in data) { if (i.Point.Equals(point)) { return(i); } } return(null); }
private void OnDestroyPoint(GraphPoint point) { graphPoints.Remove(point); for (int i = 0; i < MAX_POINTS_COUNT; i++) { sizeMatrix[i, point.Id] = INF; sizeMatrix[point.Id, i] = INF; } FindAndDeleteEdge(point); GDebug.Log("Точка " + point.Id + " удалена"); }
//Used for setting data from saved file public override void SetData(Data.NodeData data) { base.SetData(data); ControlPoints = GraphPoint.ToGraphPointList(data.controlPoints, overlayWindowRect); //Get position on graph from coordinate foreach (GraphPoint controlPoint in ControlPoints) { controlPoint.CalculateGraphPoint(); } }
// Текстовое представление пути string GetPath(GraphPoint startPoint, GraphPoint endPoint) { var path = endPoint.ToString(); while (startPoint != endPoint) { endPoint = GetPointData(endPoint).PreviousPoint; path = endPoint.ToString() + path; } return(path); }
public void AddPoint(float pointX, float pointZ, float diff) { GraphPoint GPoint = GraphPoint.Instantiate(PointPrefab); GPoint.XCoord = pointX; GPoint.ZCoord = pointZ; GPoint.Diff = diff; MapGraph.AddVertex(GPoint); GPoints.Add(GPoint); NewInterpGraph = true; }
private GraphPoint Aggregate(IEnumerable <GraphPoint> points) { GraphPoint pt = new GraphPoint(); pt.N = points.Sum(item => item.N); pt.Min = points.Min(item => item.Min); pt.Max = points.Max(item => item.Max); pt.Sum = points.Sum(item => item.Sum); pt.SquaredSum = points.Sum(item => item.SquaredSum); pt.Tmax = points.Max(item => item.Tmax); pt.Tmin = points.Min(item => item.Tmin); return(pt); }
private void Disсonnect(GraphPoint pointA, GraphPoint pointB) { for (int i = 0; i < edges.Count; i++) { if (edges[i].points.Contains(pointA.Id) && edges[i].points.Contains(pointB.Id)) { edges.Remove(edges[i]); sizeMatrix[pointA.Id, pointB.Id] = INF; sizeMatrix[pointB.Id, pointA.Id] = INF; Update(); break; } } }
void enqueueDataPoint(InstrumentMode mode, int trace, int index, float x, float y) { newDataToPlot = true; GraphPoint g = new GraphPoint(); g.index = index; g.x = x; g.y = y; g.trace = trace; g.mode = mode; graphPoints.Enqueue(g); newDataToPlot = true; }
protected void AddControlPoint(object mousePosition) { GraphPoint point = new GraphPoint(Vector2.zero, overlayWindowRect); Rect pointRect = point.Rect; pointRect.position = (Vector2)mousePosition; point.Rect = pointRect; ControlPoints.Add(point); controlPoints = controlPoints.OrderBy(o => o.Coordinate.x).ToList(); //sort to get proper index selectedPoint = ControlPoints.IndexOf(point); //Selected created point Refresh(); }
private void onTick(object sender, System.EventArgs e) { // consider simplifying this through the use of a queue, // as is done for qpBoxLines, below. if (newDataToPlot == true) { while (graphPoints.Count > 0) { GraphPoint pt = graphPoints.Dequeue(); if (instrumentMode != pt.mode) { if (pt.mode == InstrumentMode.Sweep) { instrument.SetRangeX(streamLowMass - 0.6, streamHighMass + 0.6); instrument.GraphTitle = "Sweep"; instrument.XAxisTitle = "AMU"; } else if (pt.mode == InstrumentMode.Trend) { instrument.SetRangeX(0, trendDisplaySamples); instrument.GraphTitle = "Trend"; instrument.XAxisTitle = "SAMPLE"; } instrumentMode = pt.mode; } if ((instrumentMode == InstrumentMode.Sweep) && sweepParametersChanged()) { instrument.ClearGraph(); instrument.SetRangeX(streamLowMass - 0.6, streamHighMass + 0.6); } if ((Double.IsNaN(pt.x) == false) && (Double.IsNaN(pt.y) == false)) { instrument.DataPoint(pt.trace, pt.index, pt.x, pt.y); } } newDataToPlot = false; instrument.Refresh(); } lock (qpBoxLines.SyncRoot){ while (qpBoxLines.Count > 0) { string s = (string)qpBoxLines.Dequeue(); consoleBox.AppendText(s + Environment.NewLine); } } }
GraphPoint[] CreatePoints() { const int nPoints = 10; Console.WriteLine("Points on Graph\n***************"); var points = new GraphPoint[nPoints - 1]; for (var i = 0; i < nPoints / 2; i++) { var point = new GraphPoint(i, 2.3 * i + 20.0); points[i] = point; Console.WriteLine(point.ToString()); } for (var i = 0; i < nPoints / 2 - 1; i++) { var point = new GraphPoint(i, 3.0 * i + 1.0); points[nPoints / 2 + i] = point; Console.WriteLine(point.ToString()); } Console.WriteLine("****************\n"); return points; }
GraphPoint[] CreatePoints() { int n_points = 10; Console.WriteLine("Points on Graph\n***************"); GraphPoint[] points = new GraphPoint[n_points - 1]; for (int i = 0; i < n_points / 2; i++) { GraphPoint p = new GraphPoint(i, 2.3 * i + 20.0); points[i] = p; Console.WriteLine(p.ToString()); } for (int i = 0; i < n_points / 2 - 1; i++) { GraphPoint p = new GraphPoint(i, 3.0 * i + 1.0); points[n_points / 2 + i] = p; Console.WriteLine(p.ToString()); } Console.WriteLine("****************\n"); return points; }
/// <summary> /// Virtual. Plots a time graph with a filtered set of data. /// </summary> /// <param name="subSet">Filtered set of data.</param> /// <param name="panel">The panel.</param> protected override void DrawFilteredTimeGraph(IEnumerable subSet, PanelWrapper panel) { base.DrawFilteredTimeGraph(subSet, panel); // Maintain the previous and current point plotted for the virtual method call GraphPoint prevPoint = new GraphPoint(); GraphPoint currPoint = new GraphPoint(); System.Collections.Generic.Stack<FrameworkElement> dataPointStack = new System.Collections.Generic.Stack<FrameworkElement>(); System.Collections.Generic.Stack<FrameworkElement> dataPointLabelStack = new System.Collections.Generic.Stack<FrameworkElement>(); CollisionDetectionManager collisionManager = GraphBase.GetCollisionDetectionManager(this.DynamicPlotLayer); foreach (object o in subSet) { if (panel.AbortLayout) { break; } GraphPoint gp = this.GetBoundGraphPoint(o); if (null == gp) { return; } gp.X1Pixel = this.GetXForDate(gp.X1); gp.Y1Pixel = this.GetYForValue(gp.Y1); if (!Double.IsNaN(gp.Y2)) { gp.Y2Pixel = this.GetYForValue(gp.Y2); } currPoint = gp; // process the plotted data marker this.ProcessPlottedDataMarker(prevPoint, currPoint); if (!this.Minimized) { if (!double.IsNaN(gp.Y1) && currPoint.X1Pixel >= 0 && currPoint.X1Pixel < this.DynamicMainLayerViewport.ActualWidth) { FrameworkElement marker = this.GetPlottedDataMarker(gp); double left = Canvas.GetLeft(marker); #if !SILVERLIGHT // For WPF should snap to grid if requested bool snap = GraphBase.GetSnapToPixels(marker); if (marker.SnapsToDevicePixels != snap) { marker.SnapsToDevicePixels = snap; } #endif if (left < 0 || (left + marker.Width) > this.DynamicMainLayerViewport.ActualWidth) { this.CurrentWorkingPanel.SeamedElementCollection.Add(marker); } this.DynamicPlotLayer.Children.Add(marker); dataPointStack.Push(marker); FrameworkElement labelElement = null; if (null != this.LabelTemplate) { labelElement = this.LabelTemplate.LoadContent() as FrameworkElement; labelElement.DataContext = gp; dataPointLabelStack.Push(labelElement); } if (null != labelElement) { double offsetValueX = GraphBase.GetXOffset(labelElement); double offsetValueY = GraphBase.GetYOffset(labelElement); // define the label position double labelY = currPoint.Y1Pixel; if (!double.IsNaN(gp.Y2) && gp.Y1 < gp.Y2) { labelY = currPoint.Y2Pixel; } double markerOffset = Math.Abs(GraphBase.GetYOffset(marker)) + 2; Canvas.SetTop(labelElement, (labelY - markerOffset) + offsetValueY); Canvas.SetLeft(labelElement, currPoint.X1Pixel + offsetValueX); labelElement.Visibility = this.ShowDataPointLabels; this.DynamicPlotLayer.Children.Add(labelElement); GraphBase.SetDataPointLabel(marker, labelElement); panel.LabelElements.Add(labelElement); marker.MouseEnter += new MouseEventHandler(this.DataPointMarker_MouseEnter); marker.MouseLeave += new MouseEventHandler(this.DataPointMarker_MouseLeave); } } } prevPoint = currPoint; } if (!panel.AbortLayout && this.DetectCollisions) { Collision previousCollision = null; // get the last items in the collection for the data context object[] lastItems = this.GetLastDataPoints(); object lastObject = lastItems[1]; object secondLastObject = lastItems[0]; byte lastItemsCheck = 0; while (dataPointStack.Count > 0) { FrameworkElement ele = dataPointStack.Pop(); FrameworkElement labelEle = GraphBase.GetDataPointLabel(ele); if (lastItemsCheck < 2 && null != labelEle && null != labelEle.DataContext) { // this is the last item on the page. // we plot back to front to check if things overlap. ++lastItemsCheck; object gp = ((GraphPoint)labelEle.DataContext).DataContext; if (lastObject == gp) { // this is the last item in the series. GraphBase.SetLastItem(ele, true); labelEle.Visibility = Visibility.Visible; labelEle.RenderTransform = this.LabelTransform; } if (secondLastObject == gp) { // this is the second last item in the series. GraphBase.SetSecondToLast(ele, true); labelEle.Visibility = Visibility.Visible; } } FrameworkElement clashElement = collisionManager.RegisterAndTestIfMarkerOverlaps(ele); if (null != clashElement) { previousCollision = new Collision(clashElement, ele, true); this.CurrentWorkingPanel.CollisionCollection.Add(previousCollision); GraphBase.SetDataPointOverlapProperty(ele, true); GraphBase.SetDataPointOverlapProperty(labelEle, true); labelEle.Visibility = Visibility.Collapsed; GraphBase.SetDataPointOverlapProperty(clashElement, true); FrameworkElement clashElementLabel = GraphBase.GetDataPointLabel(clashElement); GraphBase.SetDataPointOverlapProperty(clashElementLabel, true); clashElementLabel.Visibility = Visibility.Collapsed; } else { // this marker does not overlap previousCollision = null; } } while (dataPointLabelStack.Count > 0) { FrameworkElement ele2 = dataPointLabelStack.Pop(); if (collisionManager.RegisterAndTestIfLabelOverlaps(ele2)) { GraphBase.SetDataPointOverlapProperty(ele2, true); ele2.Visibility = Visibility.Collapsed; } } PanelWrapper otherPanel = null; // we get panel 2 then panel 1 when getting both panels. double markerOffsetToUse = 0; // perform seam detection // panel1 is to the left of panel2 if (this.CurrentWorkingPanel == this.Panel1) { // panel2 markers must be incremented by the width of the layer. otherPanel = this.Panel2; markerOffsetToUse = this.Panel1.Width; } else { // panel1 markers must be decremented by the width of the plot layer. // if we are renewing both panels, then do not do collisions detections on seams for if (true != this.RenewingBothPanels) { otherPanel = this.Panel1; markerOffsetToUse = this.Panel2.Width * -1; } } // this gets run if we are renewing a panel, but if renewing both, only for panel 1 if (null != otherPanel) { LookThroughAdjacentPanelForOverlap(this.CurrentWorkingPanel, otherPanel, markerOffsetToUse); } double lastCollisionPosition = -1; foreach (Collision collision in this.CurrentWorkingPanel.CollisionCollection) { if (null != this.CollisionTemplate) { FrameworkElement collisionIcon = this.CollisionTemplate.LoadContent() as FrameworkElement; double theXOffset = GraphBase.GetXOffset(collisionIcon); double theYOffset = GraphBase.GetYOffset(collisionIcon); if (null != collisionIcon) { double localxPosition = Canvas.GetLeft(collision.ClusterStartElement) + theXOffset; double localyPosition = Canvas.GetTop(collision.ClusterStartElement) + theYOffset; if (lastCollisionPosition == -1 || localxPosition < lastCollisionPosition - 46) { lastCollisionPosition = localxPosition; Canvas.SetLeft(collisionIcon, localxPosition); Canvas.SetTop(collisionIcon, localyPosition); if (true == collision.ClusterShowingIcon) { this.DynamicPlotLayer.Children.Add(collisionIcon); } } } } } } }
void __AddGameInfo(IGameInfo info) { int x, y; try { FindSlotToPlot (info, out x, out y); } catch (Exception) { x = -1; y = -1; } GraphPoint point = new GraphPoint (info); point.x = x; point.y = y; points.Add (point); }
public bool UpdateGeometry(double X, double Y, Point mousePos, double zoomFactor, bool bForceUpdate, Int64 timeStepMS) { bool bUpdatedGeometry = false; if (UpdateIntenalState(mousePos) || bForceUpdate) { bUpdatedGeometry = true; if (_enabled && _samples.Count > 0) { CalculateGraphPoints(GraphMode.AverageValues, X, Y, zoomFactor, timeStepMS); if (_points.Count >= 2) { // Clear old geometry _geometry.Clear(); _selectedGraphPoint = null; using (StreamGeometryContext ctx = _geometry.Open()) { for (int i = 0; i + 1 < _points.Count; ++i) { GraphPoint P1 = _points[i]; GraphPoint P2 = _points[i + 1]; if (IsPointVisible(P1._coordinates) || IsPointVisible(P2._coordinates)) { GraphPoint selectedGraphPoint = IsMousePosWithinSegment(mousePos, P1, P2); if (selectedGraphPoint != null && SystemPerformanceGraphsCanvas._hasSelectedGraphPoint == false) { _selectedGraphPoint = selectedGraphPoint; DrawFilledSquare(ctx, _selectedGraphPoint._coordinates, 10); SystemPerformanceGraphsCanvas._hasSelectedGraphPoint = true; } ctx.BeginFigure(P1._coordinates, true /* is filled */, false /* is closed */); ctx.LineTo(P2._coordinates, true /* is stroked */, false /* is smooth join */); } } } if (_selectedGraphPoint != null) { using (StreamGeometryContext ctx = _selectionLinesGeometry.Open()) { ctx.BeginFigure(new Point(SystemPerformanceGraphsCanvas._savedHorizontalViewport.X, _selectedGraphPoint._coordinates.Y), false /* is filled */, false /* is closed */); ctx.LineTo(new Point(_selectedGraphPoint._coordinates.X, _selectedGraphPoint._coordinates.Y), true/* is stroked */, false /* is smooth join */); ctx.LineTo(new Point(_selectedGraphPoint._coordinates.X, SystemPerformanceGraphsCanvas.cSystemGraphsHeight), true /* is stroked */, false /* is smooth join */); } } else { _selectionLinesGeometry.Clear(); } } } else { // Clear old geometry _geometry.Clear(); } } return bUpdatedGeometry; }
private void AddAimPosToNaviMap ( GraphPoint<NaviPoint>[] map, GraphPoint<NaviPoint> aimNaviP, GraphPoint<NaviPoint> curNaviP, int prePointSum, List<Segment> guardLines, List<Segment> borderLines ) { map[prePointSum + 1] = aimNaviP; for (int i = 0; i < prePointSum; i++) { Segment seg = new Segment( aimNaviP.value.Pos, map[i].value.Pos ); bool cross = false; foreach (Segment guardLine in guardLines) { if (Segment.IsCross( guardLine, seg )) { cross = true; break; } } if (!cross) { foreach (Segment borderLine in borderLines) { if (Segment.IsCross( borderLine, seg )) { cross = true; break; } } } if (!cross) { float weight = Vector2.Distance( aimNaviP.value.Pos, map[i].value.Pos ); GraphPoint<NaviPoint>.Link( map[i], aimNaviP, weight ); } } Segment curToAim = new Segment( curNaviP.value.Pos, aimNaviP.value.Pos ); bool link = true; foreach (Segment guardLine in guardLines) { if (Segment.IsCross( guardLine, curToAim )) { if (MathTools.Vector2Cross( guardLine.endPoint - guardLine.startPoint, curNaviP.value.Pos - guardLine.endPoint ) < 0) { link = false; break; } } } if (link) { foreach (Segment borderLine in borderLines) { if (Segment.IsCross( borderLine, curToAim )) { link = false; break; } } } if (link) { float weight = Vector2.Distance( curNaviP.value.Pos, aimNaviP.value.Pos ); GraphPoint<NaviPoint>.Link( curNaviP, aimNaviP, weight ); } }
/// <summary> /// Adds the label element. /// </summary> /// <param name="gp">GraphPoint containing the co-ordinates for the label.</param> /// <param name="panel">The panel to add the label element.</param> private void AddLabelElement(GraphPoint gp, PanelWrapper panel) { FrameworkElement labelElement = null; if (gp.Label == null) { if (null != this.LabelTemplate) { labelElement = this.LabelTemplate.LoadContent() as FrameworkElement; } } else { labelElement = gp.Label; } if (null != labelElement) { labelElement.DataContext = gp; TimeActivityGraph.SetIsLabel(labelElement, true); panel.LabelElements.Add(labelElement); labelElement.Visibility = this.ShowDataPointLabels; labelElement.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.LabelElement_MouseLeftButtonDown); } }
/// <summary> /// Overridden. process the Point based on the previous value. /// </summary> /// <param name="previousPoint">Previous Point Plotted.</param> /// <param name="currentPoint">Current Point Plotted.</param> protected override void ProcessPlottedDataMarker(GraphPoint previousPoint, GraphPoint currentPoint) { if (this.Minimized) { base.ProcessPlottedDataMarker(previousPoint, currentPoint); } else { // override to process other information if ((previousPoint.X1Pixel != 0 || previousPoint.Y1Pixel != 0) && this.ShowInterpolationLines) { // define the zindex for the line based on that of the data marker FrameworkElement dataMarkerTemplate = this.DataMarkerTemplate.LoadContent() as FrameworkElement; int zindex = Canvas.GetZIndex(dataMarkerTemplate) - 2; Line interpolationLine = new Line(); Canvas.SetZIndex(interpolationLine, zindex); interpolationLine.Stroke = this.InterpolationLineColor; interpolationLine.StrokeThickness = this.InterpolationLineThickness; if (previousPoint.X1Pixel < 0) { interpolationLine.Y1 = TimeLineGraph.GetYAtX(0, new Point(previousPoint.X1Pixel, previousPoint.Y1Pixel), new Point(currentPoint.X1Pixel, currentPoint.Y1Pixel)); interpolationLine.X1 = 0; } else { interpolationLine.X1 = previousPoint.X1Pixel; interpolationLine.Y1 = previousPoint.Y1Pixel; } if (currentPoint.X1Pixel > this.DynamicMainLayerViewport.ActualWidth) { interpolationLine.Y2 = TimeLineGraph.GetYAtX(this.DynamicMainLayerViewport.ActualWidth, new Point(previousPoint.X1Pixel, previousPoint.Y1Pixel), new Point(currentPoint.X1Pixel, currentPoint.Y1Pixel)); interpolationLine.X2 = this.DynamicMainLayerViewport.ActualWidth; } else { interpolationLine.X2 = currentPoint.X1Pixel; interpolationLine.Y2 = currentPoint.Y1Pixel; } this.DynamicPlotLayer.Children.Add(interpolationLine); } } }
public NodeAStar ( GraphPoint<NaviPoint> point, NodeAStar father ) { this.point = point; this.father = father; this.G = 0; this.H = 0; this.F = 0; }
/// <summary> /// 使用A*算法依据当前信息计算一条最短的路径。 /// 注意,如果目标点在警戒线以内,会返回一条并非如你期望的路径。 /// 所以请自行实现目标点无法到达时的处理逻辑。 /// </summary> /// <param name="curPos"></param> /// <param name="aimPos"></param> /// <returns></returns> public NaviPoint[] CalPathUseAStar ( Vector2 curPos, Vector2 aimPos ) { #region 复制导航图 GraphPoint<NaviPoint>[] map = new GraphPoint<NaviPoint>[Map.Length + 2]; GraphPoint<NaviPoint>[] temp = GraphPoint<NaviPoint>.DepthCopy( Map ); for (int i = 0; i < temp.Length; i++) { map[i] = temp[i]; } #endregion #region 将当前点和目标点加入到导航图中 int prePointSum = temp.Length; GraphPoint<NaviPoint> curNaviPoint = new GraphPoint<NaviPoint>( new NaviPoint( null, -1, curPos ), new List<GraphPath<NaviPoint>>() ); GraphPoint<NaviPoint> aimNaviPoint = new GraphPoint<NaviPoint>( new NaviPoint( null, -1, aimPos ), new List<GraphPath<NaviPoint>>() ); AddCurPosToNaviMap( map, curNaviPoint, prePointSum, GuardLines, BorderLines ); AddAimPosToNaviMap( map, aimNaviPoint, curNaviPoint, prePointSum, GuardLines, BorderLines ); #endregion #region 计算最短路径,使用A*算法 List<NodeAStar> open = new List<NodeAStar>(); List<NodeAStar> close = new List<NodeAStar>(); open.Add( new NodeAStar( curNaviPoint, null ) ); NodeAStar cur = null; while (open.Count != 0) { cur = open[open.Count - 1]; if (cur.point == aimNaviPoint) break; open.RemoveAt( open.Count - 1 ); close.Add( cur ); foreach (GraphPath<NaviPoint> path in cur.point.neighbors) { if (Contains( close, path.neighbor )) { continue; } else { NodeAStar inOpenNode; if (Contains( open, path.neighbor, out inOpenNode )) { float G = cur.G + path.weight; if (inOpenNode.G > G) { inOpenNode.G = G; inOpenNode.F = G + inOpenNode.H; } } else { NodeAStar childNode = new NodeAStar( path.neighbor, cur ); childNode.G = cur.G + path.weight; childNode.H = Vector2.Distance( aimPos, childNode.point.value.Pos ); childNode.F = childNode.G + childNode.H; SortInsert( open, childNode ); } } } } //if (cur == null) // return null; Stack<NodeAStar> cahe = new Stack<NodeAStar>(); while (cur.father != null) { cahe.Push( cur ); cur = cur.father; } NaviPoint[] result = new NaviPoint[cahe.Count]; int j = 0; foreach (NodeAStar node in cahe) { result[j] = node.point.value; j++; } return result; #endregion }
/// <summary> /// Gets the interpolation line for the minimized plot layer. /// </summary> /// <param name="gp">The GraphPoint containig the co-ordinates.</param> /// <returns>Returns the interpolation line.</returns> protected FrameworkElement GetInterpolationLine(GraphPoint gp) { Shape interpolationLine = null; DataTemplate template = null; if (this.LayoutRoot.Resources.Contains(MinimizedViewInterpolationLineElementName)) { template = this.LayoutRoot.Resources[MinimizedViewInterpolationLineElementName] as DataTemplate; if (template != null) { interpolationLine = template.LoadContent() as Shape; interpolationLine.DataContext = gp; } } if (interpolationLine == null || template == null) { throw new ArgumentException(GraphingResources.InterpolationLineTemplateNotFound); } Line minimizedLine = interpolationLine as Line; if (minimizedLine != null) { minimizedLine.X1 = Math.Max(0, gp.X1Pixel); minimizedLine.X2 = Math.Min(gp.X2Pixel, this.DynamicMainLayerViewport.ActualWidth); if (gp.X1X2Pixel < interpolationLine.StrokeThickness) { minimizedLine.X1 = gp.X1Pixel; minimizedLine.X2 = gp.X1Pixel + interpolationLine.StrokeThickness; } } return interpolationLine; }
public void BuildMap ( EyeableBorderObjInfo[] objInfos, Rectanglef mapBorder, float spaceForTank ) { #region 对每一个BorderObj生成逻辑坐标上的凸包点集,并向外扩展 borderLines = new List<Segment>(); convexs = new List<GuardConvex>(); foreach (EyeableBorderObjInfo obj in objInfos) { if (obj.ConvexHall == null || obj.IsDisappeared || obj.ConvexHall.Points == null) continue; Matrix matrix = obj.EyeableInfo.CurTransMatrix; GraphPoint<NaviPoint>[] convexHall; List<BordPoint> bordPoints = obj.ConvexHall.Points; if (bordPoints.Count > 2) { List<GraphPoint<NaviPoint>> list = new List<GraphPoint<NaviPoint>>(); for (int i = 0; i < bordPoints.Count; i++) { Vector2 lastPos = Vector2.Transform( ConvertHelper.PointToVector2( bordPoints[i - 1 < 0 ? bordPoints.Count - 1 : i - 1].p ), matrix ); Vector2 curPos = Vector2.Transform( ConvertHelper.PointToVector2( bordPoints[i].p ), matrix ); Vector2 nextPos = Vector2.Transform( ConvertHelper.PointToVector2( bordPoints[(i + 1) % bordPoints.Count].p ), matrix ); Vector2 v1 = curPos - lastPos; Vector2 v2 = curPos - nextPos; float ang = MathTools.AngBetweenVectors( v1, v2 ); if (ang >= MathHelper.PiOver2) { float halfDes = (float)(spaceForTank / Math.Sin( ang )); Vector2 delta = halfDes * Vector2.Normalize( v1 ) + halfDes * Vector2.Normalize( v2 ); list.Add( new GraphPoint<NaviPoint>( new NaviPoint( obj, bordPoints[i].index, curPos + delta ), new List<GraphPath<NaviPoint>>() ) ); } else { v1.Normalize(); v2.Normalize(); Vector2 cenV = Vector2.Normalize( v1 + v2 ); Vector2 vertiV = new Vector2( cenV.Y, -cenV.X ); float ang2 = MathHelper.PiOver4 - 0.25f * ang; float vertiL = (float)(spaceForTank * Math.Tan( ang2 )); list.Add( new GraphPoint<NaviPoint>( new NaviPoint( obj, bordPoints[i].index, curPos + spaceForTank * cenV + vertiL * vertiV ), new List<GraphPath<NaviPoint>>() ) ); list.Add( new GraphPoint<NaviPoint>( new NaviPoint( obj, bordPoints[i].index, curPos + spaceForTank * cenV - vertiL * vertiV ), new List<GraphPath<NaviPoint>>() ) ); } // 添加borderLine borderLines.Add( new Segment( curPos, nextPos ) ); } convexHall = list.ToArray(); convexs.Add( new GuardConvex( convexHall ) ); } else if (bordPoints.Count == 2) { convexHall = new GraphPoint<NaviPoint>[4]; Vector2 startPos = Vector2.Transform( ConvertHelper.PointToVector2( bordPoints[0].p ), matrix ); Vector2 endPos = Vector2.Transform( ConvertHelper.PointToVector2( bordPoints[1].p ), matrix ); Vector2 dir = endPos - startPos; dir.Normalize(); Vector2 normal = new Vector2( dir.Y, -dir.X ); convexHall[0] = new GraphPoint<NaviPoint>( new NaviPoint( obj, bordPoints[0].index, startPos - dir * spaceForTank ), new List<GraphPath<NaviPoint>>() ); convexHall[1] = new GraphPoint<NaviPoint>( new NaviPoint( obj, bordPoints[0].index, startPos + spaceForTank * normal ), new List<GraphPath<NaviPoint>>() ); convexHall[2] = new GraphPoint<NaviPoint>( new NaviPoint( obj, bordPoints[1].index, endPos + spaceForTank * normal ), new List<GraphPath<NaviPoint>>() ); convexHall[3] = new GraphPoint<NaviPoint>( new NaviPoint( obj, bordPoints[1].index, endPos + dir * spaceForTank ), new List<GraphPath<NaviPoint>>() ); //if (float.IsNaN( convexHall[0].value.Pos.X ) || float.IsNaN( convexHall[1].value.Pos.X )) //{ //} // 添加borderLine borderLines.Add( new Segment( startPos, endPos ) ); convexs.Add( new GuardConvex( convexHall ) ); } } #endregion #region 得到警戒线 guardLines = new List<Segment>(); foreach (GuardConvex convex in convexs) { for (int i = 0; i < convex.points.Length; i++) { guardLines.Add( new Segment( convex[i].value.Pos, convex[(i + 1) % convex.Length].value.Pos ) ); //if (float.IsNaN( convex[i].value.Pos.X )) //{ //} } } mapBorder = new Rectanglef( mapBorder.X + spaceForTank, mapBorder.Y + spaceForTank, mapBorder.Width - 2 * spaceForTank, mapBorder.Height - 2 * spaceForTank ); guardLines.Add( new Segment( mapBorder.UpLeft, mapBorder.UpRight ) ); guardLines.Add( new Segment( mapBorder.UpRight, mapBorder.DownRight ) ); guardLines.Add( new Segment( mapBorder.DownRight, mapBorder.DownLeft ) ); guardLines.Add( new Segment( mapBorder.DownLeft, mapBorder.UpLeft ) ); #endregion #region 检查凸包内部连线是否和警戒线相交,如不相交则连接该连线并计算权值 foreach (GuardConvex convex in convexs) { for (int i = 0; i < convex.Length; i++) { // 检查连线是否超出边界 if (!mapBorder.Contains( convex[i].value.Pos )) continue; Segment link = new Segment( convex[i].value.Pos, convex[(i + 1) % convex.Length].value.Pos ); bool isCross = false; foreach (Segment guardLine in guardLines) { if (link.Equals( guardLine )) continue; if (Segment.IsCross( link, guardLine )) { isCross = true; break; } } if (!isCross) { float weight = Vector2.Distance( convex[i].value.Pos, convex[(i + 1) % convex.Length].value.Pos ); //if (float.IsNaN( weight )) //{ //} GraphPoint<NaviPoint>.Link( convex[i], convex[(i + 1) % convex.Length], weight ); } } } #endregion #region 检查凸包之间连线是否与警戒线以及边界线相交,如不相交则连接并计算权值 for (int i = 0; i < convexs.Count - 1; i++) { for (int j = i + 1; j < convexs.Count; j++) { foreach (GraphPoint<NaviPoint> p1 in convexs[i].points) { // 检查连线是否超出边界 if (!mapBorder.Contains( p1.value.Pos )) continue; foreach (GraphPoint<NaviPoint> p2 in convexs[j].points) { Segment link = new Segment( p1.value.Pos, p2.value.Pos ); bool isCross = false; foreach (Segment guardLine in guardLines) { if (Segment.IsCross( link, guardLine )) { isCross = true; break; } } if (!isCross) { foreach (Segment borderLine in borderLines) { if (Segment.IsCross( link, borderLine )) { isCross = true; break; } } } if (!isCross) { float weight = Vector2.Distance( p1.value.Pos, p2.value.Pos ); //if (float.IsNaN( weight )) //{ //} GraphPoint<NaviPoint>.Link( p1, p2, weight ); } } } } } #endregion #region 整理导航图 List<GraphPoint<NaviPoint>> points = new List<GraphPoint<NaviPoint>>(); foreach (GuardConvex convex in convexs) { foreach (GraphPoint<NaviPoint> p in convex.points) { points.Add( p ); } } naviGraph = points.ToArray(); #endregion }
private void PlotPoint(Cairo.Context cairo, GraphPoint point) { if (point.x < 0 || point.y < 0) return; int size = point_size - inter_point_gap; int x = start_x + point.x; int y = start_y - point.y; if (point.info.Rated) { cairo.Color = pointBorderColor; cairo.Arc (x + size / 2, y + size / 2, size / 2, 0, 44.0 / 7.0); // 2 pi = 360 degrees cairo.Stroke (); cairo.Color = point.info. Computer ? computerColor : ratedColor; cairo.Arc (x + size / 2, y + size / 2, size / 2, 0, 44.0 / 7.0); // 2 pi = 360 degrees cairo.Fill (); } else { cairo.Color = pointBorderColor; cairo.Rectangle (x, y, size, size); cairo.Stroke (); cairo.Color = point.info. Computer ? computerColor : unratedColor; cairo.Rectangle (x, y, size, size); cairo.Fill (); } }
bool OverlappingPoint(int x, int y, int width, out GraphPoint matching) { foreach (GraphPoint point in points) { if (IsOverlapping (x, y, width, point.x, point.y)) { matching = point; return true; } } matching = GraphPoint.Zero; return false; }
private GraphPoint IsMousePosWithinSegment(Point mousePos, GraphPoint p1, GraphPoint p2) { GraphPoint result = null; if (mousePos.X >= p1._coordinates.X && mousePos.X <= p2._coordinates.X) { double aCoefCoords = (p1._coordinates.Y - p2._coordinates.Y) / (p1._coordinates.X - p2._coordinates.X); double bCoefCoords = p2._coordinates.Y - (aCoefCoords * p2._coordinates.X); double expectedY = aCoefCoords * mousePos.X + bCoefCoords; double fError = Math.Abs(expectedY - mousePos.Y); const double cCurveSelectionTolerance = 10.0f; if (fError <= cCurveSelectionTolerance) { double aCoefValue = (p2._value - p1._value) / (p2._coordinates.X - p1._coordinates.X); double value = aCoefValue * (mousePos.X - p1._coordinates.X) + p1._value; result = new GraphPoint(new Point(mousePos.X, expectedY), (float)value); //Console.WriteLine("Selected Curve ({0} - Error({1:00} pixels), time range: {2}s - {3}s, value: {4}{5}", _description, fError,p1._coordinates.X / FASTBuildMonitorControl.pix_per_second, p2._coordinates.X / FASTBuildMonitorControl.pix_per_second, value, _unitTag); } } return result; }
/// <summary> /// Adds the marker from graph point. /// </summary> /// <param name="gp">The GraphPoint.</param> /// <param name="renderFlagStick">If set to <c>true</c> [render flag stick].</param> /// <returns>The marker plotted from the graphpoint template.</returns> private FrameworkElement AddMarkerFromGraphPoint(GraphPoint gp, bool renderFlagStick) { FrameworkElement marker = null; if (gp.DataMarkerTemplate != null) { marker = gp.DataMarkerTemplate.LoadContent() as FrameworkElement; marker.DataContext = gp; marker.MaxWidth = this.DynamicMainLayerViewport.ActualWidth; this.DynamicPlotLayer.Children.Add(marker); if (renderFlagStick) { FrameworkElement flagStick = GetFlagStick(gp.X1Pixel, this.interpolationLineStartYPosition, gp.Y1Pixel + GraphBase.GetYOffset(marker)); SetFlagStick(marker, flagStick); this.DynamicPlotLayer.Children.Add(flagStick); } } return marker; }
public GuardConvex ( GraphPoint<NaviPoint>[] points ) { this.points = points; }
/// <summary> /// Gets the symbol for the datapoint. /// </summary> /// <param name="graphPoint">Start point of the symbol.</param> /// <returns>A symbol at a specified position.</returns> protected virtual FrameworkElement GetPlottedDataMarker(GraphPoint graphPoint) { FrameworkElement dataMarkerTemplate = this.DataMarkerTemplate.LoadContent() as FrameworkElement; if (dataMarkerTemplate == null) { throw new ArgumentException(GraphingResources.GraphDisplayDataMarkerError); } Canvas.SetLeft(dataMarkerTemplate, graphPoint.X1Pixel + GraphBase.GetXOffset(dataMarkerTemplate)); Canvas.SetTop(dataMarkerTemplate, graphPoint.Y1Pixel + GraphBase.GetYOffset(dataMarkerTemplate)); GraphBase.SetDataPoint(dataMarkerTemplate, true); return dataMarkerTemplate; }
private bool Contains ( List<NodeAStar> list, GraphPoint<NaviPoint> graphPoint ) { if (list.Find( new Predicate<NodeAStar>( delegate( NodeAStar node ) { if (node.point == graphPoint) return true; else return false; } ) ) == null) return false; else return true; }
/// <summary> /// Gets the symbol for the datapoint. /// </summary> /// <param name="graphPoint">Point at which the symbol needs to be positioned.</param> /// <returns>A symbol at a specified position.</returns> protected override FrameworkElement GetPlottedDataMarker(GraphPoint graphPoint) { FrameworkElement dataMarkerTemplate = this.DataMarkerTemplate.LoadContent() as FrameworkElement; if (dataMarkerTemplate == null) { throw new ArgumentException(GraphingResources.GraphDisplayDataMarkerError); } Canvas.SetLeft(dataMarkerTemplate, graphPoint.X1Pixel + GraphBase.GetXOffset(dataMarkerTemplate)); Canvas.SetTop(dataMarkerTemplate, graphPoint.Y1Pixel + GraphBase.GetYOffset(dataMarkerTemplate)); if (true == this.DebugDataPointMarkers) { TextBlock tb = new TextBlock(); tb.FontSize = 8; markerCount++; tb.Text = (markerCount - markerCountStart).ToString(System.Globalization.CultureInfo.InvariantCulture); Canvas.SetZIndex(tb, markerCount); Canvas.SetLeft(tb, graphPoint.X1Pixel); Canvas.SetTop(tb, graphPoint.Y1Pixel); this.DynamicPlotLayer.Children.Add(tb); System.Diagnostics.Debug.WriteLine("Added point at " + graphPoint.X1Pixel + " : " + graphPoint.Y1Pixel + " : " + dataMarkerTemplate.ActualHeight + " : " + dataMarkerTemplate.ActualWidth + " Point ID IS : " + tb.Text); } GraphBase.SetDataPoint(dataMarkerTemplate, true); dataMarkerTemplate.Tag = (markerCount - markerCountStart).ToString(System.Globalization.CultureInfo.InvariantCulture); return dataMarkerTemplate; }
private void AddCurPosToNaviMap ( GraphPoint<NaviPoint>[] map, GraphPoint<NaviPoint> curNaviP, int prePointSum, List<Segment> guardLines, List<Segment> borderLines ) { map[prePointSum] = curNaviP; for (int i = 0; i < prePointSum; i++) { Segment seg = new Segment( curNaviP.value.Pos, map[i].value.Pos ); bool cross = false; foreach (Segment guardLine in guardLines) { if (Segment.IsCross( guardLine, seg )) { cross = true; break; } } if (!cross) { foreach (Segment borderLine in borderLines) { if (Segment.IsCross( borderLine, seg )) { cross = true; break; } } } if (!cross) { float weight = Vector2.Distance( curNaviP.value.Pos, map[i].value.Pos ); GraphPoint<NaviPoint>.Link( map[i], curNaviP, weight ); } } }
/// <summary> /// Gets a data bound Graph Point element. /// </summary> /// <param name="o">Object containing binding data.</param> /// <returns>GraphPoint with bound data.</returns> internal GraphPoint GetBoundGraphPoint(object o) { #if SILVERLIGHT DependencyObject dp = this.PointTemplate.LoadContent(); if (null == dp) { return null; } GraphPoint gp = dp as GraphPoint; if (null == gp) { return null; } gp.DataContext = o; #else GraphPoint gp = new GraphPoint(); if (null == this.bindingY1 && null == this.bindingY2 && null == this.bindingX2) { return null; } if (null != this.bindingY1) { Binding b1 = new Binding(); b1.Mode = BindingMode.OneTime; b1.Path = this.bindingY1.ParentBinding.Path; b1.Source = o; gp.SetBinding(GraphPoint.Y1Property, b1); } if (null != this.bindingY2) { Binding b2 = new Binding(); b2.Mode = BindingMode.OneTime; b2.Path = this.bindingY2.ParentBinding.Path; b2.Source = o; gp.SetBinding(GraphPoint.Y2Property, b2); } if (null != this.bindingX1) { Binding b3 = new Binding(); b3.Mode = BindingMode.OneTime; b3.Path = this.bindingX1.ParentBinding.Path; b3.Source = o; gp.SetBinding(GraphPoint.X1Property, b3); } if (null != this.bindingX2) { Binding b4 = new Binding(); b4.Mode = BindingMode.OneTime; b4.Path = this.bindingX2.ParentBinding.Path; b4.Source = o; gp.SetBinding(GraphPoint.X2Property, b4); } if (null != this.bindingDataMarkerTemplate) { Binding b5 = new Binding(); b5.Mode = BindingMode.OneTime; b5.Path = this.bindingDataMarkerTemplate.ParentBinding.Path; b5.Source = o; gp.SetBinding(GraphPoint.DataMarkerTemplateProperty, b5); } if (null != this.bindingLabel) { Binding b6 = new Binding(); b6.Mode = BindingMode.OneTime; b6.Path = this.bindingLabel.ParentBinding.Path; b6.Source = o; gp.SetBinding(GraphPoint.LabelProperty, b6); } gp.DataContext = o; #endif return gp; }
bool MatchingPoint(int x, int y, int width, out GraphPoint matching) { foreach (GraphPoint point in points) { if (PointInsideRect (x, y, point.x, point.y, width, true)) { matching = point; return true; } } matching = GraphPoint.Zero; return false; }
/// <summary> /// Virtual. process the Point based on the previous value. /// </summary> /// <param name="previousPoint">Previous Point Plotted.</param> /// <param name="currentPoint">Current Point Plotted.</param> protected virtual void ProcessPlottedDataMarker(GraphPoint previousPoint, GraphPoint currentPoint) { // override to process other information if (this.Minimized && this.MinimizedPlotLayer != null) { if (previousPoint.X1Pixel != 0 || previousPoint.Y1Pixel != 0) { GraphPoint gp = new GraphPoint(); gp.X1Pixel = previousPoint.X1Pixel; gp.X2Pixel = currentPoint.X1Pixel; gp.Y1Pixel = this.NonDynamicRightAxisViewPort.ActualHeight / 2; this.MinimizedPlotLayer.Children.Add(this.GetInterpolationLine(gp)); } } }
public GraphControl(GraphItem[] dataset,int left,int top,int right, int bottom) : base("GraphControl",left,top,right,bottom) { this.points=new GraphPoint[dataset.Length]; offset=new Size(5,2); for(int i=0;i<dataset.Length;i++) { Point point=new Point(); point.X=(dataset[i].X * (edge/100)); point.Y=edge-(dataset[i].Y * (edge/100)); point=point+offset; points[i]=new GraphPoint(point,dataset[i]); this.Controls.Add(points[i]); this.Controls.Add(points[i].Label); } bar=new ProgressBar(); bar.Size=new Size(edge+4,16); bar.Location=new Point(3,edge+5); this.Controls.Add(bar); this.bar.Maximum=this.Right; this.bar.Minimum=this.Left; this.bar.Step=(edge/10); }