public void Render(Graphics graphics, MyPoint org, int zoom) { if (!_visible) { return; } const int height = 8; const int posX = 20; const int hSpace = 10; int posY = 30; //int posY = ClientSize.Height - 30; int width = 150; Pen pen = new Pen(Color.Black, 2.0f); int textHeight = (int)_font.GetHeight(); graphics.DrawLine(pen, posX, posY, posX + width, posY); graphics.DrawLine(pen, posX, posY - height, posX, posY + height); graphics.DrawLine(pen, posX + width, posY - height, posX + width, posY + height); MyPointF world0 = ScreenToWorld(org, zoom); MyPointF world1 = ScreenToWorld(org + new MyPoint(width, 0), zoom); double dist = TrackDataManager.ComputeDistance(world0.Y, world0.X, world1.Y, world1.X); graphics.DrawString(Units.Provider.DistanceString(dist), _font, Brushes.Black, posX + width + hSpace, posY - textHeight / 2); }
private MyPoint WorldToScreen(MyPointF pt) { int x = (int)(256.0 * ((pt.X + 180.0) / 360.0 * (1 << _zoom))); int y = (int)(256.0 * ((1.0 - Math.Log(Math.Tan(pt.Y * Math.PI / 180.0) + 1.0 / Math.Cos(pt.Y * Math.PI / 180.0)) / Math.PI) / 2.0 * (1 << _zoom))); return(new MyPoint(x, y)); }
private void CenterView(MyPointF world) { MyPoint center = GetClientRectCenter(); _screenPos = WorldToScreen(world) - center; Invalidate(); }
/// <summary> /// Zooms in one level. /// </summary> public void ZoomIn() { if (_zoom >= _maxZoom) { return; } MyPoint center = GetClientRectCenter(); MyPointF world = ScreenToWorld(_screenPos + center); _zoom++; _screenPos = WorldToScreen(world) - center; _partTrack.UpdatePointSet(_zoom); Invalidate(); }
public override bool Equals(object obj) { // If parameter is null return false. if (obj == null) { return(false); } // If parameter cannot be cast to Point return false. if (obj.GetType() != typeof(MyPointF)) { return(false); } MyPointF p = (MyPointF)obj; // Return true if the fields match: return((_x == p._x) && (_y == p._y)); }
private void CalcBoundingBox(PointF[] pts) { if (_pointsScreen.Length == 0) { return; } float minX = pts[0].X; float maxX = pts[0].X; float minY = pts[0].Y; float maxY = pts[0].Y; foreach (PointF pt in pts) { if (pt.X < minX) { minX = pt.X; } if (pt.Y < minY) { minY = pt.Y; } if (pt.X > maxX) { maxX = pt.X; } if (pt.Y > maxY) { maxY = pt.Y; } } _boundingBoxWorldMin = new MyPointF(minX, minY); _boundingBoxWorldMax = new MyPointF(maxX, maxY); }
public static MyPointF Multiply(MyPointF pt, float fac) { return(pt * fac); }
public static MyPointF Subtract(MyPointF pt) { return(-pt); }
public static MyPointF Negate(MyPointF pt) { return(-pt); }
public static MyPointF Plus(MyPointF pt) { return(pt); }
public static System.Drawing.PointF ToPointF(MyPointF pt) { return((System.Drawing.PointF)pt); }
public static MyPoint ToMyPoint(MyPointF pt) { return((MyPoint)pt); }
public void Render(Graphics graphics, MyPoint origin, int zoom) { float len = 5.0f; // Restore rendering hint and smoothing mode when done TextRenderingHint oldHint = graphics.TextRenderingHint; SmoothingMode oldMode = graphics.SmoothingMode; graphics.TextRenderingHint = TextRenderingHint.AntiAlias; graphics.SmoothingMode = SmoothingMode.AntiAlias; foreach (DistancePair pair in _list) { MyPointF p0 = (MyPointF)(WorldToScreen(pair.WorldPos0, zoom) - origin); MyPointF p1 = (MyPointF)(WorldToScreen(pair.WorldPos1, zoom) - origin); MyPointF dir = p1 - p0; MyPointF pp = new MyPointF(-dir.Y, dir.X).Normalize(); // perpendicular direction // Draw circle around p0 and p1 MyPointF center = p0 + dir * 0.5f; if (pair.DrawCircle) { float radius = dir.GetLength() * 0.5f; graphics.DrawEllipse(Pens.Gray, center.X - radius, center.Y - radius, radius * 2.0f, radius * 2.0f); } // Draw line between p0 and p1 graphics.DrawLine(Pens.Black, p0, p1); // Draw border line at p0 graphics.DrawLine(Pens.Black, p0 + pp * len, p0 - pp * len); // Draw border line at p1 graphics.DrawLine(Pens.Black, p1 + pp * len, p1 - pp * len); // Draw text string text = Units.Provider.DistanceString(pair.Distance); // The y-direction runs from top to bottom double angle = Math.Atan2(dir.X, -dir.Y); if (angle > Math.PI) { angle -= Math.PI; } if (angle < 0) { angle += Math.PI; } angle -= Math.PI / 2.0; float cos = (float)Math.Cos(angle); float sin = (float)Math.Sin(angle); SizeF textSize = graphics.MeasureString(text, _font); // Setup rotation matrix from angle and position graphics.Transform = new Matrix(cos, sin, -sin, cos, center.X, center.Y); graphics.DrawString(text, _font, Brushes.Black, -textSize.Width * 0.5f, -textSize.Height); graphics.ResetTransform(); } // Restore rendering hint and smoothing mode graphics.TextRenderingHint = oldHint; graphics.SmoothingMode = oldMode; }
/// <summary> /// Adds a new waypoint. /// </summary> /// <param name="point">The position of the waypoint.</param> public void AddWaypoint(MyPointF point, string text) { _waypointList.Add(new Waypoint(point, text)); }
public Waypoint(MyPointF worldPos, string text) { WorldPos = worldPos; Text = text; }
public static MyPointF Multiply(float fac, MyPointF pt) { return(fac * pt); }
public static MyPointF Add(MyPointF pt1, MyPointF pt2) { return(pt1 + pt2); }
public static MyPointF Subtract(MyPointF pt1, MyPointF pt2) { return(pt1 - pt2); }