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; }
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 } }
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; }
/// <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 }
public NodeAStar ( GraphPoint<NaviPoint> point, NodeAStar father ) { this.point = point; this.father = father; this.G = 0; this.H = 0; this.F = 0; }
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 }
/// <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); } } } } } } }
/// <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); } }
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; }
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 ); } } }
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; }
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; }
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 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 (); } }
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 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); }
public GuardConvex ( GraphPoint<NaviPoint>[] points ) { this.points = points; }
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; }
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; }
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> /// 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; }
/// <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; }
/// <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; }
/// <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); } } }
/// <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)); } } }
/// <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; }
/// <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; }