/// <summary> /// Support allowing the user to move the angle control handles. /// </summary> /// <param name="view"></param> /// <param name="origRect"></param> /// <param name="newPoint"></param> /// <param name="whichHandle"></param> /// <param name="evttype"></param> /// <param name="min"></param> /// <param name="max"></param> public override void DoResize(GoView view, RectangleF origRect, PointF newPoint, int whichHandle, GoInputState evttype, SizeF min, SizeF max) { if ((whichHandle == 1039 || whichHandle == 1040) && (ResizesRealtime || evttype == GoInputState.Finish || evttype == GoInputState.Cancel)) { switch (whichHandle) { case 1039: { RectangleF bounds2 = Bounds; float num6 = bounds2.Width / 2f; float num7 = bounds2.Height / 2f; float num8 = bounds2.X + num6; float num9 = bounds2.Y + num7; float angle = GoStroke.GetAngle(newPoint.X - num8, newPoint.Y - num9); float num10 = SweepAngle - (angle - StartAngle); if (SweepAngle >= 0f) { if (num10 < 0f) { num10 += 360f; } } else if (num10 >= 0f) { num10 -= 360f; } SweepAngle = num10; StartAngle = angle; break; } case 1040: { RectangleF bounds = Bounds; float num = bounds.Width / 2f; float num2 = bounds.Height / 2f; float num3 = bounds.X + num; float num4 = bounds.Y + num2; float num5 = GoStroke.GetAngle(newPoint.X - num3, newPoint.Y - num4) - StartAngle; if (SweepAngle >= 0f) { if (num5 < 0f) { num5 += 360f; } } else if (num5 >= 0f) { num5 -= 360f; } SweepAngle = num5; break; } } } else { base.DoResize(view, origRect, newPoint, whichHandle, evttype, min, max); } }
/// <summary> /// A point is in this object only if it really is inside the section of the ellipse. /// </summary> /// <param name="p"></param> /// <returns></returns> public override bool ContainsPoint(PointF p) { if (!base.ContainsPoint(p)) { return(false); } RectangleF bounds = Bounds; float num = PenWidth / 2f; float num2 = bounds.Width / 2f; float num3 = bounds.Height / 2f; float num4 = bounds.X + num2; float num5 = bounds.Y + num3; num2 += num; num3 += num; if (num2 == 0f || num3 == 0f) { return(false); } float num6 = p.X - num4; float num7 = p.Y - num5; if (num6 * num6 / (num2 * num2) + num7 * num7 / (num3 * num3) > 1f) { return(false); } float angle = GoStroke.GetAngle(p.X - num4, p.Y - num5); float num8; float num9; if (SweepAngle < 0f) { num8 = StartAngle + SweepAngle; num9 = 0f - SweepAngle; } else { num8 = StartAngle; num9 = SweepAngle; } if (num9 > 360f) { return(true); } if (num8 + num9 > 360f) { if (!(angle >= num8)) { return(angle <= num8 + num9 - 360f); } return(true); } if (angle >= num8) { return(angle <= num8 + num9); } return(false); }
/// <summary> /// Determine the angle the port at the other end makes with this port. /// </summary> /// <param name="link"></param> /// <returns>the angle in degrees</returns> public virtual float GetAngle(IGoLink link) { if (link == null) { return(0f); } IGoPort goPort = link.GetOtherPort(this); if (goPort == null) { if (link.FromPort != null && link.FromPort.GoObject != null && link.FromPort.GoObject.Bounds == Bounds) { goPort = link.ToPort; } else if (link.ToPort != null && link.ToPort.GoObject != null && link.ToPort.GoObject.Bounds == Bounds) { goPort = link.FromPort; } } if (goPort == null) { return(0f); } GoObject goObject = goPort.GoObject; if (goObject == null) { return(0f); } PointF pointF = goObject.Center; PointF center = base.Center; GoLink goLink = link as GoLink; if (goLink == null) { GoLabeledLink goLabeledLink = link as GoLabeledLink; if (goLabeledLink != null) { goLink = goLabeledLink.RealLink; } } if (goLink != null && goLink.PointsCount > 0) { pointF = ((goLink.FromPort != goPort) ? goLink.GetPoint(checked (goLink.PointsCount - 1)) : goLink.GetPoint(0)); } return(GoStroke.GetAngle(pointF.X - center.X, pointF.Y - center.Y)); }
/// <summary> /// Find the intersection point of the elliptical path defined by rectangle rect and an infinite /// line p1-p2 that is closest to point p1 within the area from startAngle through the sweepAngle. /// </summary> /// <param name="rect"></param> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="result"></param> /// <param name="startAngle"></param> /// <param name="sweepAngle"></param> /// <returns></returns> public static bool NearestIntersectionOnArc(RectangleF rect, PointF p1, PointF p2, out PointF result, float startAngle, float sweepAngle) { float num = rect.Width / 2f; float num2 = rect.Height / 2f; float num3 = rect.X + num; float num4 = rect.Y + num2; float num5; float num6; if (sweepAngle < 0f) { num5 = startAngle + sweepAngle; num6 = 0f - sweepAngle; } else { num5 = startAngle; num6 = sweepAngle; } if (p1.X != p2.X) { float num7 = (!(p1.X > p2.X)) ? ((p2.Y - p1.Y) / (p2.X - p1.X)) : ((p1.Y - p2.Y) / (p1.X - p2.X)); float num8 = p1.Y - num4 - num7 * (p1.X - num3); float num9 = (float)Math.Sqrt(num * num * (num7 * num7) + num2 * num2 - num8 * num8); float num10 = (0f - num * num * num7 * num8 + num * num2 * num9) / (num2 * num2 + num * num * (num7 * num7)) + num3; float num11 = (0f - num * num * num7 * num8 - num * num2 * num9) / (num2 * num2 + num * num * (num7 * num7)) + num3; float num12 = num7 * (num10 - num3) + num8 + num4; float num13 = num7 * (num11 - num3) + num8 + num4; float num14 = GoStroke.GetAngle(num10 - num3, num12 - num4); float num15 = GoStroke.GetAngle(num11 - num3, num13 - num4); if (num14 < num5) { num14 += 360f; } if (num15 < num5) { num15 += 360f; } if (num14 > num5 + num6) { num14 -= 360f; } if (num15 > num5 + num6) { num15 -= 360f; } bool flag = num14 >= num5 && num14 <= num5 + num6; bool flag2 = num15 >= num5 && num15 <= num5 + num6; if (flag && flag2) { float num16 = Math.Abs((p1.X - num10) * (p1.X - num10)) + Math.Abs((p1.Y - num12) * (p1.Y - num12)); float num17 = Math.Abs((p1.X - num11) * (p1.X - num11)) + Math.Abs((p1.Y - num13) * (p1.Y - num13)); if (num16 < num17) { result = new PointF(num10, num12); } else { result = new PointF(num11, num13); } return(true); } if (flag && !flag2) { result = new PointF(num10, num12); return(true); } if (!flag && flag2) { result = new PointF(num11, num13); return(true); } result = default(PointF); return(false); } float num18 = (float)Math.Sqrt(num2 * num2 - num2 * num2 / (num * num) * ((p1.X - num3) * (p1.X - num3))); float num19 = num4 + num18; float num20 = num4 - num18; float num21 = GoStroke.GetAngle(p1.X - num3, num19 - num4); float num22 = GoStroke.GetAngle(p1.X - num3, num20 - num4); if (num21 < num5) { num21 += 360f; } if (num22 < num5) { num22 += 360f; } if (num21 > num5 + num6) { num21 -= 360f; } if (num22 > num5 + num6) { num22 -= 360f; } bool flag3 = num21 >= num5 && num21 <= num5 + num6; bool flag4 = num22 >= num5 && num22 <= num5 + num6; if (flag3 && flag4) { float num23 = Math.Abs(num19 - p1.Y); float num24 = Math.Abs(num20 - p1.Y); if (num23 < num24) { result = new PointF(p1.X, num19); } else { result = new PointF(p1.X, num20); } return(true); } if (flag3 && !flag4) { result = new PointF(p1.X, num19); return(true); } if (!flag3 && flag4) { result = new PointF(p1.X, num20); return(true); } result = default(PointF); return(false); }