public void SetClearancePointTest() { var c = new Catenary(new Vector2(15, 100), 300, 50, 1.15, 770); var point = new Vector2(50.0, 95.0); c.SetClearancePoint(point); var x = point.X; var actual = new Vector2(x, c.CatenaryFunction(x)); CollectionAssert.AreEqual(point, actual, Extensions.AbsComparer(1e-3)); }
public void Render(Graphics g, RectangleF target) { Canvas canvas = GetCanvasFor(target); Style.SetGraphicsQuality(g); Catenary catenary = RulingSpan.FindCatenaryFromX(mouse_over.X); foreach (var item in RulingSpan.Spans) { RenderOne(g, canvas, item, Style, catenary == item); } if (!mouse_dn.IsZero) { catenary = RulingSpan.FindCatenaryFromX(mouse_dn.X); if (catenary != null) { double y = catenary.CatenaryFunction(mouse_dn.X); PointF A = canvas.Map(mouse_dn.X, y); PointF M = canvas.Map(mouse_dn); string text = Math.Abs(y - mouse_dn.Y).ToString("0.#"); Style.VerticalArrow(g, M.X, M.Y, A.Y, text, false); } using (Pen pen = Style.MakePen(Color.Red)) { PointF M = canvas.Map(mouse_dn); g.DrawEllipse(pen, M.X - Style.PointWidth / 2, M.Y - Style.PointWidth / 2, Style.PointWidth, Style.PointWidth); using (Font font = Style.MakeFont(SystemFonts.DialogFont)) { string text = string.Format("x:{0:0}\ny:{1:0.#}", mouse_dn.X, mouse_dn.Y); StringFormat sf = new StringFormat(); SizeF sz = g.MeasureString(text, font, M, sf); g.FillRectangle(Brushes.White, M.X - sz.Width - 4, M.Y - 4, sz.Width + 2, sz.Height + 2); g.DrawString(text, font, Brushes.Red, M.X - sz.Width - 2, M.Y - 2, sf); } } } }