public override void Draw2D(IMarkGeometryVisualizer2D view, bool shouldShowVertex) { // TODO : please review/optimize this solution // Is it a good idea to use Parallels here? //// stash the current offsets //view.PushOffset(); //view.AddOffset(Offset); int n = GeometricArithmeticModule.Max <int>(new int[] { Points.Count, Arcs.Count, Circles.Count, Lines.Count, Paths.Count }); for (int i = 0; i < n; i++) { if (i < Points.Count) { view.Draw2D(Points[i]); } if (i < Arcs.Count) { view.Draw2D(Arcs[i], shouldShowVertex); } if (i < Circles.Count) { view.Draw2D(Circles[i], shouldShowVertex); } if (i < Lines.Count) { view.Draw2D(Lines[i], shouldShowVertex); } if (i < Paths.Count) { view.Draw2D(Paths[i], shouldShowVertex); } } //// revert to previous offsets //view.PopOffset(); }
public override void SetExtents() { Perimeter = 0; if (Points.Count > 0) { Extents.MinX = Double.MaxValue; Extents.MaxX = Double.MinValue; Extents.MinY = Double.MaxValue; Extents.MaxY = Double.MinValue; Extents.MinZ = Double.MaxValue; Extents.MaxZ = Double.MinValue; for (int i = 0; i < Points.Count; i++) { Extents.MinX = GeometricArithmeticModule.Min(Extents.MinX, Points[i].X); Extents.MaxX = GeometricArithmeticModule.Max(Extents.MaxX, Points[i].X); Extents.MinY = GeometricArithmeticModule.Min(Extents.MinY, Points[i].Y); Extents.MaxY = GeometricArithmeticModule.Max(Extents.MaxY, Points[i].Y); Extents.MinZ = GeometricArithmeticModule.Min(Extents.MinZ, Points[i].Z); Extents.MaxZ = GeometricArithmeticModule.Max(Extents.MaxZ, Points[i].Z); if (i < Points.Count - 1) { Perimeter += GeometricArithmeticModule.ABSMeasure(Points[i], Points[i + 1]); } } } else { Extents.MinX = 0; Extents.MaxX = 0; Extents.MinY = 0; Extents.MaxY = 0; Extents.MinZ = 0; Extents.MaxZ = 0; } }
private void Draw(Graphics graphics, IMarkGeometry geometry, bool showVertices) { if (geometry is MarkGeometryPoint point) { var pointRadius = 0.5 * DefaultPointWidth; graphics.FillEllipse( point.Fill == null ? DefaultPointColor : ToSolidBrush((Color)point.Fill), (float)(point.X - pointRadius), (float)(point.Y - pointRadius), DefaultPointWidth, DefaultPointWidth ); } else if (geometry is MarkGeometryLine line) { graphics.DrawLine( line.Stroke == null ? DefaultStroke : new Pen((Color)line.Stroke, DefaultStrokeWidth), (float)line.StartPoint.X, (float)line.StartPoint.Y, (float)line.EndPoint.X, (float)line.EndPoint.Y ); if (showVertices) { Draw(graphics, line.StartPoint, false); Draw(graphics, line.EndPoint, false); } } else if (geometry is MarkGeometryCircle circle) { graphics.FillEllipse( circle.Fill == null ? DefaultFillColor : ToSolidBrush((Color)circle.Fill), (float)circle.Extents.MinX, (float)circle.Extents.MinY, (float)(2 * circle.Radius), (float)(2 * circle.Radius) ); graphics.DrawEllipse( circle.Stroke == null ? DefaultStroke : new Pen((Color)circle.Stroke, DefaultStrokeWidth), (float)circle.Extents.MinX, (float)circle.Extents.MinY, (float)(2 * circle.Radius), (float)(2 * circle.Radius) ); } else if (geometry is MarkGeometryArc arc) { Draw(graphics, new MarkGeometryPath(arc), showVertices); //Draw(graphics, arc.Extents.Boundary, showVertices); //// TODO : Use filled pie for filled arc //graphics.DrawArc( // arc.Fill == null ? DefaultStroke : new Pen((Color)arc.Stroke, DefaultStrokeWidth), // (float)arc.Extents.MinX, // (float)arc.Extents.MinY, // (float)(2*arc.Radius), // (float)(2*arc.Radius), // (float)GeometricArithmeticModule.ToDegrees(arc.StartAngle), // convert from radians to degrees // (float)GeometricArithmeticModule.ToDegrees(arc.Angle) //); //if (showVertices) //{ // Draw(graphics, arc.StartPoint, false); // Draw(graphics, arc.EndPoint, false); //} } else if (geometry is MarkGeometryPath path) { var points = ((List <PointF>)path).ToArray(); if (path.IsClosed) { graphics.FillPolygon( path.Fill == null ? DefaultFillColor : ToSolidBrush((Color)path.Fill), points ); } graphics.DrawLines( path.Stroke == null ? DefaultStroke : new Pen((Color)path.Stroke, DefaultStrokeWidth), points ); if (showVertices) { for (int i = 0; i < path.Points.Count; i++) { Draw(graphics, path.Points[i], false); } } } else if (geometry is MarkGeometriesWrapper wrapper) { int n = GeometricArithmeticModule.Max <int>(new int[] { wrapper.Points.Count, wrapper.Arcs.Count, wrapper.Circles.Count, wrapper.Lines.Count, wrapper.Paths.Count }); for (int i = 0; i < n; i++) { if (i < wrapper.Points.Count) { Draw(graphics, wrapper.Points[i], showVertices); } if (i < wrapper.Arcs.Count) { Draw(graphics, wrapper.Arcs[i], showVertices); } if (i < wrapper.Circles.Count) { Draw(graphics, wrapper.Circles[i], showVertices); } if (i < wrapper.Lines.Count) { Draw(graphics, wrapper.Lines[i], showVertices); } if (i < wrapper.Paths.Count) { Draw(graphics, wrapper.Paths[i], showVertices); } } } else if (geometry is MarkGeometryTree tree) { foreach (var element in tree.Flatten()) { Draw(graphics, element, showVertices); } } }
public override void SetExtents() { Extents.MinX = double.MaxValue; Extents.MaxX = double.MinValue; Extents.MinY = double.MaxValue; Extents.MaxY = double.MinValue; Extents.MinZ = double.MaxValue; Extents.MaxZ = double.MinValue; int[] ns = { Points.Count(), Arcs.Count(), Circles.Count(), Lines.Count(), Paths.Count() }; int n = GeometricArithmeticModule.Max <int>(ns); for (int i = 0; i < n; i++) { if (i < Points.Count()) { Extents.MaxX = Math.Max(Extents.MaxX, Points[i].Extents.MaxX); Extents.MaxY = Math.Max(Extents.MaxY, Points[i].Extents.MaxY); Extents.MaxZ = Math.Max(Extents.MaxZ, Points[i].Extents.MaxZ); Extents.MinX = Math.Min(Extents.MinX, Points[i].Extents.MinX); Extents.MinY = Math.Min(Extents.MinY, Points[i].Extents.MinY); Extents.MinZ = Math.Min(Extents.MinZ, Points[i].Extents.MinZ); } if (i < Arcs.Count()) { Extents.MaxX = Math.Max(Extents.MaxX, Arcs[i].Extents.MaxX); Extents.MaxY = Math.Max(Extents.MaxY, Arcs[i].Extents.MaxY); Extents.MaxZ = Math.Max(Extents.MaxZ, Arcs[i].Extents.MaxZ); Extents.MinX = Math.Min(Extents.MinX, Arcs[i].Extents.MinX); Extents.MinY = Math.Min(Extents.MinY, Arcs[i].Extents.MinY); Extents.MinZ = Math.Min(Extents.MinZ, Arcs[i].Extents.MinZ); } if (i < Circles.Count()) { Extents.MaxX = Math.Max(Extents.MaxX, Circles[i].Extents.MaxX); Extents.MaxY = Math.Max(Extents.MaxY, Circles[i].Extents.MaxY); Extents.MaxZ = Math.Max(Extents.MaxZ, Circles[i].Extents.MaxZ); Extents.MinX = Math.Min(Extents.MinX, Circles[i].Extents.MinX); Extents.MinY = Math.Min(Extents.MinY, Circles[i].Extents.MinY); Extents.MinZ = Math.Min(Extents.MinZ, Circles[i].Extents.MinZ); } if (i < Lines.Count()) { Extents.MaxX = Math.Max(Extents.MaxX, Lines[i].Extents.MaxX); Extents.MaxY = Math.Max(Extents.MaxY, Lines[i].Extents.MaxY); Extents.MaxZ = Math.Max(Extents.MaxZ, Lines[i].Extents.MaxZ); Extents.MinX = Math.Min(Extents.MinX, Lines[i].Extents.MinX); Extents.MinY = Math.Min(Extents.MinY, Lines[i].Extents.MinY); Extents.MinZ = Math.Min(Extents.MinZ, Lines[i].Extents.MinZ); } if (i < Paths.Count()) { Extents.MaxX = Math.Max(Extents.MaxX, Paths[i].Extents.MaxX); Extents.MaxY = Math.Max(Extents.MaxY, Paths[i].Extents.MaxY); Extents.MaxZ = Math.Max(Extents.MaxZ, Paths[i].Extents.MaxZ); Extents.MinX = Math.Min(Extents.MinX, Paths[i].Extents.MinX); Extents.MinY = Math.Min(Extents.MinY, Paths[i].Extents.MinY); Extents.MinZ = Math.Min(Extents.MinZ, Paths[i].Extents.MinZ); } } GridWidth = Extents.MaxX - Extents.MinX; GridHeight = Extents.MaxY - Extents.MinY; GridDepth = Extents.MaxZ - Extents.MinZ; Origin = new MarkGeometryPoint( Extents.MinX + (0.5 * GridWidth), Extents.MinY + (0.5 * GridHeight), Extents.MinZ + (0.5 * GridDepth) ); }