public void CircleTtrTest() { var ellipse = EditUtilities.Ttr( Workspace.DrawingPlane, new SelectedEntity(new Line(Point.Origin, new Point(3, 0, 0)), new Point(1, 0, 0)), new SelectedEntity(new Line(Point.Origin, new Point(0, 3, 0)), new Point(0, 1, 0)), 1.0); Assert.Equal(1.0, ellipse.MinorAxisRatio); Assert.Equal(1.0, ellipse.MajorAxis.Length); Assert.Equal(new Point(1, 1, 0), ellipse.Center); Assert.Equal(Workspace.DrawingPlane.Normal, ellipse.Normal); }
public void CircleTtrWithCirclesTest() { // from test.dxf var el = EditUtilities.Ttr( Workspace.DrawingPlane, new SelectedEntity(new Circle(new Point(100, 0, 0), 50, Vector.ZAxis), new Point(140, 30, 0)), new SelectedEntity(new Circle(new Point(100, 100, 0), 50, Vector.ZAxis), new Point(140, 70, 0)), 30.0); Assert.Equal(1.0, el.MinorAxisRatio); Assert.Equal(30, el.MajorAxis.Length); AssertClose(new Point(162.449979983983, 50, 0), el.Center); Assert.Equal(Workspace.DrawingPlane.Normal, el.Normal); }
public async Task <bool> Execute(IWorkspace workspace, object arg) { Entity circle = null; var drawingPlane = workspace.DrawingPlane; var cen = await workspace.InputService.GetPoint(new UserDirective("Select center, [ttr], or [th]ree-point", "ttr", "th")); if (cen.Cancel) { return(false); } if (cen.HasValue) { var mode = CircleMode.Radius; while (circle == null) { switch (mode) { case CircleMode.Radius: { var rad = await workspace.InputService.GetPoint(new UserDirective("Enter radius or [d]iameter/[i]sometric", "d", "i"), (p) => { return(new IPrimitive[] { new PrimitiveLine(cen.Value, p), new PrimitiveEllipse(cen.Value, (p - cen.Value).Length, drawingPlane.Normal) }); }); if (rad.Cancel) { return(false); } if (rad.HasValue) { circle = new Circle(cen.Value, (rad.Value - cen.Value).Length, drawingPlane.Normal); } else // switch modes { if (rad.Directive == null) { return(false); } switch (rad.Directive) { case "d": mode = CircleMode.Diameter; break; case "i": mode = CircleMode.Isometric; break; } } break; } case CircleMode.Diameter: { var dia = await workspace.InputService.GetPoint(new UserDirective("Enter diameter or [r]adius/[i]sometric", "r", "i"), (p) => { return(new IPrimitive[] { new PrimitiveLine(cen.Value, p), new PrimitiveEllipse(cen.Value, (p - cen.Value).Length, drawingPlane.Normal) }); }); if (dia.Cancel) { return(false); } if (dia.HasValue) { circle = new Circle(cen.Value, (dia.Value - cen.Value).Length * 0.5, drawingPlane.Normal); } else // switch modes { if (dia.Directive == null) { return(false); } switch (dia.Directive) { case "r": mode = CircleMode.Radius; break; case "i": mode = CircleMode.Isometric; break; } } break; } case CircleMode.Isometric: { var isoRad = await workspace.InputService.GetPoint(new UserDirective("Enter isometric-radius or [r]adius/[d]iameter", "r", "d"), (p) => { return(new IPrimitive[] { new PrimitiveLine(cen.Value, p), new PrimitiveEllipse(cen.Value, Vector.SixtyDegrees * (p - cen.Value).Length *MathHelper.SqrtThreeHalves, drawingPlane.Normal, IsoMinorRatio, 0.0, 360.0) }); }); if (isoRad.Cancel) { return(false); } if (isoRad.HasValue) { circle = new Ellipse(cen.Value, Vector.SixtyDegrees * (isoRad.Value - cen.Value).Length * MathHelper.SqrtThreeHalves, IsoMinorRatio, 0.0, 360.0, drawingPlane.Normal); } else // switch modes { if (isoRad.Directive == null) { return(false); } switch (isoRad.Directive) { case "r": mode = CircleMode.Radius; break; case "d": mode = CircleMode.Diameter; break; } } break; } } } } else { switch (cen.Directive) { case "ttr": var firstEntity = await workspace.InputService.GetEntity(new UserDirective("First entity")); if (firstEntity.Cancel || !firstEntity.HasValue) { break; } var secondEntity = await workspace.InputService.GetEntity(new UserDirective("Second entity")); if (secondEntity.Cancel || !secondEntity.HasValue) { break; } var radius = await workspace.InputService.GetDistance(); var ellipse = EditUtilities.Ttr(drawingPlane, firstEntity.Value, secondEntity.Value, radius.Value); if (ellipse != null) { circle = ellipse.ToEntity(); } break; case "2": break; case "th": var first = await workspace.InputService.GetPoint(new UserDirective("First point")); if (first.Cancel || !first.HasValue) { break; } var second = await workspace.InputService.GetPoint(new UserDirective("Second point"), p => new[] { new PrimitiveLine(first.Value, p) }); if (second.Cancel || !second.HasValue) { break; } var third = await workspace.InputService.GetPoint(new UserDirective("Third point"), p => { var c = PrimitiveEllipse.ThreePointCircle(first.Value, second.Value, p); if (c == null) { return new IPrimitive[] { new PrimitiveLine(first.Value, second.Value), new PrimitiveLine(second.Value, p), new PrimitiveLine(p, first.Value) } } ; else { return new IPrimitive[] { new PrimitiveLine(first.Value, second.Value), new PrimitiveLine(second.Value, p), new PrimitiveLine(p, first.Value), c } }; }); if (third.Cancel || !third.HasValue) { break; } var circ = PrimitiveEllipse.ThreePointCircle(first.Value, second.Value, third.Value); if (circ != null) { circle = new Circle(circ.Center, circ.MajorAxis.Length, circ.Normal); } break; } } if (circle != null) { workspace.AddToCurrentLayer(circle); } return(true); }