private void SetPoint(Hexagon hexagon, UnitPoint unitPoint) { #region 变化单个节点 //hexagon.HexagonPoints[nodeIndex] = unitPoint; //double radius0 = hexagon.GetRadius(hexagon.HexagonPoints[0]); //double radius = hexagon.GetRadius(unitPoint); //double k = radius / radius0; //for (int i = 0; i < hexagon.HexagonPoints.Length; i++) //{ // hexagon.HexagonPoints[i].X = hexagon.HexagonPoints[i].X + (k - 1) * (hexagon.HexagonPoints[i].X - hexagon.CenterPoint.X); // hexagon.HexagonPoints[i].Y = hexagon.HexagonPoints[i].Y + (k - 1) * (hexagon.HexagonPoints[i].Y - hexagon.CenterPoint.Y); //} #endregion double startAngle = HitUtil.LineAngleR(hexagon.CenterPoint, unitPoint, 0); double radius = hexagon.GetRadius(unitPoint); hexagon.HexagonPoints[0] = unitPoint; for (int i = 1; i < hexagon.SideCount; i++) { UnitPoint vertexPoint = HitUtil.PointOnCircle(hexagon.CenterPoint, radius, startAngle + hexagon.stepAngle * Math.PI / 180 * i); hexagon.HexagonPoints[i] = vertexPoint; } //double currentNodeAngle = HitUtil.LineAngleR(hexagon.CenterPoint, unitPoint, 0); //double startAngle = currentNodeAngle - (nodeIndex * hexagon.stepAngle); //double radius = hexagon.GetRadius(unitPoint); //for (int i = 0; i < hexagon.SideCount; i++) //{ // UnitPoint vertexPoint = HitUtil.PointOnCircle(hexagon.CenterPoint, radius, startAngle + hexagon.stepAngle * Math.PI / 180 * i); // hexagon.HexagonPoints[i] = vertexPoint; //} }
private float GetPercentInCircleByPoint(IDrawObject drawObject, UnitPoint unitPoint) { Circle circle = (Circle)drawObject; double angle = HitUtil.LineAngleR(circle.Center, unitPoint, 0); return((float)(angle / (Math.PI * 2))); }
private float GetPercentInArcByPoint(IDrawObject drawObject, UnitPoint unitPoint) { ArcBase arcBase = (ArcBase)drawObject; double angle = HitUtil.LineAngleR(arcBase.Center, unitPoint, 0); return((float)(angle / (Math.PI * 2))); }
public RectangleF GetBoundingRect(ICanvas canvas) { try { float thWidth = LineTool.ThresholdWidth(canvas, Width, ThresholdPixel); if (thWidth < Width) { thWidth = Width; } RectangleF rect = RectangleF.Empty; if (m_p2.IsEmpty || m_p3.IsEmpty) { rect = ScreenUtils.GetRect(m_p1, m_lastPoint, thWidth); } if (rect.IsEmpty) { float r = m_radius + thWidth / 2; rect = HitUtil.CircleBoundingRect(m_center, r); if (Selected) { float w = (float)canvas.ToUnit(20); rect.Inflate(w, w); } } if (m_lastPoint.IsEmpty == false) { rect = RectangleF.Union(rect, new RectangleF(m_lastPoint.Point, new SizeF(0, 0))); } return(rect); } catch (Exception ex) { throw ex; } }
public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype) { try { if (Type == BezierType.Bezier) { if (HitUtil.Distance(point, m_p1, true) <= 0.2) { return(new VertextSnapPoint(canvas, this, m_p1)); } if (HitUtil.Distance(point, m_p2, true) <= 0.2) { return(new VertextSnapPoint(canvas, this, m_p2)); } if (HitUtil.Distance(point, m_p3, true) <= 0.2) { return(new VertextSnapPoint(canvas, this, m_p3)); } if (HitUtil.Distance(point, m_p4, true) <= 0.2) { return(new VertextSnapPoint(canvas, this, m_p4)); } } return(null); } catch (Exception ex) { throw ex; } }
UnitPoint RadiusNodePoint(ICanvas canvas) { double r = Radius + canvas.ToUnit(8); float angle = StartAngle + SweepAngle / 2; return(HitUtil.PointOncircle(m_center, r, HitUtil.DegressToRadians(angle))); }
public override void OnMouseMove(ICanvas canvas, UnitPoint unitPoint) { base.OnMouseMove(canvas, unitPoint); if (this.CurrentPoint == MultiSegementLineCurrentPoint.StartPoint) { this.p1 = unitPoint; this.Points = new List <UnitPointBulge>(); Points.Add(new UnitPointBulge(this.p1)); } else if (this.CurrentPoint == MultiSegementLineCurrentPoint.MidPoint) { this.p2 = unitPoint; this.Points.Clear(); this.rectPoint.Clear(); this.Points.Add(new UnitPointBulge(this.p1)); this.Points.Add(new UnitPointBulge(new UnitPoint(this.p2.X, this.p1.Y))); this.Points.Add(new UnitPointBulge(this.p2)); this.Points.Add(new UnitPointBulge(new UnitPoint(this.p1.X, this.p2.Y))); this.maxRadius = this.GetMinSideLen() / 2; for (int i = 0; i < this.PointCount; i++) { this.rectPoint.Add(this.Points[i].Point); } return; } else if (this.CurrentPoint == MultiSegementLineCurrentPoint.EndPoint) { this.p3 = unitPoint; double radius = HitUtil.Distance(unitPoint, this.p2); this.CalculateRoundParams(radius); } }
public virtual INodePoint NodePoint(ICanvas canvas, UnitPoint point) { float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel); if (HitUtil.PointInPoint(m_center, point, thWidth)) { return(new NodePointArcCenter(this)); } if (HitUtil.PointInPoint(StartAnglePoint, point, thWidth)) { m_curPoint = eCurrentPoint.startAngle; m_lastPoint = m_center; return(new NodePointArcAngle(this)); } if (HitUtil.PointInPoint(EndAnglePoint, point, thWidth)) { m_curPoint = eCurrentPoint.endAngle; m_lastPoint = m_center; return(new NodePointArcAngle(this)); } if (HitUtil.PointInPoint(RadiusPoint, point, thWidth)) { m_curPoint = eCurrentPoint.radius; m_lastPoint = m_center; return(new NodePointArcRadius(this)); } return(null); }
public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { if (snappoint is SnapPointBase && snappoint.Owner is RectBase) { NodePointMultiConnectionLine.ePoint pointType = HitUtil.Distance(point, m_p1) < HitUtil.Distance(point, m_p2) ? NodePointMultiConnectionLine.ePoint.P1 : NodePointMultiConnectionLine.ePoint.P2; RectBase rect = snappoint.Owner as RectBase; rect.AttachConnectionCrvNode(new NodePointMultiConnectionLine(this, pointType)); if (pointType == NodePointMultiConnectionLine.ePoint.P1) { m_p1 = point; } else { m_p2 = point; } return(eDrawObjectMouseDown.Done); } OnMouseMove(canvas, point); Selected = false; if (m_allPts == null || m_allPts.Count < 2) { return(eDrawObjectMouseDown.Cancel); } return(eDrawObjectMouseDown.Done); }
public override void OnMouseMove(ICanvas canvas, UnitPoint unitPoint) { if (this.arcCurrentPointType == ArcCurrentPointType.Center) { this.Center = unitPoint; return; } if (this.arcCurrentPointType == ArcCurrentPointType.StartPoint) { this.StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(this.Center, unitPoint, 0)); this.AngleSweep = 360; if (float.IsNaN(this.InRadiusValue)) { this.Radius = (float)HitUtil.Distance(this.Center, unitPoint); this.startPoint = unitPoint; } else { this.Radius = InRadiusValue; this.startPoint = new UnitPoint(this.Radius * Math.Cos(HitUtil.DegreesToRadians(StartAngle)) + this.Center.X, this.Radius * Math.Sin(HitUtil.DegreesToRadians(StartAngle)) + this.Center.Y); } return; } if (this.arcCurrentPointType == ArcCurrentPointType.EndPoint) { float endAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(this.Center, unitPoint, 0)); this.AngleSweep = endAngle - this.StartAngle; this.AngleSweep = this.AngleSweep > 0 ? this.AngleSweep : this.AngleSweep + 360; this.endPoint = new UnitPoint(this.Radius * Math.Cos(HitUtil.DegreesToRadians(endAngle)) + this.Center.X, this.Radius * Math.Sin(HitUtil.DegreesToRadians(endAngle)) + this.Center.Y); return; } }
public virtual eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { Selected = false; if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Line) { Line src = snappoint.Owner as Line; m_p2 = HitUtil.NearestPointOnLine(src.P1, src.P2, m_p1, true); return(eDrawObjectMouseDown.DoneRepeat); } /* * if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Arc) * { * Arc src = snappoint.Owner as Arc; * m_p2 = HitUtil.NearestPointOnCircle(src.Center, src.Radius, m_p1, 0); * return eDrawObjectMouseDown.DoneRepeat; * } * */ if (Control.ModifierKeys == Keys.Control) { point = HitUtil.OrthoPointD(m_p1, point, 45); } m_p2 = point; return(eDrawObjectMouseDown.DoneRepeat); }
public override DrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snapPoint, MouseEventArgs e) { OnMouseMove(canvas, point); if (this.arcCurrentPointType == ArcCurrentPointType.Center) { this.arcCurrentPointType = ArcCurrentPointType.StartPoint; return(DrawObjectMouseDown.Continue); } if (this.arcCurrentPointType == ArcCurrentPointType.StartPoint) { this.arcCurrentPointType = ArcCurrentPointType.EndPoint; this.StartMovePoint = startPoint; return(DrawObjectMouseDown.Continue); } if (this.arcCurrentPointType == ArcCurrentPointType.EndPoint) { this.arcCurrentPointType = ArcCurrentPointType.Done; this.midPoint = new UnitPoint(this.Radius * Math.Cos(HitUtil.DegreesToRadians(this.StartAngle + AngleSweep / 2)) + this.Center.X, this.Radius * Math.Sin(HitUtil.DegreesToRadians(this.StartAngle + AngleSweep / 2)) + this.Center.Y); this.IsSelected = false; this.GroupParam.FigureSN = ++GlobalModel.TotalDrawObjectCount; this.GroupParam.ShowSN = this.GroupParam.FigureSN; this.IsCompleteDraw = true; this.EndMovePoint = this.endPoint; return(DrawObjectMouseDown.Done); } return(DrawObjectMouseDown.Done); }
public bool SetStartMovePoint(UnitPoint unitPoint) { float thresholdWidth = UCCanvas.GetThresholdWidth(); if (this.PointInObject(unitPoint)) { if (HitUtil.IsPointInLine(this.LeftTopPoint, this.RightTopPoint, unitPoint, thresholdWidth)) { unitPoint = this.HandleSideBoundError(unitPoint, LeftTopPoint, RightTopPoint, thresholdWidth); this.StartMovePoint = HitUtil.FindApparentIntersectPoint(this.CenterPoint, unitPoint, this.LeftTopPoint, this.RightTopPoint); this.StartMovePosition = NodePosition.LeftTop; } else if (HitUtil.IsPointInLine(this.RightTopPoint, this.RightBottomPoint, unitPoint, thresholdWidth)) { unitPoint = this.HandleSideBoundError(unitPoint, RightTopPoint, RightBottomPoint, thresholdWidth); this.StartMovePoint = HitUtil.FindApparentIntersectPoint(this.CenterPoint, unitPoint, this.RightTopPoint, this.RightBottomPoint); this.StartMovePosition = NodePosition.RightTop; } else if (HitUtil.IsPointInLine(this.RightBottomPoint, this.LeftBottomPoint, unitPoint, thresholdWidth)) { unitPoint = this.HandleSideBoundError(unitPoint, RightBottomPoint, LeftBottomPoint, thresholdWidth); this.StartMovePoint = HitUtil.FindApparentIntersectPoint(this.CenterPoint, unitPoint, this.RightBottomPoint, this.LeftBottomPoint); this.StartMovePosition = NodePosition.RightBottom; } else if (HitUtil.IsPointInLine(this.LeftBottomPoint, this.LeftTopPoint, unitPoint, thresholdWidth)) { unitPoint = this.HandleSideBoundError(unitPoint, LeftBottomPoint, LeftTopPoint, thresholdWidth); this.StartMovePoint = HitUtil.FindApparentIntersectPoint(this.CenterPoint, unitPoint, this.LeftBottomPoint, this.LeftTopPoint); this.StartMovePosition = NodePosition.LeftBottom; } this.OverCutting(); return(true); } return(false); }
public override DrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snapPoint, MouseEventArgs e) { OnMouseMove(canvas, point); if (this.arcCurrentPointType == ArcCurrentPointType.StartPoint) { this.arcCurrentPointType = ArcCurrentPointType.MidPoint; this.StartMovePoint = point; return(DrawObjectMouseDown.Continue); } if (this.arcCurrentPointType == ArcCurrentPointType.MidPoint) { if (this.startPoint != point) { this.arcCurrentPointType = ArcCurrentPointType.EndPoint; } return(DrawObjectMouseDown.Continue); } if (this.arcCurrentPointType == ArcCurrentPointType.EndPoint) { this.arcCurrentPointType = ArcCurrentPointType.Done; this.IsSelected = false; this.GroupParam.FigureSN = ++GlobalModel.TotalDrawObjectCount; this.GroupParam.ShowSN = this.GroupParam.FigureSN; this.IsCompleteDraw = true; this.midPoint = HitUtil.PointOnCircle(this.Center, this.Radius, HitUtil.DegreesToRadians(this.MidAngle)); this.EndMovePoint = this.endPoint; return(DrawObjectMouseDown.Done); } return(DrawObjectMouseDown.Done); }
/// <summary> /// 返回一个bool值指示点是否在线条中 /// </summary> /// <returns></returns> bool PointsInLine() { double slope1 = HitUtil.LineSlope(P1, P2); double slope2 = HitUtil.LineSlope(P1, P3); return(slope1 == slope2); }
private void MouseDownSetBridge(MouseEventArgs e) { UnitPoint mousePoint = this.ToUnit(this.mouseDownPoint); if (this.bridgeStart.IsEmpty) { this.bridgeStart = mousePoint; } else { this.bridgeEnd = mousePoint; BridgingModel param = this.bridgeFunc?.Invoke(); if (param != null) { //1.获取图形区域与桥接直线交叉的图形 var oldObjects = this.Model.DrawingLayer.Objects.FindAll(f => HitUtil.LineIntersectWithRect(this.bridgeStart, this.bridgeEnd, f.GetBoundingRectangle(BoundingRectangleType.All))); bool isChanged = false; //2.计算直线与图形的交点 var newObjects = BridgeHelper.GetBridgeObjects(oldObjects, this.bridgeStart, this.bridgeEnd, param, out isChanged); if (isChanged) { this.Model.DoBridge(newObjects, oldObjects, true); } } this.CommandEscape(); } }
public override INodePoint NodePoint(ICanvas canvas, UnitPoint point) { float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel); if (HitUtil.PointInPoint(Center, point, thWidth)) { return(new NodePointArcCenter(this)); } bool radiushit = HitUtil.PointInPoint(AnglePoint(0), point, thWidth); if (radiushit == false) { radiushit = HitUtil.PointInPoint(AnglePoint(90), point, thWidth); } if (radiushit == false) { radiushit = HitUtil.PointInPoint(AnglePoint(180), point, thWidth); } if (radiushit == false) { radiushit = HitUtil.PointInPoint(AnglePoint(270), point, thWidth); } if (radiushit) { m_curPoint = eCurrentPoint.radius; m_lastPoint = Center; return(new NodePointArcRadius(this)); } return(null); }
public bool ObjectInRectangle(ICanvas canvas, RectangleF rect, bool anyPoint) { if (m_allPts == null || m_allPts.Count < 1) { return(false); } RectangleF boundingrect = GetBoundingRect(canvas); if (anyPoint) { for (int ii = 0; ii < m_allPts.Count - 1; ++ii) { if (HitUtil.LineIntersectWithRect(m_allPts[ii], m_allPts[ii + 1], rect)) { return(true); } } return(false); } //make sure all points are in the rectangle foreach (var curPt in m_allPts) { if (!rect.Contains(curPt.Point)) { return(false); } } return(true); }
public virtual void OnMouseMove(ICanvas canvas, UnitPoint point) { m_lastPoint = point; if (m_curPoint == eCurrentPoint.p1) { m_p1 = point; return; } if (m_curPoint == eCurrentPoint.p2) { m_p2 = point; return; } if (m_curPoint == eCurrentPoint.p3) { m_p3 = point; UpdateCircleFrom3Points(); return; } if (m_curPoint == eCurrentPoint.center) { m_center = point; } if (m_curPoint == eCurrentPoint.radius) { //StartAngle = 0; //EndAngle = 360; m_radius = (float)HitUtil.Distance(m_center, point); } }
public virtual void Redo() { m_owner.P1 = HitUtil.PointOncircle(m_owner.Center, m_endValue, HitUtil.DegressToRadians(Angle1)); m_owner.P2 = HitUtil.PointOncircle(m_owner.Center, m_endValue, HitUtil.DegressToRadians(Angle2)); m_owner.P3 = HitUtil.PointOncircle(m_owner.Center, m_endValue, HitUtil.DegressToRadians(Angle3)); m_owner.Radius = m_endValue; }
public virtual void SetPosition(UnitPoint pos) { if (m_pointId != ePoint.Center && Control.ModifierKeys == Keys.Control) { pos = HitUtil.OrthoPointD(OtherPoint(m_pointId), pos, 45); } SetPoint(m_pointId, pos, m_clone); }
public virtual void OnMouseMove(ICanvas canvas, UnitPoint unitPoint) { if (Control.ModifierKeys == Keys.Control) { unitPoint = HitUtil.OrthoPointD(this.P1, unitPoint, 45); } this.P2 = unitPoint; }
public string GetInfoAsString() { return(string.Format("Line@{0},{1} - L={2:f4}<{3:f4}", P1.PosAsString(), P2.PosAsString(), HitUtil.Distance(P1, P2), HitUtil.RadiansToDegrees(HitUtil.LineAngleR(P1, P2, 0)))); }
public virtual void OnMouseMove(ICanvas canvas, UnitPoint point) { if (Control.ModifierKeys == Keys.Control) { point = HitUtil.OrthoPointD(m_p1, point, 45); } m_p2 = point; }
private double GetMinSideLen() { double sideLen = HitUtil.Distance(this.Points[0].Point, this.Points[1].Point); double sideLen2 = HitUtil.Distance(this.Points[1].Point, this.Points[2].Point); double minSide = sideLen > sideLen2 ? sideLen2 : sideLen; return(minSide); }
/// <summary> /// 获取图形信息用于显示在面板下方 /// </summary> /// <returns></returns> string IDrawObject.GetInfoAsString() { return(string.Format("bezierCurve@{0},{1} - L={2:f4}<{3:f4}", P1.PosAsString(), P4.PosAsString(), HitUtil.Distance(P1, P4), HitUtil.RadiansToDegrees(HitUtil.LineAngleR(P1, P4, 0)))); }
public INodePoint NodePoint(UnitPoint unitPoint) { if (HitUtil.CircleHitPoint(this.P1, UCCanvas.GetThresholdWidth(this.radius), unitPoint)) { return(new NodePointSingleDot(this)); } return(null); }
protected virtual void MouseMovePerpendicular(ICanvas canvas, UnitPoint point) { if (m_perSnap.Owner is LineTool) { LineTool src = m_perSnap.Owner as LineTool; m_p1 = HitUtil.NearestPointOnLine(src.P1, src.P2, point, true); m_p2 = point; } }
public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype) { float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel); if (runningsnaptypes != null) { foreach (Type snaptype in runningsnaptypes) { UnitPoint ptemp = UnitPoint.Empty; if (snaptype == typeof(VertextSnapPoint)) { ptemp = GetPointFromVertexId(eVertexId.LeftTopCorner); if (HitUtil.CircleHitPoint(ptemp, thWidth, point)) { return(new VertextSnapPoint(canvas, this, ptemp, (int)eVertexId.LeftTopCorner));//left top corner } ptemp = GetPointFromVertexId(eVertexId.RightBottomCorner); if (HitUtil.CircleHitPoint(ptemp, thWidth, point)) { return(new VertextSnapPoint(canvas, this, ptemp, (int)eVertexId.RightBottomCorner));//right bottom corner } } if (snaptype == typeof(MidpointSnapPoint)) { ptemp = GetPointFromVertexId(eVertexId.BottomEdgeMidPoint); if (HitUtil.CircleHitPoint(ptemp, thWidth, point)) { return(new MidpointSnapPoint(canvas, this, ptemp, (int)eVertexId.BottomEdgeMidPoint));//bottom edge center } ptemp = GetPointFromVertexId(eVertexId.TopEdgeMidPoint); if (HitUtil.CircleHitPoint(ptemp, thWidth, point)) { return(new MidpointSnapPoint(canvas, this, ptemp, (int)eVertexId.TopEdgeMidPoint));//top edge center } ptemp = GetPointFromVertexId(eVertexId.LeftEdgeMidPoint); if (HitUtil.CircleHitPoint(ptemp, thWidth, point)) { return(new MidpointSnapPoint(canvas, this, ptemp, (int)eVertexId.LeftEdgeMidPoint));//left edge center } ptemp = GetPointFromVertexId(eVertexId.RigthEdgeMidPoint); if (HitUtil.CircleHitPoint(ptemp, thWidth, point)) { return(new MidpointSnapPoint(canvas, this, ptemp, (int)eVertexId.RigthEdgeMidPoint));//right edge center } } if (snaptype == typeof(CenterSnapPoint)) { if (HitUtil.PointInPoint(m_center, point, thWidth)) { return(new CenterSnapPoint(canvas, this, m_center)); } } } } return(null); }
public static UnitPoint GetBulgeCenter(UnitPoint vertex, UnitPoint cutoffPoint, UnitPoint cutoffPoint2, double radius) { UnitPoint midPoint = HitUtil.LineMidpoint(cutoffPoint, cutoffPoint2); double midAngle = HitUtil.LineAngleR(vertex, midPoint, 0); double sideLen = GetDistanceBetweenVertexAndCutoffPoint(radius, midAngle * 2); double vertexToCenter = radius * radius + sideLen * sideLen; UnitPoint center = HitUtil.LineEndPoint(vertex, midAngle, vertexToCenter); return(center); }