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(); } }