Exemple #1
0
        public RulerInfo Capture(DrawContext dc, CadCursor cursor, double rangePixel)
        {
            RulerInfo match = default(RulerInfo);
            RulerInfo ri    = default(RulerInfo);

            double min = rangePixel;

            MatchIndex = -1;

            for (int i = 0; i < RCount; i++)
            {
                ri = Ruler[i].Capture(dc, cursor, rangePixel);

                if (ri.IsValid && ri.Distance < min)
                {
                    min        = ri.Distance;
                    match      = ri;
                    MatchIndex = i;
                }
            }

            return(match);
        }
Exemple #2
0
        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);
        }