Exemple #1
0
        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}");
                    }
                }
            }
        }
Exemple #2
0
        //
        // 点pを通り、a - b に平行で、a-bに垂直な線分を求める
        //
        //   +----------p------------+
        //   |                       |
        //   |                       |
        //   a                       b
        //
        public static CadSegment PerpSeg(CadVertex a, CadVertex b, CadVertex p)
        {
            CadSegment seg = default(CadSegment);

            seg.P0 = a;
            seg.P1 = b;

            CrossInfo ci = CadMath.PerpCrossLine(a.vector, b.vector, p.vector);

            if (ci.IsCross)
            {
                CadVertex nv = p - ci.CrossPoint;

                seg.P0 += nv;
                seg.P1 += nv;
            }

            return(seg);
        }