public void PlotGeoElementStartpointisend() { Point sp = new Point(0, 0); ULine l = new ULine(new Point(1, 1)); USolidBrush sb = new USolidBrush() { color = new Color(1, 1, 1, 1) }; mockedDraw.PlotGeoElement(ref sp, l, sb, false); Assert.AreEqual(sp.X, 1); Assert.AreEqual(sp.Y, 1); buf.ResetBuffer(); var a = new UArc(new Point(5, 4), new Size(3, 3), true, false, 12f); mockedDraw.PlotGeoElement(ref sp, a, sb, false); Assert.AreEqual(sp.X, 5); Assert.AreEqual(sp.Y, 4); buf.ResetBuffer(); }
// FIXME another example of type switching. Cant put d2d code on other side of bridge in eg UGeometryBase abstraction // and also, using a factory to create the UGeometryBase will make d2d specific versions. // IDEA This is possible: Use factory (DI?) and check the Uxxx instances when passed to this type of class, and recreate // a portion of the Uxxx if it doesnt match D2D? Factory could be configured for d2d/ogl etc. This links in with cacheing // code too? Not sure if this will static compile :/ thats kinda the point... we'd need the Uxxx.ICreateStuff to be a specific // D2D interface...could subclass... would check if(ICreateStuff is D2DCreator) as d2dcreator else Icreatestuff=new d2dcreator... void AppendGeometry(ref GraphicsPath path, UGeometryBase geo, NoForms.Common.Point start) // ref GraphicsPath will allow us to recreate it if we want with new. { if (geo is UArcBase) { System.Drawing.PointF[] pts; if (geo is UArc) { UArc arc = geo as UArc; pts = (geo.Retreive <SDGDraw>(() => { var elInput = new GeometryLib.Ellipse_Input(start.X, start.Y, arc.endPoint.X, arc.endPoint.Y, arc.arcSize.width, arc.arcSize.height, arc.rotation); var elSolution = new List <GeometryLib.Ellipse_Output>(GeometryLib.Ellipse.Get_X0Y0(elInput)).ToArray(); GeometryLib.Ellipse.SampleArc(elInput, elSolution, arc.reflex, arc.sweepClockwise, arc.resolution, out pts); return(new disParr(pts)); }) as disParr).pts; } //else if (geo is UEasyArc) //{ // var arc = geo as UEasyArc; // pts = (geo.Retreive<SDGDraw>(() => // { // return new disParr(new List<System.Drawing.PointF>(EllipseLib.EasyEllipse.Generate(new EllipseLib.EasyEllipse.EasyEllipseInput() // { // rotation = arc.rotation, // start_x = start.X, // start_y = start.Y, // rx = arc.arcSize.width, // ry = arc.arcSize.height, // t1 = arc.startAngle, // t2 = arc.endAngle, // resolution = arc.resolution // })).ToArray()); // }) as disParr).pts; //} else { throw new NotImplementedException(); } // clone the data List <PointF> opts = new List <PointF>(path.PointCount > 0 ? path.PathPoints : new PointF[0]); List <byte> otyps = new List <byte>(path.PointCount > 0 ? path.PathTypes : new byte[0]); // do the types if (otyps.Count == 0 || otyps[otyps.Count - 1] != (byte)PathPointType.Start) { otyps.Add((byte)PathPointType.Start); opts.Add(SDGTr.trF(start)); } for (int i = 0; i < pts.Length; i++) { otyps.Add((byte)PathPointType.Line); // try to interpolate a bit? } // append new data opts.AddRange(pts); // Replace the path via reference path = new GraphicsPath(opts.ToArray(), otyps.ToArray(), path.FillMode); } else if (geo is ULine) { ULine line = geo as ULine; path.AddLine(SDGTr.trF(start), SDGTr.trF(line.endPoint)); } else if (geo is UBeizer) { UBeizer beizer = geo as UBeizer; path.AddBezier(SDGTr.trF(start), SDGTr.trF(beizer.controlPoint1), SDGTr.trF(beizer.controlPoint2), SDGTr.trF(beizer.endPoint)); } else { throw new NotImplementedException(); } }
// FIXME another example of type switching. Cant put d2d code on other side of bridge in eg UGeometryBase abstraction // and also, using a factory to create the UGeometryBase will make d2d specific versions. // IDEA This is possible: Use factory (DI?) and check the Uxxx instances when passed to this type of class, and recreate // a portion of the Uxxx if it doesnt match D2D? Factory could be configured for d2d/ogl etc. This links in with cacheing // code too? Not sure if this will static compile :/ thats kinda the point... we'd need the Uxxx.ICreateStuff to be a specific // D2D interface...could subclass... would check if(ICreateStuff is D2DCreator) as d2dcreator else Icreatestuff=new d2dcreator... void AppendGeometry(GeometrySink sink, UGeometryBase geo) { if (geo is UArc) { UArc arc = geo as UArc; sink.AddArc(new ArcSegment() { SweepDirection = arc.sweepClockwise ? SweepDirection.Clockwise : SweepDirection.CounterClockwise, RotationAngle = -arc.rotation, ArcSize = arc.reflex ? ArcSize.Large : ArcSize.Small, Point = D2DTr.tr(arc.endPoint), Size = D2DTr.tr(arc.arcSize) }); } //else if (geo is UEasyArc) //{ // UEasyArc arc = geo as UEasyArc; // var eco = geo.Retreive<D2DDraw>(() => // { // var cp = gcpt(); // return EllipseLib.EasyEllipse.ConvertEndPoint(new EllipseLib.EasyEllipse.EasyEllipseInput() // { // resolution = arc.resolution, // t1 = arc.startAngle, // t2 = arc.endAngle, // rx = arc.arcSize.width, // ry = arc.arcSize.height, // rotation = arc.rotation, // start_x = cp.X, // start_y = cp.Y // }); // }) as EllipseLib.EasyEllipse.EECOut; // sink.AddArc(new ArcSegment() // { // SweepDirection = eco.clockwise ? SweepDirection.Clockwise : SweepDirection.CounterClockwise, // RotationAngle = -arc.rotation, // ArcSize = eco.reflex ? ArcSize.Large : ArcSize.Small, // Point = new SharpDXLib.DrawingPointF(eco.x, eco.y), // Size = D2DTr.tr(arc.arcSize) // }); //} else if (geo is ULine) { ULine line = geo as ULine; sink.AddLine(D2DTr.tr(line.endPoint)); } else if (geo is UBeizer) { UBeizer beizer = geo as UBeizer; sink.AddBezier(new BezierSegment() { Point1 = D2DTr.tr(beizer.controlPoint1), Point2 = D2DTr.tr(beizer.controlPoint2), Point3 = D2DTr.tr(beizer.endPoint) }); } else { throw new NotImplementedException(); } }
public void PlotGeoElement(ref Point start, UGeometryBase g, UBrush b, bool doublepoints) { setVC(b, start.X, start.Y); System.Drawing.PointF[] pts = new System.Drawing.PointF[0]; var lst = start; if (g is ULine) { var l = g as ULine; pts = new System.Drawing.PointF[] { new System.Drawing.PointF(l.endPoint.X, l.endPoint.Y) }; } else if (g is UBeizer) { UBeizer bez = g as UBeizer; var p1 = new System.Drawing.PointF(start.X, start.Y); var p2 = new System.Drawing.PointF(bez.controlPoint1.X, bez.controlPoint1.Y); var p3 = new System.Drawing.PointF(bez.controlPoint2.X, bez.controlPoint2.Y); var p4 = new System.Drawing.PointF(bez.endPoint.X, bez.endPoint.Y); pts = (g.Retreive <OTKDraw>(() => new disParr(Common.Bezier.Get2D(p1, p2, p3, p4, bez.resolution))) as disParr).pts; } else if (g is UArc) { UArc arc = g as UArc; pts = (g.Retreive <OTKDraw>(() => { var elInput = new GeometryLib.Ellipse_Input(lst.X, lst.Y, arc.endPoint.X, arc.endPoint.Y, arc.arcSize.width, arc.arcSize.height, arc.rotation); var elSolution = new List <GeometryLib.Ellipse_Output>(GeometryLib.Ellipse.Get_X0Y0(elInput)).ToArray(); GeometryLib.Ellipse.SampleArc(elInput, elSolution, arc.reflex, arc.sweepClockwise, arc.resolution, out pts); return(new disParr(pts)); }) as disParr).pts; } //else if (g is UEasyArc) //{ // var arc = g as UEasyArc; // pts = (g.Retreive<OTKDraw>(() => // { // return new disParr(new List<System.Drawing.PointF>(EllipseLib.EasyEllipse.Generate(new EllipseLib.EasyEllipse.EasyEllipseInput() // { // rotation = arc.rotation, // start_x = lst.X, // start_y = lst.Y, // rx = arc.arcSize.width, // ry = arc.arcSize.height, // t1 = arc.startAngle, // t2 = arc.endAngle, // resolution = arc.resolution // })).ToArray()); // }) as disParr).pts; //} else { throw new NotImplementedException(); } Point?sp = null; int i = 0; for (i = 0; i < pts.Length - 1; i++) { var p = pts[i]; sp = new Point(p.X, p.Y); setVC(b, p.X, p.Y); // end last line here if (doublepoints) { setVC(b, p.X, p.Y); // start of new line } } if (pts.Length > 0) { sp = new Point(pts[i].X, pts[i].Y); setVC(b, pts[i].X, pts[i].Y); // end last line here } if (sp != null) { start.X = sp.Value.X; start.Y = sp.Value.Y; } }