static ICurve ScaleCurveToDescribeAroundRectangle(ICurve curve, double width, double height) { //create the rectangle curve Curve rect = new Curve(); Curve.AddLineSegment(rect, -width / 2, height / 2, width / 2, height / 2); Curve.ContinueWithLineSegment(rect, width / 2, -height / 2); Curve.ContinueWithLineSegment(rect, -width / 2, -height / 2); Curve.CloseCurve(rect); //find scale big enough that the scaled curve will not intersect the rectangle width, height double upScale = Math.Max(width / curve.BBox.Width, height / curve.BBox.Height) * 2; const int numberOfTries = 10; int i; for (i = 0; i < numberOfTries; i++) { if (CurvesIntersect(rect, ScaledCurve(upScale, curve))) { upScale *= 2; } else { break; } } if (i == numberOfTries) { return(null); } double downScale = Math.Min(width / curve.BBox.Width, height / curve.BBox.Height) / 2; System.Diagnostics.Debug.Assert(!CurvesIntersect(rect, ScaledCurve(downScale, curve))); //run binary search to find the right scale const double eps = 0.01; System.Diagnostics.Debug.Assert(upScale > downScale); while (upScale - downScale > eps) { double s = (upScale + downScale) / 2; if (CurvesIntersect(rect, ScaledCurve(s, curve))) { downScale = s; } else { upScale = s; } } return(ScaledCurve((downScale + upScale) / 2, curve)); }
internal ICurve CreateBoundary() { double w = Width / 2; double h = Height / 2; Curve curve = new Curve(); Curve.AddLineSegment(curve, Center.X - w, Center.Y - h, Center.X - w, Center.Y + h); Curve.ContinueWithLineSegment(curve, Center.X + w, Center.Y + h); Curve.ContinueWithLineSegment(curve, Center.X + w, Center.Y - h); Curve.CloseCurve(curve); return(curve); }
static ICurve CreateLabelBoundary(GeomLabel label) { double w = label.Width / 2; double h = label.Height / 2; Curve curve = new Curve(); Curve.AddLineSegment(curve, label.Center.X - w, label.Center.Y - h, label.Center.X - w, label.Center.Y + h); Curve.ContinueWithLineSegment(curve, label.Center.X + w, label.Center.Y + h); Curve.ContinueWithLineSegment(curve, label.Center.X + w, label.Center.Y - h); Curve.CloseCurve(curve); return(curve); }
internal static ICurve FitArcsIntoCorners(double radius, Point[] polyline) { IEnumerable <Ellipse> ellipses = GetFittedArcSegs(radius, polyline); var curve = new Curve(polyline.Length); Ellipse prevEllipse = null; foreach (Ellipse ellipse in ellipses) { bool ellipseIsAlmostCurve = EllipseIsAlmostLineSegment(ellipse); if (prevEllipse != null) { if (ellipseIsAlmostCurve) { Curve.ContinueWithLineSegment(curve, CornerPoint(ellipse)); } else { Curve.ContinueWithLineSegment(curve, ellipse.Start); curve.AddSegment(ellipse); } } else { if (ellipseIsAlmostCurve) { Curve.AddLineSegment(curve, polyline[0], CornerPoint(ellipse)); } else { Curve.AddLineSegment(curve, polyline[0], ellipse.Start); curve.AddSegment(ellipse); } } prevEllipse = ellipse; } if (curve.Segments.Count > 0) { Curve.ContinueWithLineSegment(curve, polyline[polyline.Length - 1]); } else { Curve.AddLineSegment(curve, polyline[0], polyline[polyline.Length - 1]); } return(curve); }
Curve CreatePolyTest() { Curve c = new Curve(); IEnumerator <Point> e = new PointNodesList(this.headSite); e.MoveNext(); Point p = e.Current; while (e.MoveNext()) { Curve.AddLineSegment(c, p, e.Current); p = e.Current; } return(c); }
Curve CreateCurveFromPolyline(Polyline poly) { Curve c = new Curve(); foreach (PolylinePoint p in poly.PolylinePoints) { if (p.Next != null) { Curve.AddLineSegment(c, p.Point, p.Next.Point); } } if (poly.Closed) { Curve.AddLineSegment(c, c.End, poly.Start); } return(c); }
/// <summary> /// Creates a curve by using the underlying polyline /// </summary> /// <returns></returns> public Curve CreateCurve() { Curve curve = new Curve(); Site a = HeadSite; //the corner start Site b; //the corner origin Site c; //the corner other end while (Curve.FindCorner(a, out b, out c)) { CubicBezierSegment bezierSeg = CreateBezierSegOnSite(b); if (curve.Segments.Count == 0) { if (!ApproximateComparer.Close(a.Point, bezierSeg.Start)) { Curve.AddLineSegment(curve, a.Point, bezierSeg.Start); } } else if (!ApproximateComparer.Close(curve.End, bezierSeg.Start)) { Curve.ContinueWithLineSegment(curve, bezierSeg.Start); } curve.AddSegment(bezierSeg); a = b; } System.Diagnostics.Debug.Assert(a.Next.Next == null); if (curve.Segments.Count == 0) { if (!ApproximateComparer.Close(a.Point, a.Next.Point)) { Curve.AddLineSegment(curve, a.Point, a.Next.Point); } else { double w = 5; curve.Segments.Add(new CubicBezierSegment(a.Point, a.Point + new Point(w, w), a.Point + new Point(-w, w), b.Point)); } } else if (!ApproximateComparer.Close(curve.End, a.Next.Point)) { Curve.ContinueWithLineSegment(curve, a.Next.Point); } return(curve); }
public static ICurve GetNodeBoundary(Microsoft.Msagl.Drawing.Node n) { double cell = s_random.Next(50, 80); double ecc = (((double)s_random.Next(20, 100) / 100.00) * cell); switch (n.Id.Split()[0]) { case "Rhombus": return(CurveFactory.CreateDiamond(cell / 2.0, ecc / 2.0, new Microsoft.Msagl.Core.Geometry.Point())); case "Circle": return(CurveFactory.CreateCircle(cell / 2.0, new Microsoft.Msagl.Core.Geometry.Point())); case "Ellipse": return(CurveFactory.CreateEllipse(cell / 2.0, ecc / 2.0, new Microsoft.Msagl.Core.Geometry.Point())); case "Rectangle": return(CurveFactory.CreateRectangle(cell, ecc, new Point())); case "Parallelogram": { ICurve baseRect = CurveFactory.CreateRectangle(cell, ecc, new Point()); return(baseRect.Transform(new PlaneTransformation(1, (double)s_random.Next(0, 100) / 100.00, 0, 0, 1, 0))); } case "CurvedRectangle": return(CurveFactory.CreateRectangleWithRoundedCorners(cell * 2, ecc, ecc / 4, ecc / 4, new Microsoft.Msagl.Core.Geometry.Point())); case "Process": { Curve curve = (Curve)CurveFactory.CreateRectangle(cell * 2, ecc, new Microsoft.Msagl.Core.Geometry.Point()); Curve curveInner = (Curve)CurveFactory.CreateRectangle(cell * 1.5, ecc, new Microsoft.Msagl.Core.Geometry.Point()); Curve.CloseCurve(curve); Curve.CloseCurve(curveInner); Curve.AddLineSegment(curve, curve.Start, curveInner.Start); curve.AddSegment(curveInner); return(curve); } case "ElongatedEllipse": { var curve = new Curve(); double x = cell; double y = ecc; double r = x / 2; curve.AddSegment(new Ellipse(1.5 * Math.PI, 2.5 * Math.PI, new Point(r, 0), new Point(0, y), new Point(x, 0))); curve.AddSegment(new LineSegment(curve.End, new Point(-1 * x, y))); curve.AddSegment(new Ellipse(0.5 * Math.PI, 1.5 * Math.PI, new Point(r, 0), new Point(0, y), new Point(-1 * x, 0))); Curve.CloseCurve(curve); return(curve); } case "Database": { var curve = new Curve(); double x = ecc; double y = cell; double r = y / 2; curve.AddSegment(new Ellipse(new Point(x, 0), new Point(0, r), new Point(0, 0))); curve.AddSegment(new Ellipse(0, Math.PI, new Point(x, 0), new Point(0, r), new Point(0, 0))); curve.AddSegment(new LineSegment(curve.End, new Point(-1 * x, -1 * y))); curve.AddSegment(new LineSegment(curve.End, new Point(x, -1 * y))); Curve.CloseCurve(curve); return(curve); } } throw new Exception("unrecognised shape type"); }