public static CadRect GetContainsRectScrn(DrawContext dc, VertexList list) { CadRect rect = default(CadRect); double minx = CadConst.MaxValue; double miny = CadConst.MaxValue; double maxx = CadConst.MinValue; double maxy = CadConst.MinValue; list.ForEach(p => { CadVertex v = dc.WorldPointToDevPoint(p); minx = Math.Min(minx, v.X); miny = Math.Min(miny, v.Y); maxx = Math.Max(maxx, v.X); maxy = Math.Max(maxy, v.Y); }); rect.p0 = default(CadVertex); rect.p1 = default(CadVertex); rect.p0.X = minx; rect.p0.Y = miny; rect.p0.Z = 0; rect.p1.X = maxx; rect.p1.Y = maxy; rect.p1.Z = 0; return(rect); }
public void Check(DrawContext dc, Vector3d scrp) { Vector3d p = dc.DevPointToWorldPoint(scrp); p.X = (long)((p.X + Math.Sign(p.X) * (GridSize.X / 2.0)) / GridSize.X) * GridSize.X; p.Y = (long)((p.Y + Math.Sign(p.Y) * (GridSize.Y / 2.0)) / GridSize.Y) * GridSize.Y; p.Z = (long)((p.Z + Math.Sign(p.Z) * (GridSize.Z / 2.0)) / GridSize.Z) * GridSize.Z; MatchW = p; MatchD = dc.WorldPointToDevPoint(p); }
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}"); } } } }
public RulerInfo Capture(DrawContext dc, CadCursor cursor, double range) { RulerInfo ret = default(RulerInfo); Vector3d cwp = dc.DevPointToWorldPoint(cursor.Pos); Vector3d xfaceNormal = dc.DevVectorToWorldVector(cursor.DirX); Vector3d yfaceNormal = dc.DevVectorToWorldVector(cursor.DirY); Vector3d cx = CadMath.CrossPlane(P0, P1, cwp, xfaceNormal); Vector3d cy = CadMath.CrossPlane(P0, P1, cwp, yfaceNormal); if (!cx.IsValid() && !cy.IsValid()) { return(ret); } Vector3d p = VectorExt.InvalidVector3d; double mind = Double.MaxValue; StackArray <Vector3d> vtbl = default; vtbl[0] = cx; vtbl[1] = cy; vtbl.Length = 2; for (int i = 0; i < vtbl.Length; i++) { Vector3d v = vtbl[i]; if (!v.IsValid()) { continue; } Vector3d devv = dc.WorldPointToDevPoint(v); double td = (devv - cursor.Pos).Norm(); if (td < mind) { mind = td; p = v; } } if (!p.IsValid()) { return(ret); } if (mind > range) { return(ret); } ret.IsValid = true; ret.CrossPoint = p; ret.Distance = mind; ret.Ruler = this; return(ret); }
private void CheckCircle(DrawContext dc, CadLayer layer, CadFigure fig) { if (fig.PointCount < 3) { return; } VertexList vl = fig.PointList; if (fig.StoreList != null) { vl = fig.StoreList; } Vector3d c = vl[0].vector; Vector3d a = vl[1].vector; Vector3d b = vl[2].vector; Vector3d normal = CadMath.Normal(a - c, b - c); Vector3d tw = Target.Pos; tw.Z = 0; tw = dc.DevPointToWorldPoint(tw); Vector3d crossP = CadMath.CrossPlane(tw, tw + dc.ViewDir, c, normal); if (crossP.IsInvalid()) { // 真横から見ている場合 // viewed edge-on //DOut.tpl("crossP is invalid"); return; } double r = (a - c).Norm(); double tr = (crossP - c).Norm(); Vector3d cirP = c + (crossP - c) * (r / tr); Vector3d dcirP = dc.WorldPointToDevPoint(cirP); Vector3d dcrossP = dc.WorldPointToDevPoint(crossP); dcirP.Z = 0; dcrossP.Z = 0; double dist = (dcirP - Target.Pos).Norm(); if (dist > Range) { //DOut.tpl($"dist:{dist} Range:{Range}"); return; } if (dist < MinDist) { FigureSegment fseg = new FigureSegment(fig, 0, 0, 0); MarkSeg.Layer = layer; MarkSeg.FigSeg = fseg; MarkSeg.CrossPoint = cirP; MarkSeg.CrossPointScrn = dc.WorldPointToDevPoint(cirP); MarkSeg.Distance = dist; MinDist = dist; } }
private void CheckSeg(DrawContext dc, CadLayer layer, FigureSegment fseg) { CadFigure fig = fseg.Figure; int idxA = fseg.Index0; int idxB = fseg.Index1; Vector3d a = fseg.Point0.vector; Vector3d b = fseg.Point1.vector; if (fig.StoreList != null && fig.StoreList.Count > 1) { if (!CheckStorePoint) { return; } a = fseg.StoredPoint0.vector; b = fseg.StoredPoint1.vector; } Vector3d cwp = dc.DevPointToWorldPoint(Target.Pos); Vector3d xfaceNormal = dc.DevVectorToWorldVector(Target.DirX); Vector3d yfaceNormal = dc.DevVectorToWorldVector(Target.DirY); Vector3d cx = CadMath.CrossSegPlane(a, b, cwp, xfaceNormal); Vector3d cy = CadMath.CrossSegPlane(a, b, cwp, yfaceNormal); if (!cx.IsValid() && !cy.IsValid()) { return; } Vector3d p = VectorExt.InvalidVector3d; double mind = double.MaxValue; Vector3d dcenter = dc.WorldPointToDevPoint(CadMath.CenterPoint(a, b)); double centerDist = (dcenter - Target.Pos).Norm(); if (CheckPriority == Priority.NONE || centerDist < Range) { StackArray <Vector3d> vtbl = default; vtbl[0] = cx; vtbl[1] = cy; vtbl.Length = 2; for (int i = 0; i < vtbl.Length; i++) { Vector3d v = vtbl[i]; if (!v.IsValid()) { continue; } Vector3d devv = dc.WorldPointToDevPoint(v); double td = (devv - Target.Pos).Norm(); if (td < mind) { mind = td; p = v; } } } else { if (CheckPriority == Priority.PRIORITY_X) { p = cx; } else if (CheckPriority == Priority.PRIORITY_Y) { p = cy; } if (p.IsInvalid()) { return; } Vector3d devv = dc.WorldPointToDevPoint(p); mind = (devv - Target.Pos).Norm(); } if (!p.IsValid()) { return; } if (mind > Range) { return; } if (mind < MinDist) { MarkSeg.Layer = layer; MarkSeg.FigSeg = fseg; MarkSeg.CrossPoint = p; MarkSeg.CrossPointScrn = dc.WorldPointToDevPoint(p); MarkSeg.Distance = mind; MinDist = mind; } }