/// <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 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); }
/// <summary> /// return the direction from a point to the shape. /// </summary> /// <param name="Shape"></param> /// <param name="FromPoint"></param> /// <returns></returns> public SideToShapeInfo(ShapeSide Side, Shape Shape) { this.Side = Side; this.Shape = Shape; WhichDirection? horizDir = null; LineCoordinates horizSide = null; HorizontalIntersect horizIntersect = null; WhichDirection? vertDir = null; LineCoordinates vertSide = null; VerticalIntersect vertIntersect = null; var br = Shape.GetBoundedRect(); if (Side.LineCoor.TopMost > br.Bottom) { vertDir = WhichDirection.Up; horizSide = Shape.GetSide(WhichSide.Bottom); if (Side.LineCoor.IsHorizontal) { horizIntersect = LineCoordinates.HorizontalIntersect(Side.LineCoor, horizSide); } } else if (Side.LineCoor.BottomMost < br.Top) { vertDir = WhichDirection.Down; horizSide = Shape.GetSide(WhichSide.Top); if (Side.LineCoor.IsHorizontal) { horizIntersect = LineCoordinates.HorizontalIntersect(Side.LineCoor, horizSide); } } if (Side.LineCoor.LeftMost > br.Right) { horizDir = WhichDirection.Left; vertSide = Shape.GetSide(WhichSide.Right); if (Side.LineCoor.IsVertical) { vertIntersect = LineCoordinates.VerticalIntersect(Side.LineCoor, vertSide); } } else if (Side.LineCoor.RightMost < br.Left) { horizDir = WhichDirection.Right; vertSide = Shape.GetSide(WhichSide.Left); if (Side.LineCoor.IsVertical) { vertIntersect = LineCoordinates.VerticalIntersect(Side.LineCoor, vertSide); } } // setup the vertical side of the shape that faces the side. if (vertSide == null) { var rightSide = new ShapeSide(Shape, WhichSide.Right); var leftSide = new ShapeSide(Shape, WhichSide.Left); if (Side.RightMost > rightSide.RightMost) { vertSide = rightSide.LineCoor; } else if (Side.LeftMost < leftSide.LeftMost) { vertSide = leftSide.LineCoor; } } // setup the horizontal side of the shape that faces the side. if (horizSide == null) { var bottomSide = new ShapeSide(Shape, WhichSide.Bottom); var topSide = new ShapeSide(Shape, WhichSide.Top); if (Side.BottomMost > bottomSide.BottomMost) { horizSide = bottomSide.LineCoor; } else if (Side.TopMost < topSide.TopMost) { horizSide = topSide.LineCoor; } } this.HorizDirection = horizDir; this.HorizSide = horizSide; this.HorizIntersect = horizIntersect; this.VertDirection = vertDir; this.VertSide = vertSide; this.VertIntersect = vertIntersect; }