public void Copy(IObject src) { Vertex2D srcVertex = src as Vertex2D; Point = new OpenTK.Vector2d(srcVertex.Point.X, srcVertex.Point.Y); srcVertex.Color.CopyTo(Color, 0); }
public bool MoveVertex(IList <KeyValuePair <uint, OpenTK.Vector2d> > idVecs) { IList <OpenTK.Vector2d> oldVecs = new List <OpenTK.Vector2d>(); try { foreach (var pair in idVecs) { uint id_v = pair.Key; if (!VertexArray.IsObjectId(id_v)) { throw new InvalidOperationException(); } Vertex2D ver = VertexArray.GetObject(id_v); oldVecs.Add(ver.Point); ver.Point = pair.Value; } { IList <uint> loopIds = GetElementIds(CadElementType.Loop); foreach (uint lId in loopIds) { if (CheckLoop(lId) != 0) { throw new InvalidOperationException(); } } } } catch (Exception exception) { //////////////////////////////// // fail // 動かした点を元に戻す for (int i = 0; i < oldVecs.Count; i++) { uint id_v = idVecs[i].Key; Vertex2D ver = VertexArray.GetObject(id_v); ver.Point = oldVecs[i]; } return(false); } return(true); }
public bool MoveLoop(uint lId, OpenTK.Vector2d vecDelta) { if (!IsElementId(CadElementType.Loop, lId)) { return(false); } Dictionary <uint, OpenTK.Vector2d> mapOldVec = new Dictionary <uint, OpenTK.Vector2d>(); HashSet <uint> setLId = new HashSet <uint>(); // check these loop for intersection detection for (LoopEdgeItr lItr = this.BRep.GetLoopEdgeItr(lId); !lItr.IsChildEnd; lItr.ShiftChildLoop()) { for (lItr.Begin(); !lItr.IsEnd(); lItr++) { uint vId = lItr.GetVertexId(); if (mapOldVec.ContainsKey(vId)) { continue; // this point is already moved } mapOldVec.Add(vId, GetVertexCoord(vId)); Vertex2D vertex = VertexArray.GetObject(vId); { double oldX = vertex.Point.X; double oldY = vertex.Point.Y; vertex.Point = new OpenTK.Vector2d(oldX + vecDelta.X, oldY + vecDelta.Y); } uint eId0; bool isSameDir0; lItr.GetEdgeId(out eId0, out isSameDir0); if (!IsElementId(CadElementType.Edge, eId0)) { continue; // this is point } uint lLId; uint rLId; this.GetEdgeLoopId(out lLId, out rLId, eId0); if (!setLId.Contains(lLId)) { setLId.Add(lLId); } if (!setLId.Contains(rLId)) { setLId.Add(rLId); } } } foreach (uint lIdl0 in setLId) { if (!IsElementId(CadElementType.Loop, lIdl0)) { continue; // id0 can be 0 if this loop(id_l) have open boundary } if (CheckLoop(lIdl0) != 0) { // fail foreach (var oldVec in mapOldVec) { uint vId = oldVec.Key; Vertex2D vertex = VertexArray.GetObject(vId); vertex.Point = oldVec.Value; } return(false); } } return(true); }
public bool MoveVertex(uint vId, OpenTK.Vector2d vec) { if (!VertexArray.IsObjectId(vId)) { return(false); } OpenTK.Vector2d preVec; { // store point to move point back in case it fails Vertex2D vertex = VertexArray.GetObject(vId); preVec = vertex.Point; } OpenTK.Vector2d dist = vec; { // move point Vertex2D vertex = VertexArray.GetObject(vId); vertex.Point = dist; } try { VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(vId); if (vItr.GetEdgeCount() == 0) { // move point inside loop uint lId = vItr.GetLoopId(); if (IsElementId(CadElementType.Loop, lId)) { // ignore vtx(id_v) in the signd distance computation double distance = SignedDistancePointLoop(lId, vec, vId); if (distance < this.MinClearance) { throw new InvalidOperationException(); } } } else { // move point adjacent to loop HashSet <uint> lIds = new HashSet <uint>(); for (; !vItr.IsEnd(); vItr++) { uint lId = vItr.GetLoopId(); if (IsElementId(CadElementType.Loop, lId)) { if (!lIds.Contains(lId)) { lIds.Add(lId); } else { continue; } if (CheckLoop(lId) != 0) { throw new InvalidOperationException(); } } } } } catch (Exception exception) { //////////////////////////////// // fail { // reset the moved point Vertex2D vertex = VertexArray.GetObject(vId); vertex.Point = preVec; } return(false); } return(true); }
public bool MoveEdge(uint eId, OpenTK.Vector2d vecDelta) { System.Diagnostics.Debug.Assert(IsElementId(CadElementType.Edge, eId)); uint sVId = GetEdgeVertexId(eId, true); uint eVId = GetEdgeVertexId(eId, false); OpenTK.Vector2d preSVec; { // 点を動かす→駄目だったら元に戻す Vertex2D vertex = VertexArray.GetObject(sVId); preSVec = vertex.Point; { double oldX = vertex.Point.X; double oldY = vertex.Point.Y; vertex.Point = new OpenTK.Vector2d(oldX + vecDelta.X, oldY + vecDelta.Y); } } OpenTK.Vector2d preEVec; { // 点を動かす→駄目だったら元に戻す Vertex2D ver = VertexArray.GetObject(eVId); preEVec = ver.Point; { double oldX = ver.Point.X; double oldY = ver.Point.Y; ver.Point = new OpenTK.Vector2d(oldX + vecDelta.X, oldY + vecDelta.Y); } } try { // Check Interfarance HashSet <uint> lIds = new HashSet <uint>(); for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(sVId); !vItr.IsEnd(); vItr++) { uint lId = vItr.GetLoopId(); if (IsElementId(CadElementType.Loop, lId)) { if (!lIds.Contains(lId)) { lIds.Add(lId); } else { continue; } if (CheckLoop(lId) != 0) { throw new InvalidOperationException(); } } } for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(eVId); !vItr.IsEnd(); vItr++) { uint lId = vItr.GetLoopId(); if (IsElementId(CadElementType.Loop, lId)) { if (!lIds.Contains(lId)) { lIds.Add(lId); } else { continue; } if (CheckLoop(lId) != 0) { throw new InvalidOperationException(); } } } } catch (Exception exception) { //////////////////////////////// //if the operation fails { // 動かした点を元に戻す Vertex2D vertex = VertexArray.GetObject(sVId); vertex.Point = preSVec; } { // 動かした点を元に戻す Vertex2D vertex = VertexArray.GetObject(eVId); vertex.Point = preEVec; } return(false); } return(true); }
public Vertex2D(Vertex2D src) { Copy(src); }