public static void SelectPointAt(CadFigure fig, int index, bool sel) { CadVertex p = fig.PointList[index]; p.Selected = sel; fig.PointList[index] = p; }
private static bool ListContainsPointInTriangle(VertexList check, CadFigure triangle) { var tps = triangle.PointList; foreach (CadVertex cp in check) { if ( cp.Equals(tps[0]) || cp.Equals(tps[1]) || cp.Equals(tps[2]) ) { continue; } bool ret = CadMath.IsPointInTriangle( cp.vector, tps[0].vector, tps[1].vector, tps[2].vector ); if (ret) { return(true); } } return(false); }
private static CadFigure GetTriangleWithCenterPoint(VertexList pointList, int cpIndex) { int i1 = cpIndex; int endi = pointList.Count - 1; int i0 = i1 - 1; int i2 = i1 + 1; if (i0 < 0) { i0 = endi; } if (i2 > endi) { i2 = 0; } var triangle = CadFigure.Create(CadFigure.Types.POLY_LINES); CadVertex tp0 = pointList[i0]; CadVertex tp1 = pointList[i1]; CadVertex tp2 = pointList[i2]; triangle.AddPoint(tp0); triangle.AddPoint(tp1); triangle.AddPoint(tp2); triangle.IsLoop = true; return(triangle); }
public static double AroundLength(CadFigure fig) { if (fig == null) { return(0); } int cnt = fig.PointCount; if (cnt < 2) { return(0); } CadVertex p0; CadVertex p1; CadVertex pd; double d = 0; for (int i = 0; i < cnt - 1; i++) { p0 = fig.GetPointAt(i); p1 = fig.GetPointAt(i + 1); pd = p1 - p0; d += pd.Norm(); } return(d); }
public void CreateModel(CadFigure fig) { if (!(fig is CadFigurePolyLines)) { return; } mHeModel.Clear(); for (int i = 0; i < fig.PointCount; i++) { int idx = mHeModel.AddVertex(fig.PointList[i]); } List <CadFigure> figList = TriangleSplitter.Split(fig, 16); HeModelBuilder mb = new HeModelBuilder(); mb.Start(mHeModel); for (int i = 0; i < figList.Count; i++) { CadFigure t = figList[i]; mb.AddTriangle(t.PointList[0], t.PointList[1], t.PointList[2]); } }
public override void Redo(CadObjectDB db) { CadLayer layer = db.GetLayer(LayerID); CadFigure fig = db.GetFigure(FigureID); fig.InsertPointsRange(PointIndex, mPointList); }
public static void RotateFigure(CadFigure fig, Vector3d org, Vector3d axis, double t) { CadQuaternion q = CadQuaternion.RotateQuaternion(axis, t); CadQuaternion r = q.Conjugate();; fig.Rotate(org, q, r); }
public override void Redo(CadObjectDB db) { CadLayer layer = db.GetLayer(LayerID); CadFigure fig = db.GetFigure(FigureID); layer.AddFigure(fig); }
public override void Undo(CadObjectDB db) { CadLayer layer = db.GetLayer(LayerID); CadFigure fig = db.GetFigure(FigureID); layer.InsertFigure(mFigureIndex, fig); }
public static string DumpString(CadFigure fig, string margin) { string s = ""; s += margin + "ID:" + fig.ID.ToString() + "\n"; s += margin + "Point:[\n"; for (int i = 0; i < fig.PointList.Count; i++) { CadVertex v = fig.PointList[i]; s += margin + " " + string.Format("{0},{1},{2}\n", v.X, v.Y, v.Z); } s += margin + "]\n"; s += margin + "Children:[\n"; if (fig.ChildList != null) { for (int i = 0; i < fig.ChildList.Count; i++) { CadFigure c = fig.ChildList[i]; s += DumpString(c, margin + " "); } } s += margin + "]\n"; return(s); }
public FigureSegment(CadFigure fig, int segIndex, int a, int b) { Figure = fig; SegIndex = segIndex; Index0 = a; Index1 = b; }
public override void Undo(CadObjectDB db) { CadLayer layer = db.GetLayer(LayerID); CadFigure fig = db.GetFigure(FigureID); if (fig == null) { return; } int idx = PointIndex; int i = 0; if (mPointList == null) { mPointList = new VertexList(); } mPointList.Clear(); for (; i < InsertNum; i++) { mPointList.Add(fig.GetPointAt(idx + i)); } fig.RemovePointsRange(idx, InsertNum); }
// 三角形の重心を求める public static Vector3d TriangleCentroid(CadFigure fig) { return(CadMath.TriangleCentroid( fig.GetPointAt(0).vector, fig.GetPointAt(1).vector, fig.GetPointAt(2).vector )); }
// 三角形の面積 3D対応 public static double TriangleArea(CadFigure fig) { return(CadMath.TriangleArea( fig.GetPointAt(0).vector, fig.GetPointAt(1).vector, fig.GetPointAt(2).vector )); }
private void CheckSegs(DrawContext dc, CadLayer layer, CadFigure fig) { for (int i = 0; i < fig.SegmentCount; i++) { FigureSegment seg = fig.GetFigSegmentAt(i); CheckSeg(dc, layer, seg); } }
public override void Redo(CadObjectDB db) { CadFigure parent = db.GetFigure(ParentID); CadFigure child = db.GetFigure(ChildID); parent.ChildList.Remove(child); child.Parent = null; }
public override void Undo(CadObjectDB db) { CadFigure parent = db.GetFigure(ParentID); CadFigure child = db.GetFigure(ChildID); parent.ChildList.Insert(Index, child); child.Parent = parent; }
public CadOpeRemoveChildlen(CadFigure parent, List <CadFigure> childlen) { ParentID = parent.ID; childlen.ForEach(a => { ChildIDList.Add(a.ID); }); }
public static CadRuler Create(CadFigure fig, int idx0, int idx1) { CadRuler ret = default(CadRuler); ret.Fig = fig; ret.Idx0 = idx0; ret.Idx1 = idx1; return(ret); }
//public static CadFigure Clone(CadFigure src) //{ // MpFigure_v1002 mpf = MpFigure_v1002.Create(src, false); // byte[] data = MessagePackSerializer.Serialize(mpf); // MpFigure_v1002 mpfCopy = MessagePackSerializer.Deserialize<MpFigure_v1002>(data); // CadFigure fig = mpfCopy.Restore(); // fig.ID = 0; // return fig; //} public static CadFigure Clone(CadFigure src) { byte[] data = MpUtil.FigToBin(src, false); CadFigure fig = MpUtil.BinToFig(data); fig.ID = 0; return(fig); }
public override void Undo(CadObjectDB db) { CadFigure parent = db.GetFigure(ParentID); foreach (uint childID in ChildIDList) { CadFigure fig = db.GetFigure(childID); parent.AddChild(fig); } }
public static int SegmentCount(CadFigure fig) { int cnt = fig.PointList.Count - 1; if (fig.IsLoop) { cnt++; } return(cnt); }
public override void Redo(CadObjectDB db) { CadFigure parent = db.GetFigure(ParentID); foreach (uint childID in ChildIDList) { parent.ChildList.RemoveAll(a => a.ID == childID); CadFigure fig = db.GetFigure(childID); fig.Parent = null; } }
public double DistanceY; // Y距離 (Screen座標系) public void reset() { this = default; IsValid = false; Figure = null; DistanceX = CadConst.MaxValue; DistanceY = CadConst.MaxValue; }
public static MinMax3D GetFigureMinMaxIncludeChild(CadFigure fig) { MinMax3D mm = MinMax3D.Create(); fig.ForEachFig(item => { mm.Check(GetFigureMinMax(item)); }); return(mm); }
public static CadFigure GetRootFig(CadFigure src) { while (true) { if (src.Parent == null) { return(src); } src = src.Parent; } }
public static EditResult Cut(CadObjectDB db, CadFigure fig, int sp) { EditResult result = new EditResult(); if (fig.Type != CadFigure.Types.POLY_LINES) { return(result); } if (fig.IsLoop) { return(result); } int pcnt = fig.PointCount; int headNum = sp + 1; int tailNum = pcnt - sp; CadFigure headFig = null; CadFigure tailFig = null; if (headNum <= 1 || tailNum <= 1) { return(result); } if (headNum >= 2) { headFig = db.NewFigure(CadFigure.Types.POLY_LINES); headFig.AddPoints(fig.PointList, 0, headNum); } if (tailNum >= 2) { tailFig = db.NewFigure(CadFigure.Types.POLY_LINES); tailFig.AddPoints(fig.PointList, sp, tailNum); } if (headFig != null) { result.AddList.Add(new EditResult.Item(fig.LayerID, headFig)); } if (tailFig != null) { result.AddList.Add(new EditResult.Item(fig.LayerID, tailFig)); } result.RemoveList.Add(new EditResult.Item(fig.LayerID, fig)); return(result); }
public static MinMax3D GetFigureMinMax(CadFigure fig) { MinMax3D mm = MinMax3D.Create(); int i = 0; for (; i < fig.PointCount; i++) { mm.Check(fig.PointList[i].vector); } return(mm); }
public void Search(DrawContext dc, CadObjectDB db, CadLayer layer) { if (layer == null) { return; } for (int i = 0; i < layer.FigureList.Count; i++) { CadFigure fig = layer.FigureList[i]; CheckFigure(dc, layer, fig); } }
private void CheckFigPoint(DrawContext dc, Vector3d pt, CadLayer layer, CadFigure fig, int ptIdx) { Vector3d ppt = dc.WorldPointToDevPoint(pt); double dx = Math.Abs(ppt.X - Target.Pos.X); double dy = Math.Abs(ppt.Y - Target.Pos.Y); CrossInfo cix = CadMath.PerpCrossLine(Target.Pos, Target.Pos + Target.DirX, ppt); CrossInfo ciy = CadMath.PerpCrossLine(Target.Pos, Target.Pos + Target.DirY, ppt); double nx = (ppt - ciy.CrossPoint).Norm(); // Cursor Y軸からの距離 double ny = (ppt - cix.CrossPoint).Norm(); // Cursor X軸からの距離 if (nx <= Range) { if (nx < XMatch.DistanceX || (nx == XMatch.DistanceX && ny < XMatch.DistanceY)) { XMatch = GetMarkPoint(pt, ppt, nx, ny, layer, fig, ptIdx); } } if (ny <= Range) { if (ny < YMatch.DistanceY || (ny == YMatch.DistanceY && nx < YMatch.DistanceX)) { YMatch = GetMarkPoint(pt, ppt, nx, ny, layer, fig, ptIdx); } } if (dx <= Range && dy <= Range) { double minDist = (XYMatch.DistanceX * XYMatch.DistanceX) + (XYMatch.DistanceY * XYMatch.DistanceY); double curDist = (dx * dx) + (dy * dy); if (curDist <= minDist) { MarkPoint t = GetMarkPoint(pt, ppt, dx, dy, layer, fig, ptIdx); //t.dump(); XYMatch = t; if (!XYMatchSet.Contains(t)) { XYMatchList.Add(XYMatch); XYMatchSet.Add(XYMatch); //DOut.pl($"PointSearcher XYMatchList cnt:{XYMatchList.Count}"); } } } }