public bool MoveEdgeCtrl(uint eId, uint iCtrl, OpenTK.Vector2d deltaVec) { if (!IsElementId(CadElementType.Edge, eId)) { return(false); } IList <double> oldRelCos = null; { Edge2D e = GetEdge(eId); oldRelCos = e.GetCurveRelPoint(); } Edge2D edge = GetEdge(eId); if (iCtrl >= edge.GetCurvePoint().Count) { return(true); } { OpenTK.Vector2d sPt = edge.GetVertex(true); OpenTK.Vector2d ePt = edge.GetVertex(false); double sqLen = CadUtils.SquareLength(ePt - sPt); var eh = (ePt - sPt) * (1 / sqLen); OpenTK.Vector2d ev = new OpenTK.Vector2d(-eh.Y, eh.X); var p0 = edge.GetCurvePoint()[(int)iCtrl] + deltaVec; IList <double> aRelCo = edge.GetCurveRelPoint(); aRelCo[(int)(iCtrl * 2 + 0)] = OpenTK.Vector2d.Dot(p0 - sPt, eh); aRelCo[(int)(iCtrl * 2 + 1)] = OpenTK.Vector2d.Dot(p0 - sPt, ev); edge.SetCurveRelPoint(aRelCo); } HashSet <uint> setLId = new HashSet <uint>(); for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(true)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(false)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } foreach (uint lId in setLId) { if (!this.BRep.IsElementId(CadElementType.Loop, lId)) { continue; } if (CheckLoop(lId) != 0) { // fail edge.SetCurveRelPoint(oldRelCos); return(true); } } return(true); }
public bool DragArc(uint eId, OpenTK.Vector2d vec) { if (!IsElementId(CadElementType.Edge, eId)) { return(false); } if (GetEdgeCurveType(eId) != CurveType.CurveArc) { return(true); } bool oldIsLeftSide; double oldDist; { Edge2D e = GetEdge(eId); e.GetCurveArc(out oldIsLeftSide, out oldDist); } Edge2D edge = GetEdge(eId); System.Diagnostics.Debug.Assert(edge.CurveType == CurveType.CurveArc); { OpenTK.Vector2d sPt = edge.GetVertex(true); OpenTK.Vector2d ePt = edge.GetVertex(false); double edgeLen = Math.Sqrt(CadUtils.SquareLength(sPt, ePt)); if (Math.Abs(CadUtils.TriHeight(vec, sPt, ePt)) > edgeLen * 0.02) { OpenTK.Vector2d cPt; bool ret = CadUtils.CenterCircumcircle(sPt, ePt, vec, out cPt); System.Diagnostics.Debug.Assert(ret); double dist = CadUtils.TriHeight(cPt, sPt, ePt); double distRatio = dist / edgeLen; edge.SetCurveArc(CadUtils.TriArea(sPt, ePt, vec) > 0, distRatio); } else { return(true); } } HashSet <uint> setLId = new HashSet <uint>(); for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(true)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(false)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } foreach (uint lId in setLId) { if (!this.BRep.IsElementId(CadElementType.Loop, lId)) { continue; } if (CheckLoop(lId) != 0) { // fail edge.SetCurveArc(oldIsLeftSide, oldDist); return(true); } } return(true); }
public static int CheckEdgeIntersection(IList <Edge2D> edges) { uint edgeCnt = (uint)edges.Count; for (int iedge = 0; iedge < edgeCnt; iedge++) { Edge2D iE = edges[iedge]; if (iE.IsCrossEdgeSelf()) { return(1); } uint iPt0 = iE.GetVertexId(true); uint iPt1 = iE.GetVertexId(false); BoundingBox2D iBB = iE.GetBoundingBox(); for (int jedge = iedge + 1; jedge < edgeCnt; jedge++) { Edge2D jE = edges[jedge]; uint jPt0 = jE.GetVertexId(true); uint jPt1 = jE.GetVertexId(false); if ((iPt0 - jPt0) * (iPt0 - jPt1) * (iPt1 - jPt0) * (iPt1 - jPt1) != 0) { BoundingBox2D jBB = jE.GetBoundingBox(); if (jBB.MinX > iBB.MaxX || jBB.MaxX < iBB.MinX) { continue; } if (jBB.MinY > iBB.MaxY || jBB.MaxY < iBB.MinY) { continue; } if (!iE.IsCrossEdge(jE)) { continue; } return(1); } if (iPt0 == jPt0 && iPt1 == jPt1) { if (iE.IsCrossEdgeShareBothPoints(jE, true)) { return(1); } } else if (iPt0 == jPt1 && iPt1 == jPt0) { if (iE.IsCrossEdgeShareBothPoints(jE, false)) { return(1); } } else if (iPt0 == jPt0) { if (iE.IsCrossEdgeShareOnePoint(jE, true, true)) { return(1); } } else if (iPt0 == jPt1) { if (iE.IsCrossEdgeShareOnePoint(jE, true, false)) { return(1); } } else if (iPt1 == jPt0) { if (iE.IsCrossEdgeShareOnePoint(jE, false, true)) { return(1); } } else if (iPt1 == jPt1) { if (iE.IsCrossEdgeShareOnePoint(jE, false, false)) { return(1); } } continue; } } return(0); }