Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
        public override FigureSegment GetFigSegmentAt(int n)
        {
            FigureSegment seg = new FigureSegment(this, n, SegList[n].Idx0, SegList[n].Idx1);

            return(seg);
        }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        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;
            }
        }