public void Draw(Geometry.Box box, Graphics graphics, Settings settings, Geometry.Traits traits) { LocalCS cs = new LocalCS(box, graphics); Drawer drawer = new Drawer(graphics, settings.color); float rx = cs.ConvertDimensionX(Radius); float ry = cs.ConvertDimensionY(Radius); if (rx < 0 || ry < 0) { return; } if (traits.Unit == Geometry.Unit.None) { PointF c = cs.Convert(Center); if (rx == 0 || ry == 0) { drawer.DrawPoint(c.X, c.Y); } else { float x = c.X - rx; float y = c.Y - ry; float w = rx * 2; float h = ry * 2; drawer.DrawEllipse(x, y, w, h); drawer.FillEllipse(x, y, w, h); } } else // Radian, Degree { if (rx == 0 || ry == 0) { drawer.DrawPeriodicPoint(cs, Center, box, traits.Unit, settings.showDots); } else { Drawer.PeriodicDrawableNSphere pd = new Drawer.PeriodicDrawableNSphere(cs, this, traits.Unit); Geometry.Interval interval = RelativeEnvelopeLon(this, traits.Unit); drawer.DrawPeriodic(cs, box, interval, traits.Unit, pd, true, false, settings.showDots); } } }
public static bool DrawScales(Graphics graphics, Geometry.Box box, Colors colors, bool fill) { if (!box.IsValid()) { return(false); } LocalCS cs = new LocalCS(box, graphics, fill); // Aabb float min_x = cs.ConvertX(box.Min[0]); float min_y = cs.ConvertY(box.Min[1]); float max_x = cs.ConvertX(box.Max[0]); float max_y = cs.ConvertY(box.Max[1]); // pen for lines Pen penAabb = new Pen(colors.AabbColor, 1); float maxHeight = 20.0f; // font and brush for text Font font = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif), maxHeight / 2.0f); SolidBrush brushText = new SolidBrush(colors.TextColor); // Scales { float wWidth = graphics.VisibleClipBounds.Width; float wHeight = graphics.VisibleClipBounds.Height; // In CS coordinates double mi_x = cs.InverseConvertX(0); double mi_y = cs.InverseConvertY(wHeight); double ma_x = cs.InverseConvertX(wWidth); double ma_y = cs.InverseConvertY(0); double mima_x = ma_x - mi_x; double mima_y = ma_y - mi_y; // Esstimate numbers of strings for both axes double esst_x = Math.Abs(mima_x) < 10 ? mima_x / 10 : mima_x; float wStrNumX = wWidth / StringWidth(graphics, font, esst_x) / 1.25f; float wStrNumH = wHeight / StringWidth(graphics, font, 1.0) / 2.0f; // Find closest power of 10 lesser than the width and height double pd_x = AbsOuterPow10(mima_x / wStrNumX); double pd_y = AbsOuterPow10(mima_y / wStrNumH); // Find starting x and y values being the first lesser whole // values of the same magnitude, per axis double x = ScaleStart(mi_x, pd_x); double y = ScaleStart(mi_y, pd_y); // Make sure the scale starts outside the view if (x > mi_x) { x -= pd_x; } if (y > mi_y) { y -= pd_y; } // Create the string output pattern, e.g. 0.00 for previously calculated step string xStrFormat = StringFormat(pd_x); string yStrFormat = StringFormat(pd_y); float wd_x = cs.ConvertDimensionX(pd_x); int smallScaleX = SmallScaleSegments(wd_x, 10); float wd_x_step = wd_x / smallScaleX; float wd_x_limit = wd_x - wd_x_step / 2; float wd_y = cs.ConvertDimensionY(pd_y); int smallScaleY = SmallScaleSegments(wd_y, 10); float wd_y_step = wd_y / smallScaleY; float wd_y_limit = wd_y - wd_y_step / 2; // Draw horizontal scale double limit_x = ma_x + pd_x * 1.001; for (; x < limit_x; x += pd_x) { float wx = cs.ConvertX(x); // scale graphics.DrawLine(penAabb, wx, wHeight, wx, wHeight - 5); // value string xStr = Util.ToString(x, xStrFormat); SizeF xStrSize = graphics.MeasureString(xStr, font); float xStrLeft = wx - xStrSize.Width / 2; float xStrTop = wHeight - 5 - xStrSize.Height; graphics.DrawString(xStr, font, brushText, xStrLeft, xStrTop); // small scale for (float wsx = wx + wd_x_step; wsx < wx + wd_x_limit; wsx += wd_x_step) { graphics.DrawLine(penAabb, wsx, wHeight, wsx, wHeight - 3); } } // Draw vertical scale double limit_y = ma_y + pd_y * 1.001; for (; y < limit_y; y += pd_y) { float wy = cs.ConvertY(y); // scale graphics.DrawLine(penAabb, wWidth, wy, wWidth - 5, wy); // value string yStr = Util.ToString(y, yStrFormat); SizeF yStrSize = graphics.MeasureString(yStr, font); float yStrLeft = wWidth - 5 - yStrSize.Width; float yStrTop = wy - yStrSize.Height / 2; graphics.DrawString(yStr, font, brushText, yStrLeft, yStrTop); // small scale for (float wsy = wy - wd_y_step; wsy > wy - wd_y_limit; wsy -= wd_y_step) { graphics.DrawLine(penAabb, wWidth, wsy, wWidth - 3, wsy); } } } return(true); }
public void Draw(Geometry.Box box, Graphics graphics, Settings settings, Geometry.Traits traits) { LocalCS cs = new LocalCS(box, graphics); Drawer drawer = new Drawer(graphics, settings.color); double width = Dim(0); double height = Dim(1); float rw = cs.ConvertDimensionX(Math.Abs(width)); float rh = cs.ConvertDimensionY(Math.Abs(height)); if (traits.Unit == Geometry.Unit.None) { float rx = cs.ConvertX(Math.Min(Min[0], Max[0])); float ry = cs.ConvertY(Math.Max(Min[1], Max[1])); if (rw == 0 && rh == 0) { drawer.DrawPoint(rx, ry); } else if (rw == 0 || rh == 0) { drawer.DrawLine(rx, ry, rx + rw, ry + rh); } else { drawer.DrawRectangle(rx, ry, rw, rh); bool isInvalid = width < 0 || height < 0; if (!isInvalid) { drawer.FillRectangle(rx, ry, rw, rh); } else { drawer.DrawLine(rx, ry, rx + rw, ry + rh); drawer.DrawLine(rx + rw, ry, rx, ry + rh); } } } else // Radian, Degree { if (rw == 0 && rh == 0) { drawer.DrawPeriodicPoint(cs, Min, box, traits.Unit, settings.showDots); } else if (rw == 0 || rh == 0) { Geometry.Segment seg = new Geometry.Segment(Min, Max); Drawer.PeriodicDrawableBox pd = new Drawer.PeriodicDrawableBox(cs, seg, traits.Unit); Geometry.Interval interval = RelativeEnvelopeLon(seg, false, traits.Unit); drawer.DrawPeriodic(cs, box, interval, traits.Unit, pd, false, false, settings.showDots); } else { Geometry.Ring ring = new Geometry.Ring(); ring.Add(new Geometry.Point(Min[0], Min[1])); ring.Add(new Geometry.Point(Max[0], Min[1])); ring.Add(new Geometry.Point(Max[0], Max[1])); ring.Add(new Geometry.Point(Min[0], Max[1])); Drawer.PeriodicDrawableBox pd = new Drawer.PeriodicDrawableBox(cs, ring, traits.Unit); Geometry.Interval interval = RelativeEnvelopeLon(ring, true, traits.Unit); drawer.DrawPeriodic(cs, box, interval, traits.Unit, pd, true, false, settings.showDots); } } }