public static LineCoordinates GetCoordinates(this Line Line) { var coor = new LineCoordinates( new Point(Line.X1, Line.Y1), new Point(Line.X2, Line.Y2)); return(coor); }
public void LineCoordinatesClassGetIndexOfLongestLineMethodReturnsCorrectValueIfThereAreMultipleNonNullItemsInList() { int count = _rnd.Next(20) + 2; double[] lengths = new double[count]; for (int i = 0; i < count; ++i) { lengths[i] = _rnd.NextDouble() * 120; } int answer = lengths.MaxIndex(); List <LineCoordinates> testInput = new List <LineCoordinates>(count); for (int i = 0; i < count; ++i) { VertexInformation startVertex = new VertexInformation(new TrainDrawingInfo(), _rnd.NextTimeOfDay(), _rnd.NextArrivalDepartureOptions(), _rnd.NextDouble() * 200, _rnd.NextDouble() * 200); double theta = _rnd.NextDouble() * Math.PI * 2; VertexInformation endVertex = new VertexInformation(new TrainDrawingInfo(), _rnd.NextTimeOfDay(), _rnd.NextArrivalDepartureOptions(), startVertex.X + lengths[i] * Math.Cos(theta), startVertex.Y + lengths[i] * Math.Sin(theta)); testInput.Add(new LineCoordinates(startVertex, endVertex)); } int testOutput = LineCoordinates.GetIndexOfLongestLine(testInput); Assert.AreEqual(answer, testOutput); }
public static void DrawGridLines( this Canvas Canvas1, double Spacing, string Tag = null) { var lineChar = new LineCharacteristics() { StrokeThickness = 1, }; // draw horizontal grid lines. double ht = Canvas1.ActualHeight; for (var ix = 0.0; ix < Canvas1.ActualHeight; ix = ix + Spacing) { var start = new Point(0, ix); var coor = new LineCoordinates(start, new Point(Canvas1.ActualWidth, ix)); var line = Canvas1.DrawLine(coor, lineChar); if (Tag != null) { line.Tag = Tag; } } // draw vertical grid lines. for (var ix = 0.0; ix < Canvas1.ActualWidth; ix += Spacing) { var start = new Point(ix, 0); var coor = new VerticalLineCoordinates(start, Canvas1.ActualHeight); var line = Canvas1.DrawLine(coor, lineChar); if (Tag != null) { line.Tag = Tag; } } }
/// <summary> /// map out a route from shape1 to shape2, starting from a specific side of shape1. /// </summary> /// <param name="InCanvas"></param> /// <param name="Shape1"></param> /// <param name="Shape2"></param> /// <param name="DepartureSide"></param> /// <param name="Route"></param> public static void DrawRouteBetweenShapes( this Canvas InCanvas, Shape Shape1, Shape Shape2, WhichSide DepartureSide, ConnectionRoute Route) { // vertical and horizontal intersection of the two shapes. var vi = ShapeExt.VerticalIntersect(Shape1, Shape2); var hi = ShapeExt.HorizontalIntersect(Shape1, Shape2); if (DepartureSide == WhichSide.Left) { LineCoordinates coor = null; if (Shape1.IsEntirelyToTheRightOf(Shape2).GetValueOrDefault() && (vi.Length > 0)) { coor = InCanvas.DrawLineBetweenShapes( Shape1, WhichSide.Left, Shape2, WhichSide.Right); } else { // draw a short line from the shape to the next available orbit location // around the from shape. var leg = ConnectionLeg.DrawLegToOrbit(Shape1, DepartureSide); Route.AddLeg(leg); } } }
public TriangleLines( LineCoordinates Side1, LineCoordinates Side2, LineCoordinates Side3) { { var line = new TriangleLine() { SideName = "Side1", LineCoor = Side1 }; this.Add(line); } { var line = new TriangleLine() { SideName = "Side2", LineCoor = Side2 }; this.Add(line); } { var line = new TriangleLine() { SideName = "Side3", LineCoor = Side3 }; this.Add(line); } }
public static LineCoordinates TryDrawDirectLineToShape( PointToShapeInfo ToShapeInfo, LineCoordinates FromSide, WhichDirection Direction) { LineCoordinates lineCoor = null; #if skip Point?toPoint = null; // The vertical direction to the shape matches the requested draw direction. // And a straight line can be drawn from the point to the shape. if ((ToShapeInfo.VertDirection != null) && (ToShapeInfo.VertDirection.Value == Direction) && (ToShapeInfo.HorizSide.WithinHorizontalRange(FromPoint.X))) { toPoint = new Point(FromPoint.X, ToShapeInfo.HorizSide.Start.Y); } // same as above, only in the horizontal direction. else if ((ToShapeInfo.HorizDirection != null) && (ToShapeInfo.HorizDirection.Value == Direction) && (ToShapeInfo.VertSide.WithinVerticalRange(FromPoint.Y))) { toPoint = new Point(ToShapeInfo.VertSide.Start.X, FromPoint.Y); } // build the coordinates of the direct line. if (toPoint != null) { lineCoor = new LineCoordinates(FromPoint, toPoint.Value); } #endif return(lineCoor); }
/// <summary> /// Return a ConnectionLeg which contains draw instructions for a line that runs /// from the DepartureSide of a shape to the location of the orbit that runs /// around the shape. /// </summary> /// <param name="FromShape"></param> /// <param name="DepartureSide"></param> /// <returns></returns> public static ConnectionLeg DrawLegToOrbit(Shape FromShape, WhichSide DepartureSide) { var sideCoor = FromShape.GetSide(DepartureSide); var midPt = sideCoor.MidPoint; double lgthToOrbit = 30; ConnectionLeg leg = null; // draw line depending on the side of the shape. LineCoordinates legCoor = null; var whichDir = DepartureSide.ToDirection(); legCoor = new LineCoordinates(midPt, new LineVector(lgthToOrbit, whichDir)); // line is off the canvas. do not create a connection leg. if ((legCoor.Start.X < 0) || (legCoor.Start.Y < 0) || (legCoor.End.X < 0) || (legCoor.End.Y < 0)) { leg = null; } else { leg = new ConnectionLeg() { Start = midPt, LineCoor = legCoor, Direction = whichDir }; } return(leg); }
public LineLeftToRightInfo(LineCoordinates Coor) { if (Coor.Start.Y > Coor.End.Y) { if (Coor.Start.X < Coor.End.X) { this.Start = new Point(Coor.Start.X, Coor.Start.Y); this.End = new Point(Coor.End.X, Coor.End.Y); } else { this.Start = new Point(Coor.End.X, Coor.End.Y); this.End = new Point(Coor.Start.X, Coor.Start.Y); } } else { if (Coor.Start.X <= Coor.End.X) { this.Start = new Point(Coor.Start.X, Coor.Start.Y); this.End = new Point(Coor.End.X, Coor.End.Y); } else { this.Start = new Point(Coor.End.X, Coor.End.Y); this.End = new Point(Coor.Start.X, Coor.Start.Y); } } }
/// <summary> /// The opposite side line is the line opposite the angle between this line and the /// adjacent line. This line, the adjacent line and the opposite line form a right /// triangle. Where the right angle of the right triangle is at the intersection of /// the adjacent line and the opposite side line. /// /// Use this method to get the position on the line of the opposite side line as /// the length of the adjacent line is varied. /// </summary> /// <param name="AdjacentSideLength"></param> /// <returns></returns> public LineCoordinates CalcOppositeSideLine(double AdjacentSideLength) { var adjSide = new HorizontalLineCoordinates(this.Start, AdjacentSideLength); var angle = Math.Abs(this.Angle); var radians = angle * (Math.PI / 180); var tan = Math.Tan(radians); // length of the opposite side line. var oppLgth = AdjacentSideLength * tan; // the end point of the opposite side line. Where the end point is either // above the adjacent line or below it. Depending on if the line ( the // hypotenuse ) goes up or down. Point oppEnd; if (this.SlopesUp == true) { oppEnd = new Point(adjSide.End.X, adjSide.End.Y - oppLgth + 1.00); _OppositeSideLine = new LineCoordinates(oppEnd, adjSide.End); } else { oppEnd = new Point(adjSide.End.X, adjSide.End.Y + oppLgth - 1.00); _OppositeSideLine = new LineCoordinates(adjSide.End, oppEnd); } return(_OppositeSideLine); }
/// <summary> /// Determine how much the two shapes vertically intersect each other. /// </summary> /// <param name="Shape1"></param> /// <param name="Shape2"></param> /// <returns></returns> public static VerticalIntersect VerticalIntersect(Shape Shape1, Shape Shape2) { var side1 = Shape1.GetSide(WhichSide.Left); var side2 = Shape2.GetSide(WhichSide.Left); var vi = LineCoordinates.VerticalIntersect(side1, side2); return vi; }
public void LineCoordinatesClassConstructorSetsVertex2PropertyToValueOfSecondParameter() { VertexInformation testParam0 = new VertexInformation(new TrainDrawingInfo(), _rnd.NextTimeOfDay(), _rnd.NextArrivalDepartureOptions(), _rnd.NextDouble(), _rnd.NextDouble()); VertexInformation testParam1 = new VertexInformation(new TrainDrawingInfo(), _rnd.NextTimeOfDay(), _rnd.NextArrivalDepartureOptions(), _rnd.NextDouble(), _rnd.NextDouble()); LineCoordinates testOutput = new LineCoordinates(testParam0, testParam1); Assert.AreSame(testParam1, testOutput.Vertex2); }
/// <summary> /// Determine how much the two shapes horizontally intersect each other. /// </summary> /// <param name="Shape1"></param> /// <param name="Shape2"></param> /// <returns></returns> public static HorizontalIntersect HorizontalIntersect(Shape Shape1, Shape Shape2) { var side1 = Shape1.GetSide(WhichSide.Top); var side2 = Shape2.GetSide(WhichSide.Top); var hi = LineCoordinates.HorizontalIntersect(side1, side2); return hi; }
public static ConnectionLeg DrawLegToShape( Shape FromShape, Shape ToShape, ConnectionLeg LastLeg, WhichDirection Direction) { ConnectionLeg leg = null; LineCoordinates legCoor = null; var toShapeInfo = ToShape.DirectionToShape(LastLeg.End); // start point of the leg. var legStart = LastLeg.End; // attempt to draw a direct line to the shape. if (legCoor == null) { legCoor = ConnectionRoute.TryDrawDirectLineToShape( toShapeInfo, legStart, Direction); } // drawing a vertical line. draw it to the halfway point of the vertical side // of the shape. if ((legCoor == null) && Direction.IsVertical() && (toShapeInfo.VertDirection.Equals(Direction))) { var toPoint = new Point(legStart.X, toShapeInfo.VertSide.MidPoint.Y); legCoor = new LineCoordinates(legStart, toPoint); } // drawing a horizontal line. draw it to the halfway point of the horiz side of // the shape. if ((legCoor == null) && Direction.IsHorizontal() && (toShapeInfo.HorizDirection.Equals(Direction))) { var toPoint = new Point(toShapeInfo.HorizSide.MidPoint.X, legStart.Y); legCoor = new LineCoordinates(legStart, toPoint); } // leg not drawn. The current leg is part of an orbit around a shape. Have to draw to // the next corner of the orbit. if (legCoor == null) { var rectMore = ShapeMore.Construct(FromShape); legCoor = rectMore.DrawLineToOrbitCorner(legStart, Direction); } leg = new ConnectionLeg() { Direction = Direction, LineCoor = legCoor, Start = legStart }; return(leg); }
public void LineCoordinatesClassGetIndexOfLongestLineMethodReturnsZeroIfParameterContainsOneItem() { List <LineCoordinates> testInput = new List <LineCoordinates> { new LineCoordinates(new VertexInformation(new TrainDrawingInfo(), _rnd.NextTimeOfDay(), _rnd.NextArrivalDepartureOptions(), _rnd.NextDouble(), _rnd.NextDouble()), new VertexInformation(new TrainDrawingInfo(), _rnd.NextTimeOfDay(), _rnd.NextArrivalDepartureOptions(), _rnd.NextDouble(), _rnd.NextDouble())) }; int testOutput = LineCoordinates.GetIndexOfLongestLine(testInput); Assert.AreEqual(0, testOutput); }
public static ObliqueTriangle ConstructFromVertexPositions( Point Pos1, Point Pos2, Point Pos3) { // setup the left most vertex, then the upper vertex and lower vertex. var rv = ObliqueTriangle.SplitLeftMostPoint(new Point[] { Pos1, Pos2, Pos3 }); Point pt1 = rv.Item1; // pt1 is left most point var rv2 = ObliqueTriangle.SplitTopMostPoint(rv.Item2); Point pt2 = rv2.Item1; // pt2 is top most point of pt2 and pt3. Point pt3 = rv2.Item2[0]; // Create lines between the points. Line numbers match the number of the opposite // point. LineCoordinates line1 = new LineCoordinates(pt2, pt3); LineCoordinates line2 = new LineCoordinates(pt1, pt3); LineCoordinates line3 = new LineCoordinates(pt1, pt2); // the angle of each vertex. var ang1 = LineCoordinates.AngleBetween(line2, line3); var ang2 = LineCoordinates.AngleBetween(line1, line3); var ang3 = LineCoordinates.AngleBetween(line2, line1); var vertex1 = new TriangleVertex() { Angle = ang1, Location = pt1, Line = line1 }; var vertex2 = new TriangleVertex() { Angle = ang2, Location = pt2, Line = line2 }; var vertex3 = new TriangleVertex() { Angle = ang3, Location = pt3, Line = line3 }; var ot = new ObliqueTriangle() { Vertex1 = vertex1, Vertex2 = vertex2, Vertex3 = vertex3 }; return(ot); }
/// <summary> /// Construct an ObliqueTriangle from three lines. If the end points of all the /// lines do not meet to form a triangle, return null. /// </summary> /// <param name="Line1"></param> /// <param name="Line2"></param> /// <param name="Line3"></param> /// <returns></returns> public static ObliqueTriangle TryConstructFromLines( LineCoordinates Line1, LineCoordinates Line2, LineCoordinates Line3) { ObliqueTriangle ot = null; // line up the points of the lines var linePoints = new Point[] { Line1.Start, Line1.End, Line2.Start, Line2.End, Line3.Start, Line3.End }; // start of line1 matches the end points of the other 2 lines. return(ot); }
public void LineCoordinatesClassGetIndexOfLongestLineMethodReturnsMinusOneIfEveryItemInParameterIsNull() { List <LineCoordinates> testInput = new List <LineCoordinates>(); int count = _rnd.Next(20) + 1; for (int i = 0; i < count; ++i) { testInput.Add(null); } int testOutput = LineCoordinates.GetIndexOfLongestLine(testInput); Assert.AreEqual(-1, testOutput); }
public override LineCoordinates DrawLineToOrbitCorner( Point Start, WhichDirection Direction) { double lgthToOrbit = 30; LineCoordinates lineCoor = null; switch (Direction) { case WhichDirection.Left: { var rect = this.BoundedRect.Value; var toX = rect.Left - lgthToOrbit + 1.00; var orbitPoint = new Point(toX, Start.Y); lineCoor = new LineCoordinates(orbitPoint, Start); break; } case WhichDirection.Right: { var rect = this.BoundedRect.Value; var toX = rect.Right + lgthToOrbit - 1.00; var orbitPoint = new Point(toX, Start.Y); lineCoor = new LineCoordinates(orbitPoint, Start); break; } case WhichDirection.Up: { var rect = this.BoundedRect.Value; var toY = rect.Top - lgthToOrbit + 1.00; var orbitPoint = new Point(Start.X, toY); lineCoor = new LineCoordinates(orbitPoint, Start); break; } case WhichDirection.Down: { var rect = this.BoundedRect.Value; var toY = rect.Bottom + lgthToOrbit - 1.00; var orbitPoint = new Point(Start.X, toY); lineCoor = new LineCoordinates(orbitPoint, Start); break; } default: throw new ApplicationException("unhandled direction"); } return(lineCoor); }
public static ConnectionLeg DrawLegFromPoint(Point FromPoint, LineVector Vector) { // draw line depending on the side of the shape. var legCoor = new LineCoordinates(FromPoint, Vector); var leg = new ConnectionLeg() { Start = FromPoint, LineCoor = legCoor, Direction = Vector.Direction }; return(leg); }
public static Line DrawLine(this Canvas InCanvas, LineCoordinates LineCoor) { Line newLine = new Line(); newLine.Stroke = Brushes.Black; newLine.Fill = Brushes.Black; newLine.StrokeLineJoin = PenLineJoin.Bevel; newLine.X1 = LineCoor.Start.X; newLine.Y1 = LineCoor.Start.Y; newLine.X2 = LineCoor.End.X; newLine.Y2 = LineCoor.End.Y; newLine.StrokeThickness = 2; InCanvas.Children.Add(newLine); return(newLine); }
public TriangleVertex OppositeVertex(TriangleLine TriLine) { var startCoor = TriLine.StartLine.LineCoor; var endCoor = TriLine.EndLine.LineCoor; var loc = LineCoordinates.CommonEndPoint(startCoor, endCoor); var angle = LineCoordinates.AngleBetween(startCoor, endCoor); var oppVertex = new TriangleVertex() { Angle = angle, Line = TriLine.LineCoor, Location = loc }; return(oppVertex); }
public static Rect GetBoundedRect(this Line Line) { var coor = new LineCoordinates( new Point(Line.X1, Line.Y1), new Point(Line.X2, Line.Y2)); return(coor.BoundedRect); #if skip var left = Line.GetLeft(); var top = Line.GetTop(); var width = Math.Abs(Line.X2 - Line.X1) + 1.00; var height = Math.Abs(Line.Y2 - Line.Y1) + 1.00; var rect = new Rect(left, top, width, height); return(rect); #endif }
public static Line DrawLine(this Canvas InCanvas, LineCoordinates LineCoor, LineCharacteristics LineChar) { Line newLine = new Line(); newLine.Stroke = LineChar.Stroke; newLine.Fill = LineChar.Fill; newLine.StrokeLineJoin = LineChar.StrokeLineJoin; newLine.X1 = LineCoor.Start.X; newLine.Y1 = LineCoor.Start.Y; newLine.X2 = LineCoor.End.X; newLine.Y2 = LineCoor.End.Y; newLine.StrokeThickness = LineChar.StrokeThickness; InCanvas.Children.Add(newLine); return(newLine); }
public static LineCoordinates DrawLineBetweenShapes( this Canvas InCanvas, Shape Shape1, WhichSide WhichSide1, Shape Shape2, WhichSide WhichSide2) { LineCoordinates betLine = null; var coor1 = Shape1.GetSide(WhichSide1); var coor2 = Shape2.GetSide(WhichSide2); // line runs from the midpoint of one side to the mid point of the other. betLine = new LineCoordinates(coor1.MidPoint, coor2.MidPoint); // draw a vertical line between the shapes. if ((WhichSide1 == WhichSide.Bottom) && (WhichSide2 == WhichSide.Top)) { var hi = LineCoordinates.HorizontalIntersect(coor1, coor2); if (hi.Length > 0) { double centeredIntersect1 = hi.Line1Ofs + (hi.Length / 2); Point fromPt = coor1.CalcHorizontalPointOnLine(centeredIntersect1); double centeredIntersect2 = hi.Line2Ofs + (hi.Length / 2); Point toPt = coor2.CalcHorizontalPointOnLine(centeredIntersect2); betLine = new LineCoordinates(fromPt, toPt); } } // draw a horizontal line between the shapes. else if ((WhichSide1 == WhichSide.Right) && (WhichSide2 == WhichSide.Left)) { var vi = LineCoordinates.VerticalIntersect(coor1, coor2); if (vi.Length > 0) { double centeredIntersect1 = vi.Line1Ofs + (vi.Length / 2); Point fromPt = coor1.CalcVerticalPointOnLine(centeredIntersect1); double centeredIntersect2 = vi.Line2Ofs + (vi.Length / 2); Point toPt = coor2.CalcVerticalPointOnLine(centeredIntersect2); betLine = new LineCoordinates(fromPt, toPt); } } // get horizontal intersect between the two lines // return the intersect as from and to pos, // get center pos of the horizontal intersect return(betLine); }
public void LineCoordinatesClassGetIndexOfLongestLineMethodReturnsIndexOfNonNullItemIfParameterOnlyContainsOneNonNullItem() { List <LineCoordinates> testInput = new List <LineCoordinates>(); LineCoordinates testItem = new LineCoordinates(new VertexInformation(new TrainDrawingInfo(), _rnd.NextTimeOfDay(), _rnd.NextArrivalDepartureOptions(), _rnd.NextDouble(), _rnd.NextDouble()), new VertexInformation(new TrainDrawingInfo(), _rnd.NextTimeOfDay(), _rnd.NextArrivalDepartureOptions(), _rnd.NextDouble(), _rnd.NextDouble())); int count = _rnd.Next(20) + 1; int pos = _rnd.Next(count); for (int i = 0; i < count; ++i) { testInput.Add(i == pos ? testItem : null); } int testOutput = LineCoordinates.GetIndexOfLongestLine(testInput); Assert.AreEqual(pos, testOutput); }
public static List <Shape> FindShapesThatIntersectLine( this Canvas Canvas, LineCoordinates Line) { List <Shape> shapes = new List <Shape>( ); foreach (var elem in Canvas.Children) { var uiShape = elem as Shape; if (uiShape != null) { bool doesIntersect = Line.DoesIntersect(uiShape); if (doesIntersect == true) { shapes.Add(uiShape); } } } return(shapes); }
public void TrainDrawingInfoClassLineVertexesPropertyGetMethodReturnsAllVertexesFromAllLines() { int lineCount = _rnd.Next(10) + 1; TrainDrawingInfo testObject = new TrainDrawingInfo(); List <VertexInformation> vertexList = new List <VertexInformation>(lineCount * 2); for (int i = 0; i < lineCount; ++i) { LineCoordinates line = new LineCoordinates(GetVertexInformation(testObject), GetVertexInformation(testObject)); vertexList.Add(line.Vertex1); vertexList.Add(line.Vertex2); testObject.Lines.Add(line); } List <VertexInformation> testOutput = testObject.LineVertexes.ToList(); Assert.AreEqual(vertexList.Count, testOutput.Count); foreach (VertexInformation vi in testOutput) { Assert.IsTrue(vertexList.Contains(vi)); vertexList.Remove(vi); } }
public PointToShapeInfo(Shape Shape, Point Point) { WhichDirection? horizDir = null; LineCoordinates horizSide = null; WhichDirection? vertDir = null; LineCoordinates vertSide = null; var topSide = Shape.GetSide(WhichSide.Top); var leftSide = Shape.GetSide(WhichSide.Left); if (Point.Y > leftSide.End.Y) { vertDir = WhichDirection.Up; horizSide = Shape.GetSide(WhichSide.Bottom); } else if (Point.Y < leftSide.Start.Y) { vertDir = WhichDirection.Down; horizSide = Shape.GetSide(WhichSide.Top); } if (Point.X > topSide.End.X) { horizDir = WhichDirection.Left; vertSide = Shape.GetSide(WhichSide.Right); } else if (Point.X < topSide.Start.X) { horizDir = WhichDirection.Right; vertSide = Shape.GetSide(WhichSide.Left); } this.HorizDirection = horizDir; this.HorizSide = horizSide; this.VertDirection = vertDir; this.VertSide = vertSide; }
public ConnectionLeg DrawInitialLegToShape() { ConnectionLeg leg = null; LineCoordinates legCoor = null; Point? legStart = null; // starting side var fromSide = this.FromSide; var toShapeInfo = new SideToShapeInfo(fromSide, this.ToShape); // the direction of the initial line. var dir = fromSide.WhichSide.ToDirection(); // draw horizontal line staight to the target shape. if (toShapeInfo.HorizDirection.Equals(dir) && (toShapeInfo.VertIntersect != null) && (toShapeInfo.VertIntersect.Length > 0)) { var vi = toShapeInfo.VertIntersect; double centeredIntersect1 = vi.Line1Ofs + (vi.Length / 2); legStart = vi.Line1.CalcVerticalPointOnLine(centeredIntersect1); double centeredIntersect2 = vi.Line2Ofs + (vi.Length / 2); Point toPt = vi.Line2.CalcVerticalPointOnLine(centeredIntersect2); legCoor = new LineCoordinates(legStart.Value, toPt); } // draw vertical staight to the target shape. else if (toShapeInfo.VertDirection.Equals(dir) && (toShapeInfo.HorizIntersect != null) && (toShapeInfo.HorizIntersect.Length > 0)) { var hi = toShapeInfo.HorizIntersect; double centeredIntersect1 = hi.Line1Ofs + (hi.Length / 2); legStart = hi.Line1.CalcHorizontalPointOnLine(centeredIntersect1); double centeredIntersect2 = hi.Line2Ofs + (hi.Length / 2); Point toPt = hi.Line2.CalcHorizontalPointOnLine(centeredIntersect2); legCoor = new LineCoordinates(legStart.Value, toPt); } // drawing a vertical line. // The end destination shape is in the direction of the vertical line. // ( ex: drawing the line down and the shape is below the side ) // Draw the line to the mid point of the vertical side of the to_shape. else if (toShapeInfo.VertDirection.Equals(dir)) { // start the leg at the mid point of the start from side. legStart = fromSide.LineCoor.MidPoint; // draw the line down ( or up ) to the mid point of the vertical side // ( either left or right side ) of the "to shape". var toY = toShapeInfo.VertSide.MidPoint.Y; var legEnd = new Point(legStart.Value.X, toY); legCoor = new LineCoordinates(legStart.Value, legEnd); } // drawing a horizontal line. // The end destination shape is in the direction of the horizontal line. // ( ex: drawing the line to the right and the shape is to the righ of the side ) // Draw the line to the mid point of the horizonntal side of the to_shape. else if (toShapeInfo.HorizDirection.Equals(dir)) { // start the leg at the mid point of the start from side. legStart = fromSide.LineCoor.MidPoint; // draw the line left ( or right ) to the mid point of the horiz side var toX = toShapeInfo.HorizSide.MidPoint.X; var legEnd = new Point(toX, legStart.Value.Y); legCoor = new LineCoordinates(legStart.Value, legEnd); } // create the leg. if (legCoor != null) { leg = new ConnectionLeg() { Direction = dir, LineCoor = legCoor, Start = legStart.Value }; } // draw a short line from the shape to the next available orbit location // around the from shape. else { leg = ConnectionLeg.DrawLegToOrbit(this.FromSide.Shape, this.FromSide.WhichSide); } return(leg); }
public void LineCoordinatesClassGetIndexOfLongestLineMethodReturnsMinusOneIfParameterIsEmptyList() { int testOutput = LineCoordinates.GetIndexOfLongestLine(new List <LineCoordinates>()); Assert.AreEqual(-1, testOutput); }