From c89d00ab09e3f34cbf4bda8d1b33862703967498 Mon Sep 17 00:00:00 2001 From: Lev Nachmanson Date: Wed, 18 Sep 2024 11:53:03 -0700 Subject: [PATCH] revert the last commit Signed-off-by: Lev Nachmanson --- "E\357\200\272" | 396 ------------------ .../MSAGL/Miscellaneous/LayoutHelpers.cs | 2 +- GraphLayout/MSAGL/Routing/SplineRouter.cs | 8 +- 3 files changed, 3 insertions(+), 403 deletions(-) delete mode 100644 "E\357\200\272" diff --git "a/E\357\200\272" "b/E\357\200\272" deleted file mode 100644 index e83a7ea1..00000000 --- "a/E\357\200\272" +++ /dev/null @@ -1,396 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Msagl.Core.Layout; - -namespace Microsoft.Msagl.Core.Geometry.Curves { - /// - /// the helper class to create curves - /// - public sealed class CurveFactory { - CurveFactory() { } - /// - /// Creates an ellipse by the length of axes and the center - /// - /// - /// - /// - /// - static public ICurve CreateEllipse(double radiusInXDirection, double radiusInYDirection, Point center) { - return new Ellipse(radiusInXDirection, radiusInYDirection, center); - } - - /// - /// Creates an ellipse by the length of axes and the center - /// - /// - /// - /// - static public ICurve CreateCircle(double radius, Point center) { - return new Ellipse(radius, radius, center); - } - - /// - /// Create a rectangle with smoothed corners - /// - /// the rectangle width - /// the rectangle height - /// the length of the x axis of the corner smoothing ellipse - /// the length of the y axis of the corner smoothing ellipse - /// the rectangle center - /// - static public ICurve CreateRectangleWithRoundedCorners(double width, double height, double radiusInXDirection, double radiusInYDirection, Point center) { - var box = new Rectangle(center.X - width / 2, center.Y - height / 2, center.X + width / 2, center.Y + height / 2); - return new RoundedRect(box, radiusInXDirection, radiusInYDirection); - } - - /// - /// Create in the specified curve, a rectangle with smoothed corners - /// - /// - /// the rectangle width - /// the rectangle height - /// the length of the x axis of the corner smoothing ellipse - /// the length of the y axis of the corner smoothing ellipse - /// the rectangle center - /// - static internal void CreateRectangleWithRoundedCorners(Curve c, double width, double height, double radiusInXDirection, double radiusInYDirection, Point center) { - if (radiusInXDirection == 0 || radiusInYDirection == 0) { - CreateRectangle(c, width, height, center); - return; - } - double w = width / 2; - if (radiusInXDirection > w / 2) - radiusInXDirection = w / 2; - double h = height / 2; - if (radiusInYDirection > h / 2) - radiusInYDirection = h / 2; - double x = center.X; - double y = center.Y; - double ox = w - radiusInXDirection; - double oy = h - radiusInYDirection; - double top = y + h; - double bottom = y - h; - double left = x - w; - double right = x + w; - //ellipse's axises - Point a = new Point(radiusInXDirection, 0); - Point b = new Point(0, radiusInYDirection); - - c.IncreaseSegmentCapacity(8); - - if (ox > 0) - c.AddSegment(new LineSegment(new Point(x - ox, bottom), new Point(x + ox, bottom))); - c.AddSegment(new Ellipse(1.5 * Math.PI, 2 * Math.PI, a, b, x + ox, y - oy)); - if (oy > 0) - c.AddSegment(new LineSegment(new Point(right, y - oy), new Point(right, y + oy))); - c.AddSegment(new Ellipse(0, 0.5 * Math.PI, a, b, x + ox, y + oy)); - if (ox > 0) - c.AddSegment(new LineSegment(new Point(x + ox, top), new Point(x - ox, top))); - c.AddSegment(new Ellipse(0.5 * Math.PI, Math.PI, a, b, x - ox, y + oy)); - if (oy > 0) - c.AddSegment(new LineSegment(new Point(left, y + oy), new Point(left, y - oy))); - c.AddSegment(new Ellipse(Math.PI, 1.5 * Math.PI, a, b, x - ox, y - oy)); - } - - /// - /// create a box of the given width and height at center. - /// - /// - /// - /// - /// - static public ICurve CreateRectangle(double width, double height, Point center) { - double w = width / 2; - double h = height / 2; - double x = center.X; - double y = center.Y; - Curve c = new Curve(); - Point[] p = new Point[] { new Point(x - w, y - h), new Point(x + w, y - h), new Point(x + w, y + h), new Point(x - w, y + h) }; - c.AddSegs(new LineSegment(p[0], p[1]), new LineSegment(p[1], p[2]), new LineSegment(p[2], p[3]), new LineSegment(p[3], p[0])); - return c; - } - - /// - /// create a box of the given width and height at center. - /// - /// - /// - /// - /// - /// - static internal void CreateRectangle(Curve c, double width, double height, Point center) { - double w = width / 2; - double h = height / 2; - double x = center.X; - double y = center.Y; - Point[] p = new Point[] { new Point(x - w, y - h), new Point(x + w, y - h), new Point(x + w, y + h), new Point(x - w, y + h) }; - c.AddSegs(new LineSegment(p[0], p[1]), new LineSegment(p[1], p[2]), new LineSegment(p[2], p[3]), new LineSegment(p[3], p[0])); - } - - /// - /// Create a polyline curve for the given rectangle - /// - /// - /// - static public ICurve CreateRectangle(Rectangle rectangle) { - return CreateRectangle(rectangle.Width, rectangle.Height, rectangle.Center); - } - - /// - /// Creates a curve resembling a house large enough to inscribe within it a rectangle of the - /// given width and height at center. - /// - /// the house width - the rectangle width - /// the height of the inscribed rectangle; the house will be half-again higher - /// the center of the inscribed rectangle - /// - static public ICurve CreateHouse(double width, double height, Point center) { - double w = width / 2; - double h = height / 2; - double x = center.X; - double y = center.Y; - Curve c = new Curve(4); - Curve.AddLineSegment(c, x - w, y - h, x + w, y - h); - Curve.ContinueWithLineSegment(c, x + w, y + h); - Curve.ContinueWithLineSegment(c, x, y + 2 * h); - Curve.ContinueWithLineSegment(c, x - w, y + h); - Curve.CloseCurve(c); - return c; - } - - /// - /// Creates curve resembling a house within the rectangle formed by width and height at center - /// (if the rectangle is a square, the house has the shape of home plate in baseball). - /// - /// the bounding rectangle width - /// the bounding rectangle height - /// the bounding rectangle center - /// - static public ICurve CreateInteriorHouse(double width, double height, Point center) { - double w = width / 2; - double h = height / 2; - double x = center.X; - double y = center.Y; - Curve c = new Curve(4); - Curve.AddLineSegment(c, x - w, y - h, x + w, y - h); - Curve.ContinueWithLineSegment(c, x + w, y); - Curve.ContinueWithLineSegment(c, x, y + h); - Curve.ContinueWithLineSegment(c, x - w, y); - Curve.CloseCurve(c); - return c; - } - - /// - /// Creates a curve resembling an inverted house - /// - /// the house width - /// the house heigth - /// the house center - /// - static public ICurve CreateInvertedHouse(double width, double height, Point center) { - ICurve shape = CreateHouse(width, height, center); - return RotateCurveAroundCenterByDegree(shape, center, 180.0); - } - - /// - /// Creates a curve resembling a diamond large enough to inscribe within it a rectangle of the - /// given width and height at center. - /// - /// the width of the inscribed rectangle - /// the height of the inscribed rectangle - /// the diamond center - /// - static public ICurve CreateDiamond(double width, double height, Point center) { - double w = width; - double h = height; - double x = center.X; - double y = center.Y; - Curve c = new Curve(); - Point[] p = new Point[] { new Point(x, y - h), new Point(x + w, y), new Point(x, y + h), new Point(x - w, y) }; - c.AddSegs(new LineSegment(p[0], p[1]), new LineSegment(p[1], p[2]), new LineSegment(p[2], p[3]), new LineSegment(p[3], p[0])); - return c; - } - - /// - /// Creates a curve resembling a diamond within the rectangle formed by width and height at center. - /// - /// the bounding rectangle width - /// the bounding rectangle height - /// the bounding rectangle center - /// - static public ICurve CreateInteriorDiamond(double width, double height, Point center) { - return CreateDiamond(width / 2, height / 2, center); - } - - // This adds the padding to the edges around the inscribed rectangle of an octagon. - static double octagonPad = 1.0 / 4; - - /// - /// Creates a curve of the form of an octagon large enough to inscribe a rectangle - /// of width and height around center. - /// - /// the inscribed rectangle width - /// the inscribed rectangle height - /// the inscribed rectangle (and octagon) center - /// - public static Polyline CreateOctagon(double width, double height, Point center) { - double w = width / 2; - double h = height / 2; - Point[] ps = new Point[8]; - - ps[7] = new Point(w + (octagonPad * w), h - (h * octagonPad)); - ps[4] = new Point(-ps[7].X, ps[7].Y); - ps[3] = new Point(ps[4].X, -ps[4].Y); - ps[0] = new Point(ps[7].X, -ps[7].Y); - - // Pad out vertically - ps[6] = new Point(w - (w * octagonPad), h + (h * octagonPad)); - ps[5] = new Point(-ps[6].X, ps[6].Y); - ps[1] = new Point(ps[6].X, -ps[6].Y); - ps[2] = new Point(ps[5].X, -ps[5].Y); - - for (int i = 0; i < 8; i++) { - ps[i] += center; - } - - Polyline polyline = new Polyline(ps) { Closed = true }; - return polyline; - } - - /// - /// Creates a curve of the form of an hexagon large enough to inscribe a rectangle - /// of width and height around center. - /// - /// the inscribed rectangle width - /// the inscribed rectangle height - /// the inscribed rectangle (and hexagon) center - /// - public static ICurve CreateHexagon(double width, double height, Point center) { - var h = height / 2; - var w = width / 2; - var x = center.X; - var y = center.Y; - return new Polyline(new[]{ - new Point(-w - h + x, 0 + y), - new Point(-w + x, h + y), - new Point( w + x, h + y), - new Point( w + h + x, 0 + y), - new Point( w + x, - h + y), - new Point(-w + x, - h + y), - }) { Closed = true }; - } - - /// - /// Creates a curve in the form of an octagon within the rectangle formed by width and height at center. - /// - /// the bounding rectangle width - /// the bounding rectangle height - /// the bounding rectangle center - /// - public static ICurve CreateInteriorOctagon(double width, double height, Point center) { - return CreateOctagon(width / (1.0 + octagonPad), height / (1.0 + octagonPad), center); - } - - /// - /// testing, don't use - /// - /// - /// - /// - public static ICurve CreateTestShape(double width, double height) { - int mult = 1; - double w = width * 3; - double h = height * 3; - Curve curve = new Curve(9); - Curve.AddLineSegment(curve, -w, -h, 0, -h / 2); - Curve.ContinueWithLineSegment(curve, w / 2, -0.75 * h); - Curve.ContinueWithLineSegment(curve, w, -h); - Curve.ContinueWithLineSegment(curve, 0.75 * w, -h / 2); - Curve.ContinueWithLineSegment(curve, w / 2, 0); - Curve.ContinueWithLineSegment(curve, w, h); - - Curve.ContinueWithLineSegment(curve, 0, h / 2); - Curve.ContinueWithLineSegment(curve, -w, mult * h); - Curve.ContinueWithLineSegment(curve, -w / 3, 0); - Curve.CloseCurve(curve); - return curve; - } - - /// - /// create a triangle inside the box formed by width and height. - /// - /// - /// - /// - /// - static public ICurve CreateInteriorTriangle(double width, double height, Point center) { - double w = width / 2; - double h = height / 2; - double x = center.X; - double y = center.Y; - Curve c = new Curve(3); - Point[] p = new Point[] { new Point(x - w, y - h), new Point(x + w, y - h), new Point(x, y + h) }; - c.AddSegment(new LineSegment(p[0], p[1])); - c.AddSegment(new LineSegment(p[1], p[2])); - c.AddSegment(new LineSegment(p[2], p[0])); - return c; - } - - /// - /// Rotate a curve around a given point using radians - /// - /// - /// - /// - /// - public static ICurve RotateCurveAroundCenterByRadian(ICurve curve, Point center, double angle) { - ValidateArg.IsNotNull(curve, "curve"); - var c = Math.Cos(angle); - var s = Math.Sin(angle); - var transform = new PlaneTransformation(1, 0, center.X, 0, 1, center.Y) * new PlaneTransformation(c, -s, 0, s, c, 0) * new PlaneTransformation(1, 0, -center.X, 0, 1, -center.Y); - return curve.Transform(transform); - } - - /// - /// Rotate a curve around a given point using degrees - /// - /// - /// - /// - /// - public static ICurve RotateCurveAroundCenterByDegree(ICurve curve, Point center, double degree) { - return RotateCurveAroundCenterByRadian(curve, center, degree * (Math.PI / 180.0)); - } - - /// - /// - /// - /// - /// - public static ICurve CreateStar(double width, Point center) { - const double a = Math.PI * 2 / 5; - var r2 = width / (2 * Math.Sin(a)); - var r = r2 / 2; - return new Polyline(StarPoints(r, r2, center, a)) { Closed = true }; - - } - - static IEnumerable StarPoints(double r, double r2, Point center, double a) { - var ang = Math.PI / 2; - var anghalf = a / 2; - for (int i = 0; i < 5; i++) { - yield return center + r2 * new Point(Math.Cos(ang), Math.Sin(ang)); - yield return center + r * new Point(Math.Cos(ang + anghalf), Math.Sin(ang + anghalf)); - ang += a; - } - } - - internal static Polyline CreateRegularPolygon(int n, Point center, double rad) { - var pt = new Point[n]; - double a = 2 * Math.PI / n; - for (int i = 0; i < n; i++) - pt[i] = rad * (new Point(Math.Cos(i * a), Math.Sin(i * a))) + center; - return new Polyline(pt) { Closed = true }; - } - } -} diff --git a/GraphLayout/MSAGL/Miscellaneous/LayoutHelpers.cs b/GraphLayout/MSAGL/Miscellaneous/LayoutHelpers.cs index 939325ff..e483fae6 100644 --- a/GraphLayout/MSAGL/Miscellaneous/LayoutHelpers.cs +++ b/GraphLayout/MSAGL/Miscellaneous/LayoutHelpers.cs @@ -191,7 +191,7 @@ static void AddOrphanNodesToRootCluster(GeometryGraph geometryGraph) { public static void RouteAndLabelEdges(GeometryGraph geometryGraph, LayoutAlgorithmSettings layoutSettings, IEnumerable edgesToRoute, int straighLineRoutingThreshold, CancelToken cancelToken) { //todo: what about parent edges!!!! var filteredEdgesToRoute = - edgesToRoute.Where(e => !e.UnderCollapsedCluster() && e.SourcePort != null && e.TargetPort != null).ToArray(); + edgesToRoute.Where(e => !e.UnderCollapsedCluster()).ToArray(); if (filteredEdgesToRoute.Length == 0) return; var ers = layoutSettings.EdgeRoutingSettings; diff --git a/GraphLayout/MSAGL/Routing/SplineRouter.cs b/GraphLayout/MSAGL/Routing/SplineRouter.cs index 2e2c8f36..0143094e 100644 --- a/GraphLayout/MSAGL/Routing/SplineRouter.cs +++ b/GraphLayout/MSAGL/Routing/SplineRouter.cs @@ -36,8 +36,7 @@ IEnumerable edgeGeometriesEnumeration { get { if (this._edges != null) { foreach (var item in this._edges.Select(e => e.EdgeGeometry)) { - if (item.SourcePort != null && item.TargetPort != null) - yield return item; + yield return item; } } } @@ -633,9 +632,6 @@ Set EdgePassport(Edge edge) { IEnumerable AllPorts() { foreach (var edgeGeometry in edgeGeometriesEnumeration) { - if (edgeGeometry.SourcePort == null || edgeGeometry.TargetPort == null) { - Console.WriteLine(""); - } yield return edgeGeometry.SourcePort; yield return edgeGeometry.TargetPort; } @@ -647,7 +643,7 @@ void CalculatePortsToShapes() { foreach (var port in shape.Ports) portsToShapes[port] = shape; //assign all orphan ports to the root - foreach (var port in AllPorts().Where(p => p != null && !portsToShapes.ContainsKey(p))) { + foreach (var port in AllPorts().Where(p => !portsToShapes.ContainsKey(p))) { root.Ports.Insert(port); portsToShapes[port] = root; }